install_prereqs.sh 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #!/usr/bin/env bash
  2. # Copyright 2018 Google LLC
  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. # Within Travis, installs prerequisites for a build.
  16. # Examines the following configured environment variables that should be
  17. # specified in an env: block
  18. # - PROJECT - Firebase or Firestore
  19. # - METHOD - xcodebuild or cmake; default is xcodebuild
  20. set -euo pipefail
  21. # Set up secrets for integration tests and metrics collection. This does not work for pull
  22. # requests from forks. See
  23. # https://docs.travis-ci.com/user/pull-requests#pull-requests-and-security-restrictions
  24. function install_secrets() {
  25. if [[ -n "${encrypted_de2056405dcb_key:-}" && $secrets_installed != true ]]; then
  26. secrets_installed=true
  27. openssl aes-256-cbc -K $encrypted_de2056405dcb_key -iv $encrypted_de2056405dcb_iv \
  28. -in scripts/travis-encrypted/Secrets.tar.enc \
  29. -out scripts/travis-encrypted/Secrets.tar -d
  30. tar xvf scripts/travis-encrypted/Secrets.tar
  31. cp Secrets/Auth/Sample/Application.plist Example/Auth/Sample/Application.plist
  32. cp Secrets/Auth/Sample/AuthCredentials.h Example/Auth/Sample/AuthCredentials.h
  33. cp Secrets/Auth/Sample/GoogleService-Info_multi.plist Example/Auth/Sample/GoogleService-Info_multi.plist
  34. cp Secrets/Auth/Sample/GoogleService-Info.plist Example/Auth/Sample/GoogleService-Info.plist
  35. cp Secrets/Auth/Sample/Sample.entitlements Example/Auth/Sample/Sample.entitlements
  36. cp Secrets/Auth/ApiTests/AuthCredentials.h Example/Auth/ApiTests/AuthCredentials.h
  37. cp Secrets/Storage/App/GoogleService-Info.plist FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist
  38. cp Secrets/Storage/App/GoogleService-Info.plist Example/Database/App/GoogleService-Info.plist
  39. cp Secrets/Metrics/database.config Metrics/database.config
  40. # Firebase Installations
  41. fis_resources_dir=FirebaseInstallations/Source/Tests/Resources/
  42. mkdir -p "$fis_resources_dir"
  43. cp Secrets/Installations/GoogleService-Info.plist "$fis_resources_dir"
  44. # FirebaseInstanceID
  45. iid_resources_dir=Example/InstanceID/Resources/
  46. mkdir -p "$iid_resources_dir"
  47. cp Secrets/Installations/GoogleService-Info.plist "$iid_resources_dir"
  48. fi
  49. }
  50. # apt_install program package
  51. #
  52. # Installs the given package if the given command is missing
  53. function apt_install() {
  54. local program="$1"
  55. local package="$2"
  56. which "$program" >& /dev/null || sudo apt-get install "$package"
  57. }
  58. secrets_installed=false
  59. # Default values, if not supplied on the command line or environment
  60. platform="iOS"
  61. method="xcodebuild"
  62. if [[ $# -eq 0 ]]; then
  63. # Take arguments from the environment
  64. project=$PROJECT
  65. platform=${PLATFORM:-${platform}}
  66. method=${METHOD:-${method}}
  67. else
  68. project="$1"
  69. if [[ $# -gt 1 ]]; then
  70. platform="$2"
  71. fi
  72. if [[ $# -gt 2 ]]; then
  73. method="$3"
  74. fi
  75. fi
  76. echo "Installing prerequisites for $project for $platform using $method"
  77. if [[ "$method" != "cmake" ]]; then
  78. scripts/setup_bundler.sh
  79. fi
  80. if [[ ! -z "${QUICKSTART:-}" ]]; then
  81. install_secrets
  82. scripts/setup_quickstart.sh "$QUICKSTART"
  83. fi
  84. system=$(uname -s)
  85. case "$system" in
  86. Darwin)
  87. xcode_version=$(xcodebuild -version | head -n 1)
  88. xcode_version="${xcode_version/Xcode /}"
  89. xcode_major="${xcode_version/.*/}"
  90. ;;
  91. *)
  92. xcode_major="0"
  93. ;;
  94. esac
  95. case "$project-$platform-$method" in
  96. FirebasePod-iOS-xcodebuild)
  97. gem install xcpretty
  98. bundle exec pod install --project-directory=CoreOnly/Tests/FirebasePodTest --repo-update
  99. ;;
  100. Auth-*)
  101. # Install the workspace for integration testing.
  102. gem install xcpretty
  103. bundle exec pod install --project-directory=Example/Auth/AuthSample --repo-update
  104. ;;
  105. Crashlytics-*)
  106. ;;
  107. Database-*)
  108. ;;
  109. Functions-*)
  110. # Start server for Functions integration tests.
  111. ./Functions/Backend/start.sh synchronous
  112. ;;
  113. Storage-*)
  114. ;;
  115. Installations-*)
  116. install_secrets
  117. ;;
  118. InstanceID*)
  119. install_secrets
  120. ;;
  121. InAppMessaging-*-xcodebuild)
  122. gem install xcpretty
  123. bundle exec pod install --project-directory=FirebaseInAppMessaging/Tests/Integration/DefaultUITestApp --no-repo-update
  124. ;;
  125. Firestore-*-xcodebuild | Firestore-*-fuzz)
  126. if [[ $xcode_major -lt 9 ]]; then
  127. # Firestore still compiles with Xcode 8 to help verify general
  128. # conformance with C++11 by using an older compiler that doesn't have as
  129. # many extensions from later versions of the language. However, Firebase
  130. # as a whole does not support this environment and @available checks in
  131. # GoogleDataTransport would otherwise break this build.
  132. #
  133. # This drops the dependency that adds GoogleDataTransport into
  134. # Firestore's dependencies.
  135. sed -i.bak "/s.dependency 'FirebaseCoreDiagnostics'/d" FirebaseCore.podspec
  136. fi
  137. gem install xcpretty
  138. # The Firestore Podfile is multi-platform by default, but this doesn't work
  139. # with command-line builds using xcodebuild. The PLATFORM environment
  140. # variable forces the project to be set for just that single platform.
  141. export PLATFORM="$platform"
  142. bundle exec pod install --project-directory=Firestore/Example --repo-update
  143. ;;
  144. Firestore-iOS-cmake | Firestore-tvOS-cmake | Firestore-macOS-cmake)
  145. brew outdated cmake || brew upgrade cmake
  146. brew outdated go || brew upgrade go # Somehow the build for Abseil requires this.
  147. brew install ccache
  148. brew install ninja
  149. # Install python packages required to generate proto sources
  150. pip install six
  151. ;;
  152. Firestore-Linux-cmake)
  153. apt_install ccache ccache
  154. apt_install cmake cmake
  155. apt_install go golang-go
  156. apt_install ninja ninja-build
  157. # Install python packages required to generate proto sources
  158. pip install six
  159. ;;
  160. SymbolCollision-*-xcodebuild)
  161. gem install xcpretty
  162. bundle exec pod install --project-directory=SymbolCollisionTest --repo-update
  163. ;;
  164. *-pod-lib-lint)
  165. ;;
  166. *)
  167. echo "Unknown project-platform-method combo" 1>&2
  168. echo " PROJECT=$project" 1>&2
  169. echo " PLATFORM=$platform" 1>&2
  170. echo " METHOD=$method" 1>&2
  171. exit 1
  172. ;;
  173. esac