From 2126a738bcb775d71bffc44490b52a6f752d3320 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Fri, 10 Feb 2023 19:52:33 -0800 Subject: [PATCH] Actually install the correct version of ruby to install cocoapods - If we already have the desired version, we are good - If we don't, but we have brew, we install the desired version - If we don't have brew, but we have a sufficiently recent OSX, we are good - If we don't have brew and we don't have a sufficiently recent OSX, we warn that there might be problems --- README.md | 4 +++ setup/export_shared_dep_versions.sh | 9 ++++-- setup/setup_ios_native.sh | 46 +++++++++++++++++------------ 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index c9b029ec0..85fc73f21 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,10 @@ Pre-requisites ``` +- if you are not on the most recent version of OSX, `homebrew` + - this allows us to install the current version of cocoapods without + running into ruby incompatibilities - e.g. + https://github.com/CocoaPods/CocoaPods/issues/11763 Important --- diff --git a/setup/export_shared_dep_versions.sh b/setup/export_shared_dep_versions.sh index 123580155..74ffb7087 100644 --- a/setup/export_shared_dep_versions.sh +++ b/setup/export_shared_dep_versions.sh @@ -1,9 +1,14 @@ export NVM_VERSION=0.39.0 export NODE_VERSION=14.18.1 export NPM_VERSION=6.14.15 -export RUBY_VERSION=2.6.0 +# make sure that this is a stable version from +# so that https://github.com/postmodern/ruby-versions +# ideally, this would be the same version as the CI +# Looks like brew supports only major and minor, not patch version +export RUBY_VERSION=2.7 export COCOAPODS_VERSION=1.11.2 export GRADLE_VERSION=7.1.1 +export OSX_EXP_VERSION=12 export NVM_DIR="$HOME/.nvm" -export RUBY_PATH=$HOME/.gem/ruby/$RUBY_VERSION/bin +export RUBY_PATH=$HOME/.gem/ruby/$RUBY_VERSION.0/bin diff --git a/setup/setup_ios_native.sh b/setup/setup_ios_native.sh index 16c04118f..07cd0e977 100644 --- a/setup/setup_ios_native.sh +++ b/setup/setup_ios_native.sh @@ -4,26 +4,34 @@ set -e # Setup the development environment source setup/setup_shared.sh -# Importing rvm keys -curl -sSL https://rvm.io/mpapis.asc | gpg2 --import - -curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import - - -# Download and install rvm -echo "Installing stable rvm" -curl -sSL https://get.rvm.io | bash -s stable - -# Enable rvm -source /Users/kshankar/.rvm/scripts/rvm - -# Download and install ruby -echo "Installing ruby $RUBY_VERSION" -rvm install ruby-$RUBY_VERSION - -echo "Switching to ruby version $RUBY_VERSION" -rvm use $RUBY_VERSION - +OSX_MAJOR_VERSION=`sw_vers | grep ProductVersion | cut -d ':' -f 2 | cut -d '.' -f 1` +echo "Found OSX major version" $OSX_MAJOR_VERSION + +CURR_RUBY_VERSION=`ruby --version | cut -d ' ' -f 2 | cut -d '.' -f 1-2` +echo "Found ruby version "$CURR_RUBY_VERSION + +if [ $CURR_RUBY_VERSION == $RUBY_VERSION ]; then + echo "Found ruby version "$CURR_RUBY_VERSION" expected "$RUBY_VERSION" no need to upgrade" +else + if [ -x /usr/local/bin/brew ]; then + echo "Found brew installation with version" `/usr/local/bin/brew --version` + echo "Installing ruby version to brew" $RUBY_VERSION + brew install ruby@$RUBY_VERSION + else + if [ $OSX_MAJOR_VERSION -ge $OSX_EXP_VERSION ]; then + echo "No brew installation found, but OSX major version "$OSX_MAJOR_VERSION" and expected version "$OSX_EXP_VERSION" so CocoaPods should work" + else + echo "No brew installation found, but OSX major version "$OSX_MAJOR_VERSION" != expected version "$OSX_EXP_VERSION" CocoaPods install will likely fail" + echo "Found ruby version "`ruby --version` + exit 1 + fi + fi +fi + +echo "Adding $RUBY_PATH to the path before the install" export PATH=$RUBY_PATH:$PATH + echo "Installing cocoapods" -gem install --no-document --user-install cocoapods -v $COCOAPODS_VERSION +/usr/local/opt/ruby@$RUBY_VERSION/bin/gem install --no-document --user-install cocoapods -v $COCOAPODS_VERSION source setup/setup_shared_native.sh