build.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/usr/bin/env bash
  2. # Copyright 2018 Google
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # USAGE: build.sh product [platform] [method]
  16. #
  17. # Builds the given product for the given platform using the given build method
  18. set -euo pipefail
  19. if [[ $# -lt 1 ]]; then
  20. cat 1>&2 <<EOF
  21. USAGE: $0 product [platform] [method]
  22. product can be one of:
  23. Firebase
  24. Firestore
  25. platform can be one of:
  26. iOS (default)
  27. macOS
  28. tvOS
  29. method can be one of:
  30. xcodebuild (default)
  31. cmake
  32. EOF
  33. exit 1
  34. fi
  35. product="$1"
  36. platform="iOS"
  37. if [[ $# -gt 1 ]]; then
  38. platform="$2"
  39. fi
  40. method="xcodebuild"
  41. if [[ $# -gt 2 ]]; then
  42. method="$3"
  43. fi
  44. echo "Building $product for $platform using $method"
  45. # Runs xcodebuild with the given flags, piping output to xcpretty
  46. # If xcodebuild fails with known error codes, retries once.
  47. function RunXcodebuild() {
  48. xcodebuild "$@" | xcpretty; result=$?
  49. if [[ $result == 65 ]]; then
  50. echo "xcodebuild exited with 65, retrying" 1>&2
  51. sleep 5
  52. xcodebuild "$@" | xcpretty; result=$?
  53. fi
  54. if [[ $result != 0 ]]; then
  55. exit $result
  56. fi
  57. }
  58. # Compute standard flags for all platforms
  59. case "$platform" in
  60. iOS)
  61. xcb_flags=(
  62. -sdk 'iphonesimulator'
  63. -destination 'platform=iOS Simulator,name=iPhone 7'
  64. )
  65. ;;
  66. macOS)
  67. xcb_flags=(
  68. -sdk 'macosx'
  69. -destination 'platform=OS X,arch=x86_64'
  70. )
  71. ;;
  72. tvOS)
  73. xcb_flags=(
  74. -sdk "appletvsimulator"
  75. -destination 'platform=tvOS Simulator,name=Apple TV'
  76. )
  77. ;;
  78. *)
  79. echo "Unknown platform '$platform'" 1>&2
  80. exit 1
  81. ;;
  82. esac
  83. xcb_flags+=(
  84. ONLY_ACTIVE_ARCH=YES
  85. CODE_SIGNING_REQUIRED=NO
  86. )
  87. case "$product-$method-$platform" in
  88. Firebase-xcodebuild-*)
  89. RunXcodebuild \
  90. -workspace 'Example/Firebase.xcworkspace' \
  91. -scheme "AllUnitTests_$platform" \
  92. "${xcb_flags[@]}" \
  93. build \
  94. test
  95. ;;
  96. Firestore-xcodebuild-iOS)
  97. RunXcodebuild \
  98. -workspace 'Firestore/Example/Firestore.xcworkspace' \
  99. -scheme 'Firestore_Tests' \
  100. "${xcb_flags[@]}" \
  101. build \
  102. test
  103. RunXcodebuild \
  104. -workspace 'Firestore/Example/Firestore.xcworkspace' \
  105. -scheme 'SwiftBuildTest' \
  106. "${xcb_flags[@]}" \
  107. build
  108. ;;
  109. Firestore-cmake-macOS)
  110. test -d build || mkdir build
  111. echo "Preparing cmake build ..."
  112. (cd build; cmake ..)
  113. echo "Building cmake build ..."
  114. cpus=$(sysctl -n hw.ncpu)
  115. (cd build; make -j $cpus all)
  116. ;;
  117. *)
  118. echo "Don't know how to build this product-platform-method combination" 1>&2
  119. echo " product=$product" 1>&2
  120. echo " platform=$platform" 1>&2
  121. echo " method=$method" 1>&2
  122. exit 1
  123. ;;
  124. esac