Introduce Gemfile, ruby-version (#32303)

Summary:
Implement par of the discussion https://github.com/react-native-community/discussions-and-proposals/discussions/411, except the `.nvmrc` part, this includes:
 - Setting `.ruby-version` in the main project and also `template/`
 - Fixing the CocoaPods version with a project-level `Gemfile` and also `template/Gemfile`
 - Using all `pod` executions from `bundle exec pod`, using the determined version
 - Script to manage and update the ruby version

## Changelog

[iOS] [Added] - Gemfile with CocoaPods 1.11 and ruby-version (2.7.4)

Pull Request resolved: https://github.com/facebook/react-native/pull/32303

Test Plan: Build for iOS and run all CircleCI tests to see if nothing changed

Reviewed By: RSNara

Differential Revision: D31344686

Pulled By: fkgozali

fbshipit-source-id: 25c63131ca9b16d3cf6341019548e0d63bdcaefe
This commit is contained in:
Gustavo Sverzut Barbieri 2021-10-01 21:21:03 -07:00 committed by Facebook GitHub Bot
parent d8931e2f94
commit 57aa70c06c
18 changed files with 335 additions and 43 deletions

2
.bundle/config Normal file
View File

@ -0,0 +1,2 @@
BUNDLE_PATH: "vendor/bundle"
BUNDLE_FORCE_RUBY_PLATFORM: 1

View File

@ -65,6 +65,16 @@ commands:
name: Initial Setup name: Initial Setup
command: mkdir -p ./reports/{buck,build,junit,outputs} command: mkdir -p ./reports/{buck,build,junit,outputs}
setup_ruby:
steps:
- restore_cache:
key: 1-gems-{{ checksum "Gemfile.lock" }}
- run: bundle check || bundle install --path vendor/bundle --clean
- save_cache:
key: 1-gems-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
run_yarn: run_yarn:
steps: steps:
- restore_cache: - restore_cache:
@ -356,6 +366,7 @@ jobs:
steps: steps:
- checkout - checkout
- setup_artifacts - setup_artifacts
- setup_ruby
- run_yarn - run_yarn
- run: | - run: |
@ -407,7 +418,7 @@ jobs:
- run: - run:
name: Setup the CocoaPods environment name: Setup the CocoaPods environment
command: pod setup command: bundle exec pod setup
- with_rntester_pods_cache_span: - with_rntester_pods_cache_span:
steps: steps:

4
.gitignore vendored
View File

@ -91,6 +91,10 @@ package-lock.json
/React/FBReactNativeSpec/**/*.xcodeproj /React/FBReactNativeSpec/**/*.xcodeproj
/packages/react-native-codegen/**/*.xcodeproj /packages/react-native-codegen/**/*.xcodeproj
# Ruby Gems (Bundler)
/vendor
/template/vendor
# CocoaPods # CocoaPods
/template/ios/Pods/ /template/ios/Pods/
/template/ios/Podfile.lock /template/ios/Podfile.lock

1
.ruby-version Normal file
View File

@ -0,0 +1 @@
2.7.4

6
Gemfile Normal file
View File

@ -0,0 +1,6 @@
source 'https://rubygems.org'
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby '2.7.4'
gem 'cocoapods', '~> 1.11', '>= 1.11.2'

100
Gemfile.lock Normal file
View File

@ -0,0 +1,100 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.4)
rexml
activesupport (6.1.4.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
claide (1.0.3)
cocoapods (1.11.2)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.11.2)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.4.0, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.4.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (>= 2.3.0, < 3.0)
gh_inspector (~> 1.0)
molinillo (~> 0.8.0)
nap (~> 1.0)
ruby-macho (>= 1.0, < 3.0)
xcodeproj (>= 1.21.0, < 2.0)
cocoapods-core (1.11.2)
activesupport (>= 5.0, < 7)
addressable (~> 2.8)
algoliasearch (~> 1.0)
concurrent-ruby (~> 1.1)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
netrc (~> 0.11)
public_suffix (~> 4.0)
typhoeus (~> 1.0)
cocoapods-deintegrate (1.0.5)
cocoapods-downloader (1.5.1)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.1)
cocoapods-trunk (1.6.0)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.2.0)
colored2 (3.1.2)
concurrent-ruby (1.1.9)
escape (0.0.4)
ethon (0.14.0)
ffi (>= 1.15.0)
ffi (1.15.4)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
json (2.5.1)
minitest (5.14.4)
molinillo (0.8.0)
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
public_suffix (4.0.6)
rexml (3.2.5)
ruby-macho (2.5.1)
typhoeus (1.4.0)
ethon (>= 0.9.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
xcodeproj (1.21.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
rexml (~> 3.2.4)
zeitwerk (2.4.2)
PLATFORMS
ruby
DEPENDENCIES
cocoapods (~> 1.11, >= 1.11.2)
RUBY VERSION
ruby 2.7.4p191
BUNDLED WITH
2.2.28

View File

@ -355,7 +355,7 @@ function shouldUseNativeDriver(
'animated module is missing. Falling back to JS-based animation. To ' + 'animated module is missing. Falling back to JS-based animation. To ' +
'resolve this, add `RCTAnimation` module to this app, or remove ' + 'resolve this, add `RCTAnimation` module to this app, or remove ' +
'`useNativeDriver`. ' + '`useNativeDriver`. ' +
'Make sure to run `pod install` first. Read more about autolinking: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md', 'Make sure to run `bundle exec pod install` first. Read more about autolinking: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md',
); );
_warnedMissingNativeAnimated = true; _warnedMissingNativeAnimated = true;
} }

