build_with_environment.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/env bash
  2. # Copyright 2019 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. # The script uses combination of Gemfile/Podfile to validate Firebase
  16. # compatibility with Cocoapods versions and settings.
  17. # See `printUsage` for usage.
  18. set -euo pipefail
  19. source scripts/buildcache.sh
  20. #
  21. function runXcodebuild() {
  22. parameters=(
  23. -workspace 'CocoapodsIntegrationTest.xcworkspace'
  24. -scheme 'CocoapodsIntegrationTest'
  25. -sdk 'iphonesimulator'
  26. -destination 'platform=iOS Simulator,name=iPhone 14'
  27. CODE_SIGNING_REQUIRED=NO
  28. clean
  29. build
  30. )
  31. parameters=("${buildcache_xcb_flags[@]}" "${parameters[@]}")
  32. echo xcodebuild "${parameters[@]}"
  33. xcodebuild "${parameters[@]}" | xcpretty; result=$?
  34. }
  35. # Configures bundler environment using Gemfile at the specified path.
  36. function prepareBundle() {
  37. cp -f "$@" ./Gemfile
  38. # Travis sets this variable. We should unset it otherwise `bundle exec` will
  39. # use the Gemfile by the path from the variable.
  40. unset BUNDLE_GEMFILE
  41. bundle update
  42. }
  43. # Updates Cocoapods using Podfile at the specified path.
  44. function prepareCocoapods() {
  45. cp -f "$@" ./Podfile
  46. echo "Cocoapods version: $(bundle exec pod --version)"
  47. bundle exec pod deintegrate
  48. bundle exec pod update
  49. }
  50. function printUsage() {
  51. echo "USAGE: build_with_environment.sh --gemfile=<path_to_gemfile> --podfile=<path_to_podfile>"
  52. }
  53. for i in "$@"
  54. do
  55. case $i in
  56. --gemfile=*)
  57. GEMFILE="${i#*=}"
  58. shift
  59. ;;
  60. --podfile=*)
  61. PODFILE="${i#*=}"
  62. shift
  63. ;;
  64. *)
  65. printUsage
  66. exit -1
  67. ;;
  68. esac
  69. done
  70. if [ -z ${GEMFILE+x} ]; then
  71. echo "--gemfile=<path_to_gemfile> is a required parameter"
  72. exit -1
  73. fi
  74. if [ -z ${PODFILE+x} ]; then
  75. echo "--podfile=<path_to_podfile> is a required parameter"
  76. exit -1
  77. fi
  78. # Convert path to absolute one in case the script is run from another directory.
  79. RESOLVED_GEMFILE="$(realpath ${GEMFILE})"
  80. RESOLVED_PODFILE="$(realpath ${PODFILE})"
  81. echo "Gemfile = ${RESOLVED_GEMFILE}"
  82. echo "Podfile = ${RESOLVED_PODFILE}"
  83. # Make sure we build from the project root dir.
  84. scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
  85. pushd "${scriptDir}/.."
  86. prepareBundle "${RESOLVED_GEMFILE}"
  87. prepareCocoapods "${RESOLVED_PODFILE}"
  88. runXcodebuild
  89. # Recover original directory just in case
  90. popd