1ffe3c632Sopenharmony_ci#!/bin/bash
2ffe3c632Sopenharmony_ci#
3ffe3c632Sopenharmony_ci# This script sets up a Kokoro MacOS worker for running Protobuf tests
4ffe3c632Sopenharmony_ci
5ffe3c632Sopenharmony_ciset -eux
6ffe3c632Sopenharmony_ci
7ffe3c632Sopenharmony_ci##
8ffe3c632Sopenharmony_ci# Select Xcode version
9ffe3c632Sopenharmony_ci
10ffe3c632Sopenharmony_ci# Remember to update the Xcode version when Xcode_11.3.app is not available.
11ffe3c632Sopenharmony_ci# If xcode is not available, it will probably encounter the failure for
12ffe3c632Sopenharmony_ci# "autom4te: need GNU m4 1.4 or later: /usr/bin/m4"
13ffe3c632Sopenharmony_ci# go/kokoro/userdocs/macos/selecting_xcode.md for more information.
14ffe3c632Sopenharmony_ciexport DEVELOPER_DIR=/Applications/Xcode_11.3.app/Contents/Developer
15ffe3c632Sopenharmony_ci
16ffe3c632Sopenharmony_ci##
17ffe3c632Sopenharmony_ci# Select C/C++ compilers
18ffe3c632Sopenharmony_ci
19ffe3c632Sopenharmony_ciexport CC=gcc
20ffe3c632Sopenharmony_ciexport CXX=g++
21ffe3c632Sopenharmony_ci
22ffe3c632Sopenharmony_ci##
23ffe3c632Sopenharmony_ci# Brew: update, then upgrade the installed tools to current version and install
24ffe3c632Sopenharmony_ci# some needed ones not in the Kokoro base image. This ensure current versions
25ffe3c632Sopenharmony_ci# of CMake, autotools, etc.
26ffe3c632Sopenharmony_ci
27ffe3c632Sopenharmony_ci# But first...
28ffe3c632Sopenharmony_ci#
29ffe3c632Sopenharmony_ci# The transitive deps of the installed tools need protobuf, but Kokoro manually
30ffe3c632Sopenharmony_ci# installed it outside of brew so it needs to be removed so brew can install the
31ffe3c632Sopenharmony_ci# tools (and a newer version of protobuf). g/kokoro-users/7FRvQMUdN40 about why
32ffe3c632Sopenharmony_ci# it is a manual install vs. a brew install in the first place.
33ffe3c632Sopenharmony_cisudo rm -rf \
34ffe3c632Sopenharmony_ci    /usr/local/include/google/protobuf \
35ffe3c632Sopenharmony_ci    /usr/local/bin/protoc
36ffe3c632Sopenharmony_ci# Likewise, updating python can have issues because of some existing binaries.
37ffe3c632Sopenharmony_cisudo rm -rf \
38ffe3c632Sopenharmony_ci    /usr/local/bin/2to3* \
39ffe3c632Sopenharmony_ci    /usr/local/bin/idle3* \
40ffe3c632Sopenharmony_ci    /usr/local/bin/pydoc3* \
41ffe3c632Sopenharmony_ci    /usr/local/bin/python3* \
42ffe3c632Sopenharmony_ci    /usr/local/bin/pyvenv*
43ffe3c632Sopenharmony_ci
44ffe3c632Sopenharmony_cibrew update
45ffe3c632Sopenharmony_cibrew upgrade
46ffe3c632Sopenharmony_ci
47ffe3c632Sopenharmony_ci##
48ffe3c632Sopenharmony_ci# Install Ruby
49ffe3c632Sopenharmony_ci
50ffe3c632Sopenharmony_ciif [[ "${KOKORO_INSTALL_RUBY:-}" == "yes" ]] ; then
51ffe3c632Sopenharmony_ci  brew install ruby
52ffe3c632Sopenharmony_cifi
53ffe3c632Sopenharmony_ci
54ffe3c632Sopenharmony_ci##
55ffe3c632Sopenharmony_ci# Install Cocoapods
56ffe3c632Sopenharmony_ci
57ffe3c632Sopenharmony_ciif [[ "${KOKORO_INSTALL_COCOAPODS:-}" == "yes" ]] ; then
58ffe3c632Sopenharmony_ci  # The existing cocoapods was installed via gem, but that doesn't work well
59ffe3c632Sopenharmony_ci  # with the overlap in deps with things managed by brew (errors around ruby
60ffe3c632Sopenharmony_ci  # versions, etc.); so remove it and install in via brew instead.
61ffe3c632Sopenharmony_ci  gem uninstall -a "$(gem list | grep cocoapods | cut -d ' ' -f 1)"
62ffe3c632Sopenharmony_ci  brew install cocoapods
63ffe3c632Sopenharmony_cifi
64ffe3c632Sopenharmony_ci
65ffe3c632Sopenharmony_ci##
66ffe3c632Sopenharmony_ci# Install Tox
67ffe3c632Sopenharmony_ci
68ffe3c632Sopenharmony_ciif [[ "${KOKORO_INSTALL_TOX:-}" == "yes" ]] ; then
69ffe3c632Sopenharmony_ci  sudo python3 -m pip install --upgrade pip tox
70ffe3c632Sopenharmony_cifi
71ffe3c632Sopenharmony_ci
72ffe3c632Sopenharmony_ci##
73ffe3c632Sopenharmony_ci# Install RVM
74ffe3c632Sopenharmony_ci
75ffe3c632Sopenharmony_ciif [[ "${KOKORO_INSTALL_RVM:-}" == "yes" ]] ; then
76ffe3c632Sopenharmony_ci  curl -sSL https://rvm.io/mpapis.asc | gpg --import -
77ffe3c632Sopenharmony_ci  curl -sSL https://rvm.io/pkuczynski.asc | gpg --import -
78ffe3c632Sopenharmony_ci
79ffe3c632Sopenharmony_ci  curl -sSL https://get.rvm.io | bash -s stable --ruby
80ffe3c632Sopenharmony_cifi
81