View File

@ -172,6 +172,12 @@ let numberOfChangedLinesWithNewVersion = exec(
{silent: true}, {silent: true},
).stdout.trim(); ).stdout.trim();
// Make sure to update ruby version
if (exec('scripts/update-ruby.sh').code) {
echo('Failed to update Ruby version');
exit(1);
}
// Release builds should commit the version bumps, and create tags. // Release builds should commit the version bumps, and create tags.
// Nightly builds do not need to do that. // Nightly builds do not need to do that.
if (!nightlyBuild) { if (!nightlyBuild) {

View File

@ -6,12 +6,12 @@
set -ex set -ex
SCRIPTS=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) SCRIPTS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT=$(dirname $SCRIPTS) ROOT="$(dirname "$SCRIPTS")"
# Specify `SPEC_REPO` as an env variable if you want to push to a specific spec repo. # Specify `SPEC_REPO` as an env variable if you want to push to a specific spec repo.
# Defaults to `react-test`, which is meant to be a dummy repo used to test that the specs fully lint. # Defaults to `react-test`, which is meant to be a dummy repo used to test that the specs fully lint.
: ${SPEC_REPO:="react-test"} : "${SPEC_REPO:=react-test}"
SPEC_REPO_DIR="$HOME/.cocoapods/repos/$SPEC_REPO" SPEC_REPO_DIR="$HOME/.cocoapods/repos/$SPEC_REPO"
# If the `SPEC_REPO` does not exist yet, assume this is purely for testing and create a dummy repo. # If the `SPEC_REPO` does not exist yet, assume this is purely for testing and create a dummy repo.
@ -28,7 +28,7 @@ fi
cd "$SPEC_REPO_DIR" cd "$SPEC_REPO_DIR"
SPEC_REPOS="$(git remote get-url origin),https://github.com/CocoaPods/Specs.git" SPEC_REPOS="$(git remote get-url origin),https://github.com/CocoaPods/Specs.git"
POD_LINT_OPT="--verbose --allow-warnings --fail-fast --private --swift-version=3.0 --sources=$SPEC_REPOS" POD_LINT_OPT=(--verbose --allow-warnings --fail-fast --private "--swift-version=3.0" "--sources=$SPEC_REPOS")
# Get the version from a podspec. # Get the version from a podspec.
version() { version() {
@ -37,33 +37,34 @@ version() {
# Lint both framework and static library builds. # Lint both framework and static library builds.
lint() { lint() {
local SUBSPEC=$1 local SUBSPEC="$1"
if [ "${SUBSPEC:-}" ]; then if [ "${SUBSPEC:-}" ]; then
local SUBSPEC_OPT="--subspec=$SUBSPEC" local SUBSPEC_OPT="--subspec=$SUBSPEC"
fi fi
pod lib lint $SUBSPEC_OPT $POD_LINT_OPT bundle exec pod lib lint "$SUBSPEC_OPT" "${POD_LINT_OPT[@]}"
pod lib lint $SUBSPEC_OPT $POD_LINT_OPT --use-libraries bundle exec pod lib lint "$SUBSPEC_OPT" "${POD_LINT_OPT[@]}" --use-libraries
} }
# Push the spec in arg `$1`, which is expected to be in the cwd, to the `SPEC_REPO` in JSON format. # Push the spec in arg `$1`, which is expected to be in the cwd, to the `SPEC_REPO` in JSON format.
push() { push() {
local SPEC_NAME=$1 local SPEC_NAME POD_NAME SPEC_DIR SPEC_PATH
local POD_NAME=$(basename $SPEC_NAME .podspec) SPEC_NAME="$1"
local SPEC_DIR="$SPEC_REPO_DIR/$POD_NAME/$(version $SPEC_NAME)" POD_NAME=$(basename "$SPEC_NAME" .podspec)
local SPEC_PATH="$SPEC_DIR/$SPEC_NAME.json" SPEC_DIR="$SPEC_REPO_DIR/$POD_NAME/$(version "$SPEC_NAME")"
mkdir -p $SPEC_DIR SPEC_PATH="$SPEC_DIR/$SPEC_NAME.json"
env INSTALL_YOGA_WITHOUT_PATH_OPTION=1 INSTALL_YOGA_FROM_LOCATION="$ROOT" pod ipc spec $SPEC_NAME > $SPEC_PATH mkdir -p "$SPEC_DIR"
env INSTALL_YOGA_WITHOUT_PATH_OPTION=1 INSTALL_YOGA_FROM_LOCATION="$ROOT" bundle exec pod ipc spec "$SPEC_NAME" > "$SPEC_PATH"
} }
# Perform linting and publishing of podspec in cwd. # Perform linting and publishing of podspec in cwd.
# Skip linting with `SKIP_LINT` if e.g. publishing to a private spec repo. # Skip linting with `SKIP_LINT` if e.g. publishing to a private spec repo.
process() { process() {
cd $1 cd "$1"
if [ -z "$SKIP_LINT" ]; then if [ -z "$SKIP_LINT" ]; then
lint $2 lint "$2"
fi fi
local SPEC_NAME=(*.podspec) local SPEC_NAME=(*.podspec)
push $SPEC_NAME push "${SPEC_NAME[0]}"
} }
# Make third-party deps accessible # Make third-party deps accessible

View File

@ -96,7 +96,7 @@ fi
if [[ $USE_HERMES == true && ! -f "$HERMES_CLI_PATH" ]]; then if [[ $USE_HERMES == true && ! -f "$HERMES_CLI_PATH" ]]; then
echo "error: USE_HERMES is set to true but the hermesc binary could not be " \ echo "error: USE_HERMES is set to true but the hermesc binary could not be " \
"found at ${HERMES_CLI_PATH}. Perhaps you need to run pod install or otherwise " \ "found at ${HERMES_CLI_PATH}. Perhaps you need to run 'bundle exec pod install' or otherwise " \
"point the HERMES_CLI_PATH variable to your custom location." >&2 "point the HERMES_CLI_PATH variable to your custom location." >&2
exit 2 exit 2
fi fi

View File

@ -99,6 +99,7 @@ try {
); );
mv('_flowconfig', '.flowconfig'); mv('_flowconfig', '.flowconfig');
mv('_watchmanconfig', '.watchmanconfig'); mv('_watchmanconfig', '.watchmanconfig');
mv('_bundle', '.bundle');
describe('Install React Native package'); describe('Install React Native package');
exec(`npm install ${REACT_NATIVE_PACKAGE}`); exec(`npm install ${REACT_NATIVE_PACKAGE}`);
@ -210,7 +211,7 @@ try {
echo(`Metro is running, ${SERVER_PID}`); echo(`Metro is running, ${SERVER_PID}`);
describe('Install CocoaPod dependencies'); describe('Install CocoaPod dependencies');
exec('pod install'); exec('bundle exec pod install');
describe('Test: iOS end-to-end test'); describe('Test: iOS end-to-end test');
if ( if (

View File

@ -71,7 +71,7 @@ read -r -n 1
success "About to test iOS JSC... " success "About to test iOS JSC... "
success "Installing CocoaPods dependencies..." success "Installing CocoaPods dependencies..."
rm -rf packages/rn-tester/Pods rm -rf packages/rn-tester/Pods
(cd packages/rn-tester && pod install) (cd packages/rn-tester && bundle exec pod install)
info "Press any key to open the workspace in Xcode, then build and test manually." info "Press any key to open the workspace in Xcode, then build and test manually."
info "" info ""
@ -85,7 +85,7 @@ read -r -n 1
success "About to test iOS Hermes... " success "About to test iOS Hermes... "
success "Installing CocoaPods dependencies..." success "Installing CocoaPods dependencies..."
rm -rf packages/rn-tester/Pods rm -rf packages/rn-tester/Pods
(cd packages/rn-tester && USE_HERMES=1 pod install) (cd packages/rn-tester && USE_HERMES=1 bundle exec pod install)
info "Press any key to open the workspace in Xcode, then build and test manually." info "Press any key to open the workspace in Xcode, then build and test manually."
info "" info ""

66
scripts/update-ruby.sh Executable file
View File

@ -0,0 +1,66 @@
#!/bin/bash
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
set -e
if [ "$VERBOSE" = 1 ]; then
set -x
fi
case $(sed --help 2>&1) in
*GNU*) sed_i () { sed -i "$@"; };;
*) sed_i () { sed -i '' "$@"; };;
esac
SCRIPTS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(dirname "$SCRIPTS")"
die() {
echo "ERROR: $*" >&2
exit 1
}
if [ $# -eq 1 ]; then
VERSION=$1
else
VERSION=$(ruby --version | cut -d' ' -f2 | cut -dp -f1)
fi
if [ -z "$VERSION" ]; then
die "Please provide an installed/usable Ruby version"
fi
echo "Setting Ruby version to: $VERSION"
cd "$ROOT" || die "Failed to change to $ROOT"
# do this first, so rbenv/rvm will automatically pick the desired version
echo "$VERSION" > .ruby-version
# make sure we're using it
CURRENT_VERSION=$(ruby --version | cut -d' ' -f2 | cut -dp -f1)
if [ -z "$CURRENT_VERSION" ]; then
# rbenv/rvm uses shims, the commands do exist, but do not return a version if misconfigured
die "Missing usable ruby, check your installation"
elif [ "$VERSION" != "$CURRENT_VERSION" ]; then
die "Plese use the ruby version you are trying to set: $VERSION ('$CURRENT_VERSION' in use)"
fi
echo "$VERSION" > template/_ruby-version
sed_i -e "s/^\(ruby '\)[^']*\('.*\)$/\1$VERSION\2/" Gemfile
sed_i -e "s/^\(ruby '\)[^']*\('.*\)$/\1$VERSION\2/" template/Gemfile
rm -f Gemfile.lock template/Gemfile.lock
bundle lock
(cd template && bundle lock)
git add \
.ruby-version \
Gemfile \
template/_ruby-version \
template/Gemfile \
template/Gemfile.lock

View File

@ -11,31 +11,16 @@
THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd) THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
RNTESTER_DIR="$THIS_DIR/../packages/rn-tester" RNTESTER_DIR="$THIS_DIR/../packages/rn-tester"
# Note: Keep in sync with FB internal. # Keep this separate for FB internal access.
REQUIRED_COCOAPODS_VERSION="1.11.2"
validate_env () { validate_env () {
# Check that CocoaPods is working. cd "$RNTESTER_DIR" || exit
if [ -z "$(command -v pod)" ]; then bundle check || exit
echo "You need to install CocoaPods." cd "$THIS_DIR" || exit
echo "See https://guides.cocoapods.org/using/getting-started.html#getting-started for instructions."
exit 1
fi
COCOAPODS_VERSION=$(pod --version)
if [[ "$COCOAPODS_VERSION" != "$REQUIRED_COCOAPODS_VERSION" ]];
then
echo "You must have CocoaPods $REQUIRED_COCOAPODS_VERSION installed; you have $COCOAPODS_VERSION."
echo "Installing via gem is recommended:"
echo " sudo gem install cocoapods -v $REQUIRED_COCOAPODS_VERSION"
exit 1
fi
} }
update_pods () { update_pods () {
validate_env
cd "$RNTESTER_DIR" || exit cd "$RNTESTER_DIR" || exit
pod install bundle check || exit
bundle exec pod install
cd "$THIS_DIR" || exit cd "$THIS_DIR" || exit
} }

6
template/Gemfile Normal file
View File

@ -0,0 +1,6 @@
source 'https://rubygems.org'
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby '2.7.4'
gem 'cocoapods', '~> 1.11', '>= 1.11.2'

100
template/Gemfile.lock Normal file
View File

@ -0,0 +1,100 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.4)
rexml
activesupport (6.1.4.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
claide (1.0.3)
cocoapods (1.11.2)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.11.2)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.4.0, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.4.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (>= 2.3.0, < 3.0)
gh_inspector (~> 1.0)
molinillo (~> 0.8.0)
nap (~> 1.0)
ruby-macho (>= 1.0, < 3.0)
xcodeproj (>= 1.21.0, < 2.0)
cocoapods-core (1.11.2)
activesupport (>= 5.0, < 7)
addressable (~> 2.8)
algoliasearch (~> 1.0)
concurrent-ruby (~> 1.1)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
netrc (~> 0.11)
public_suffix (~> 4.0)
typhoeus (~> 1.0)
cocoapods-deintegrate (1.0.5)
cocoapods-downloader (1.5.1)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.1)
cocoapods-trunk (1.6.0)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.2.0)
colored2 (3.1.2)
concurrent-ruby (1.1.9)
escape (0.0.4)
ethon (0.14.0)
ffi (>= 1.15.0)
ffi (1.15.4)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
json (2.5.1)
minitest (5.14.4)
molinillo (0.8.0)
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
public_suffix (4.0.6)
rexml (3.2.5)
ruby-macho (2.5.1)
typhoeus (1.4.0)
ethon (>= 0.9.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
xcodeproj (1.21.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
rexml (~> 3.2.4)
zeitwerk (2.4.2)
PLATFORMS
arm64-darwin-20
DEPENDENCIES
cocoapods (~> 1.11, >= 1.11.2)
RUBY VERSION
ruby 2.7.4p191
BUNDLED WITH
2.2.28

2
template/_bundle/config Normal file
View File

@ -0,0 +1,2 @@
BUNDLE_PATH: "vendor/bundle"
BUNDLE_FORCE_RUBY_PLATFORM: 1

1
template/_ruby-version Normal file
View File

@ -0,0 +1 @@
2.7.4