Skip to content

Commit

Permalink
Introduce Gemfile, ruby-version (facebook#32303)
Browse files Browse the repository at this point in the history
Summary:
Implement par of the discussion react-native-community/discussions-and-proposals#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: facebook#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
  • Loading branch information
barbieri authored and facebook-github-bot committed Oct 2, 2021
1 parent d8931e2 commit 57aa70c
Show file tree
Hide file tree
Showing 18 changed files with 335 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BUNDLE_PATH: "vendor/bundle"
BUNDLE_FORCE_RUBY_PLATFORM: 1
13 changes: 12 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ commands:
name: Initial Setup
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:
steps:
- restore_cache:
Expand Down Expand Up @@ -356,6 +366,7 @@ jobs:
steps:
- checkout
- setup_artifacts
- setup_ruby
- run_yarn

- run: |
Expand Down Expand Up @@ -407,7 +418,7 @@ jobs:

- run:
name: Setup the CocoaPods environment
command: pod setup
command: bundle exec pod setup

- with_rntester_pods_cache_span:
steps:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ package-lock.json
/React/FBReactNativeSpec/**/*.xcodeproj
/packages/react-native-codegen/**/*.xcodeproj

# Ruby Gems (Bundler)
/vendor
/template/vendor

# CocoaPods
/template/ios/Pods/
/template/ios/Podfile.lock
Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.7.4
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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 changes: 100 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Libraries/Animated/NativeAnimatedHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ function shouldUseNativeDriver(
'animated module is missing. Falling back to JS-based animation. To ' +
'resolve this, add `RCTAnimation` module to this app, or remove ' +
'`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;
}
Expand Down
6 changes: 6 additions & 0 deletions scripts/bump-oss-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ let numberOfChangedLinesWithNewVersion = exec(
{silent: true},
).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.
// Nightly builds do not need to do that.
if (!nightlyBuild) {
Expand Down
33 changes: 17 additions & 16 deletions scripts/process-podspecs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

set -ex

SCRIPTS=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
ROOT=$(dirname $SCRIPTS)
SCRIPTS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(dirname "$SCRIPTS")"

# 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.
: ${SPEC_REPO:="react-test"}
: "${SPEC_REPO:=react-test}"
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.
Expand All @@ -28,7 +28,7 @@ fi
cd "$SPEC_REPO_DIR"
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.
version() {
Expand All @@ -37,33 +37,34 @@ version() {

# Lint both framework and static library builds.
lint() {
local SUBSPEC=$1
local SUBSPEC="$1"
if [ "${SUBSPEC:-}" ]; then
local SUBSPEC_OPT="--subspec=$SUBSPEC"
fi
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[@]}"
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() {
local SPEC_NAME=$1
local POD_NAME=$(basename $SPEC_NAME .podspec)
local SPEC_DIR="$SPEC_REPO_DIR/$POD_NAME/$(version $SPEC_NAME)"
local SPEC_PATH="$SPEC_DIR/$SPEC_NAME.json"
mkdir -p $SPEC_DIR
env INSTALL_YOGA_WITHOUT_PATH_OPTION=1 INSTALL_YOGA_FROM_LOCATION="$ROOT" pod ipc spec $SPEC_NAME > $SPEC_PATH
local SPEC_NAME POD_NAME SPEC_DIR SPEC_PATH
SPEC_NAME="$1"
POD_NAME=$(basename "$SPEC_NAME" .podspec)
SPEC_DIR="$SPEC_REPO_DIR/$POD_NAME/$(version "$SPEC_NAME")"
SPEC_PATH="$SPEC_DIR/$SPEC_NAME.json"
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.
# Skip linting with `SKIP_LINT` if e.g. publishing to a private spec repo.
process() {
cd $1
cd "$1"
if [ -z "$SKIP_LINT" ]; then
lint $2
lint "$2"
fi
local SPEC_NAME=(*.podspec)
push $SPEC_NAME
push "${SPEC_NAME[0]}"
}

# Make third-party deps accessible
Expand Down
2 changes: 1 addition & 1 deletion scripts/react-native-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fi

if [[ $USE_HERMES == true && ! -f "$HERMES_CLI_PATH" ]]; then
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
exit 2
fi
Expand Down
3 changes: 2 additions & 1 deletion scripts/run-ci-e2e-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ try {
);
mv('_flowconfig', '.flowconfig');
mv('_watchmanconfig', '.watchmanconfig');
mv('_bundle', '.bundle');

describe('Install React Native package');
exec(`npm install ${REACT_NATIVE_PACKAGE}`);
Expand Down Expand Up @@ -210,7 +211,7 @@ try {
echo(`Metro is running, ${SERVER_PID}`);

describe('Install CocoaPod dependencies');
exec('pod install');
exec('bundle exec pod install');

describe('Test: iOS end-to-end test');
if (
Expand Down
4 changes: 2 additions & 2 deletions scripts/test-manual-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ read -r -n 1
success "About to test iOS JSC... "
success "Installing CocoaPods dependencies..."
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 ""
Expand All @@ -85,7 +85,7 @@ read -r -n 1
success "About to test iOS Hermes... "
success "Installing CocoaPods dependencies..."
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 ""
Expand Down
66 changes: 66 additions & 0 deletions scripts/update-ruby.sh
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 57aa70c

Please sign in to comment.