prepare_build_macos_rc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #!/bin/bash
  2. # Copyright 2017 gRPC authors.
  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. # Source this rc script to prepare the environment for macos builds
  16. # Print basic info about the mac worker
  17. echo "kokoro pool: \"$KOKORO_JOB_POOL\""
  18. echo "OS: $(sw_vers -productName) $(sw_vers -productVersion) $(sw_vers -buildVersion)"
  19. echo "CPU type: $(sysctl -n machdep.cpu.brand_string)"
  20. echo "CPU: $(sysctl -n machdep.cpu.vendor) $(uname -m) Family $(sysctl -n machdep.cpu.family) Model $(sysctl -n machdep.cpu.brand_string)"
  21. echo "CPU Cores: $(sysctl -n hw.ncpu)"
  22. echo "Memory: $(sysctl -n hw.memsize)"
  23. # Info on disk usage and mounted volumes
  24. mount
  25. df -h /tmpfs /
  26. # show original open file limit values
  27. launchctl limit maxfiles
  28. ulimit -a
  29. # WARNING: TRY TO KEEP THIS FILE AS LEAN AS POSSIBLE
  30. # The rules:
  31. # - think twice before adding installer that takes long time (builds are already slow)
  32. # - do not add any steps that are flaky (builds will become flaky)
  33. # - try adding a dependency under a language-specific section first (reduces latency and increases build stability)
  34. # - only add stuff that you absolutely need for your builds to work (add comment to explain why its needed)
  35. # Disable HOMEBREW update to avoid new updates which potentially have problems.
  36. # Brew packages installed when Kokoro image was built tend to have less conflict.
  37. export HOMEBREW_NO_AUTO_UPDATE=1
  38. # Dump the brew configuration for debugging just in case. Check "Core tap HEAD" field
  39. # because it should be the same as below unless it's been updated.
  40. # - Kokoro MacOS Mojave: 27fa87c94a6cf7be40fc8f8fc96bc7c387b7781e
  41. brew config
  42. # Add GCP credentials for BQ access
  43. pip install --user google-api-python-client oauth2client six==1.16.0
  44. export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/GrpcTesting-d0eeee2db331.json
  45. DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
  46. # If this is a PR using RUN_TESTS_FLAGS var, then add flags to filter tests
  47. if [ -n "$KOKORO_GITHUB_PULL_REQUEST_NUMBER" ]; then
  48. export RUN_TESTS_FLAGS="--filter_pr_tests --base_branch origin/$KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH $RUN_TESTS_FLAGS"
  49. fi
  50. if [ "${PREPARE_BUILD_INSTALL_DEPS_RUBY}" == "true" ]
  51. then
  52. # Workaround for https://github.com/rvm/rvm/issues/5133
  53. export CURL_CA_BUNDLE=$(pwd)/etc/roots.pem
  54. # Fetch keys per https://rvm.io/rvm/install
  55. gpg_recv_keys_success=0
  56. for ((i=0;i<5;i++)); do
  57. # Use the Ubuntu keyserver instead of pool.sks-keyservers.net because sks-keyservers is now deprecated.
  58. GPG_KEYSERVER_ADDRESS="keyserver.ubuntu.com"
  59. gpg --keyserver "hkp://${GPG_KEYSERVER_ADDRESS}" --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB \
  60. && gpg_recv_keys_success=1
  61. [[ "$gpg_recv_keys_success" == 1 ]] && break
  62. sleep 3
  63. done
  64. [[ "$gpg_recv_keys_success" == 1 ]] || exit 1
  65. rvm get stable # Per https://stackoverflow.com/questions/65477613/rvm-where-is-ruby-3-0-0
  66. # stop echoing bash commands temporarily to prevent rvm from polluting the logs
  67. set +x
  68. source $HOME/.rvm/scripts/rvm
  69. for RUBY_VERSION in 2.5.0 2.7.0 3.0.0; do
  70. echo "Installing ruby-${RUBY_VERSION}"
  71. time rvm install "ruby-${RUBY_VERSION}"
  72. done;
  73. echo "Setting default ruby version."
  74. rvm use 2.5.0 --default
  75. echo "Installing cocoapods."
  76. time gem install cocoapods --version 1.3.1 --no-document
  77. echo "Updating osx-ssl-certs."
  78. rvm osx-ssl-certs status all
  79. rvm osx-ssl-certs update all
  80. # restore echo
  81. set -x
  82. fi
  83. if [ "${PREPARE_BUILD_INSTALL_DEPS_OBJC}" == "true" ]
  84. then
  85. # cocoapods
  86. export LANG=en_US.UTF-8
  87. time gem install cocoapods --version 1.7.2 --no-document
  88. # pre-fetch cocoapods master repo's most recent commit only
  89. mkdir -p ~/.cocoapods/repos
  90. time git clone --depth 1 https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/master
  91. # Needed for ios-binary-size
  92. time pip install --user -r $DIR/requirements.macos.txt
  93. # Store intermediate build files of ObjC tests into /tmpfs
  94. # TODO(jtattermusch): this has likely been done to avoid running
  95. # out of disk space when running ios-binary-size tests, but
  96. # it would be good to revisit.
  97. mkdir /tmpfs/Build-ios-binary-size
  98. ln -s /tmpfs/Build-ios-binary-size src/objective-c/examples/Sample/Build
  99. mkdir -p /tmpfs/DerivedData
  100. rm -rf ~/Library/Developer/Xcode/DerivedData
  101. mkdir -p ~/Library/Developer/Xcode
  102. ln -s /tmpfs/DerivedData ~/Library/Developer/Xcode/DerivedData
  103. fi
  104. if [ "${PREPARE_BUILD_INSTALL_DEPS_PYTHON}" == "true" ]
  105. then
  106. # python
  107. time pip install --user -r $DIR/requirements.macos.txt
  108. time pip install --user --upgrade virtualenv Mako tox setuptools==44.1.1 twisted
  109. # Install Python 3.7 if it doesn't exist
  110. if [ ! -f "/usr/local/bin/python3.7" ]; then
  111. time curl -O https://www.python.org/ftp/python/3.7.0/python-3.7.0-macosx10.9.pkg
  112. echo "ee4ad46ab8cd226ffc8df56d48acfdf7daa2714a9c51e6dc6262fc0b25519578 python-3.7.0-macosx10.9.pkg" > /tmp/python_installer_checksum.sha256
  113. shasum -c /tmp/python_installer_checksum.sha256
  114. time sudo installer -pkg ./python-3.7.0-macosx10.9.pkg -target /
  115. fi
  116. # Install Python 3.8 if it doesn't exist
  117. if [ ! -f "/usr/local/bin/python3.8" ]; then
  118. time curl -O https://www.python.org/ftp/python/3.8.0/python-3.8.0-macosx10.9.pkg
  119. echo "30961fe060da9dc5afdc4e789a57fe9bcc0d20244474e9f095d7bfc89d2e1869 python-3.8.0-macosx10.9.pkg" > /tmp/python_installer_checksum.sha256
  120. shasum -c /tmp/python_installer_checksum.sha256
  121. time sudo installer -pkg ./python-3.8.0-macosx10.9.pkg -target /
  122. fi
  123. # Install Python 3.9 if it doesn't exist
  124. if [ ! -f "/usr/local/bin/python3.9" ]; then
  125. time curl -O https://www.python.org/ftp/python/3.9.0/python-3.9.0-macosx10.9.pkg
  126. echo "dadee1d10c1a8ed58bb64ec7409a48c9fe38599791eaaea29303ee59fb95dfeb python-3.9.0-macosx10.9.pkg" > /tmp/python_installer_checksum.sha256
  127. shasum -c /tmp/python_installer_checksum.sha256
  128. time sudo installer -pkg ./python-3.9.0-macosx10.9.pkg -target /
  129. fi
  130. # Install Python 3.10 if it doesn't exist
  131. if [ ! -f "/usr/local/bin/python3.10" ]; then
  132. time curl -O https://www.python.org/ftp/python/3.10.0/python-3.10.0rc1-macos11.pkg
  133. echo "5933d3d72438b03742d2bb3c8d6cb0e5db165d7110bbc95dac8016f5e31fae7b python-3.10.0rc1-macos11.pkg" > /tmp/python_installer_checksum.sha256
  134. shasum -c /tmp/python_installer_checksum.sha256
  135. time sudo installer -pkg ./python-3.10.0rc1-macos11.pkg -target /
  136. fi
  137. fi
  138. if [ "${PREPARE_BUILD_INSTALL_DEPS_CSHARP}" == "true" ]
  139. then
  140. # Disable some unwanted dotnet options
  141. export NUGET_XMLDOC_MODE=skip
  142. export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
  143. export DOTNET_CLI_TELEMETRY_OPTOUT=true
  144. # Installed versions should be kept in sync with
  145. # templates/tools/dockerfile/csharp_dotnetcli_deps.include
  146. time curl -O https://download.visualstudio.microsoft.com/download/pr/e0fe8c99-e33c-4d75-bd4e-2478ed3ee35a/ff06e47afc7c13bdbbaa50a9713ac772/dotnet-sdk-3.1.415-osx-x64.pkg
  147. time sudo installer -pkg ./dotnet-sdk-3.1.415-osx-x64.pkg -target /
  148. time curl -O https://download.visualstudio.microsoft.com/download/pr/14a45451-4cc9-48e1-af69-0aff75891d09/ff6e83986a2a9a535015fb3104a90a1b/dotnet-sdk-6.0.100-osx-x64.pkg
  149. time sudo installer -pkg ./dotnet-sdk-6.0.100-osx-x64.pkg -target /
  150. fi
  151. if [ "${PREPARE_BUILD_INSTALL_DEPS_PHP}" == "true" ]
  152. then
  153. # It's required to update homebrew because it won't work with the default version Kokoro has.
  154. # This can be fragile though because the future version of brew can break - consider pinning
  155. # the formulas if that happens (see https://github.com/grpc/grpc/pull/24837).
  156. brew update || true
  157. # macos mojave support for php7.3 brew formula removed MacOS Mojave support here: https://github.com/Homebrew/homebrew-core/commit/d8496609d310a233bfb46272ec7948845f32d7c5#diff-df64282b6e4230b6f35468dfbbd500fcd62b0f93b01b2b161e92f512b7feb1a3
  158. # so we need earlier version of the formulata than that. See https://github.com/grpc/grpc/pull/24837 for an example of pinning homebrew formulas to a specific commit.
  159. (cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core; git checkout 10b1944581fbbdc216057fd70e89dbbe3d04161e)
  160. brew config
  161. brew install php@7.3 || true
  162. export LDFLAGS="-L/usr/local/opt/php@7.3/lib ${LDFLAGS}"
  163. export CPPFLAGS="-I/usr/local/opt/php@7.3/include ${CPPFLAGS}"
  164. export PATH="/usr/local/opt/php@7.3/bin:/usr/local/opt/php@7.3/sbin:${PATH}"
  165. # the exit code from "brew install php@7.3" is useless
  166. # so instead we check if PHP was indeed installed successfully.
  167. # Failing early is better than cryptic errors later in the build process.
  168. /usr/local/opt/php@7.3/bin/php --version
  169. # Workaround for https://github.com/Homebrew/homebrew-core/issues/41081
  170. mkdir -p /usr/local/lib/php/pecl
  171. fi
  172. # TODO(jtattermusch): better debugging of clock skew, remove once not needed
  173. date
  174. time git submodule update --init