Skip to content

Commit

Permalink
Introduce .xcode.env configuration file to source node
Browse files Browse the repository at this point in the history
Summary:
This Diff does 2 things:
1. Removes all the remnant of the `find-node.sh` script. This allows React Native to stay agnostic from any other node manager
2. Introduces a way for the developers to specify which `node` executable they want to use, through a simple `.env` file.

## Changelog
[iOS][Changed] - This PR removes the `find-node.sh` scripts and replaces it with an `.xcode.env` file that is sourced by the script phases that needs it. The `.xcode.env` file is versioned: to customize a local environment, an unversioned `.xcode.local.env` can be used.

Differential Revision: D35317070

fbshipit-source-id: 6ca01077cb61f7fa04bcc50cb8b365fe4dd696d4
  • Loading branch information
Riccardo Cipolleschi authored and facebook-github-bot committed Apr 1, 2022
1 parent 124826a commit ae38ffe
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 101 deletions.
6 changes: 0 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,6 @@ jobs:
- brew_install:
package: applesimutils

- run:
name: Configure Node
# Sourcing find-node.sh will ensure nvm is set up.
# It also helps future invocation of find-node.sh prevent permission issue with nvm.sh.
command: source scripts/find-node-for-xcode.sh && nvm install 16 && nvm alias default 16

- run:
name: Configure Watchman
command: echo "{}" > .watchmanconfig
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ DerivedData
*.ipa
*.xcuserstate
project.xcworkspace
packages/rn-tester/.xcode.local.env

# Gradle
/build/
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"README.md",
"rn-get-polyfills.js",
"scripts/compose-source-maps.js",
"scripts/find-node-for-xcode.sh",
"scripts/generate-artifacts.js",
"scripts/generate-provider-cli.js",
"scripts/generate-specs-cli.js",
Expand Down
4 changes: 4 additions & 0 deletions packages/rn-tester/.xcode.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# PATH to the node executable. You can use the `command -v node` to check what value make sense for your set up
# This `.xcode.env` file is versioned. To customize your local environment, you can create an `.xcode.local.env`
# file that is not versioned.
export NODE_BINARY=/usr/local/bin/node
6 changes: 3 additions & 3 deletions packages/rn-tester/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ SPEC CHECKSUMS:
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
FBLazyVector: 19e408e76fa9258dd32191a50d60c41444f52d29
FBReactNativeSpec: fc6b3c34276fb05bb3e0f6bccc50e21dd38de5bf
FBReactNativeSpec: e68b48bb704799479631b7dd7b9d6401c5c97089
Flipper: 26fc4b7382499f1281eb8cb921e5c3ad6de91fe0
Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c
Flipper-DoubleConversion: 3d3d04a078d4f3a1b6c6916587f159dc11f232c4
Expand Down Expand Up @@ -934,10 +934,10 @@ SPEC CHECKSUMS:
React-RCTTest: 451f186880271c249a3ff65761f569592a7765e1
React-RCTText: a861fbf2835299d3cc4189697cddd8bd8602afb9
React-RCTVibration: 00dbb5e9451af741c77be12978281ded80046f3d
React-rncore: ed4c24b136f613ebbcfc780a33e2bc23021f3eae
React-rncore: d1eb68f86013f765b075c1e7c2cb07ecedb135ab
React-runtimeexecutor: 97dca9247f4d3cfe0733384b189c6930fbd402b7
ReactCommon: 4a2e9e61ef59dc6f7b92f05a6b9e37a0013ee854
ScreenshotManager: 8baf7f62c6b602ba59ea979d9ed294c98ee3019e
ScreenshotManager: 1ada1f2bd91e08e4790d63bc5e8f537cb90f901c
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
Yoga: cdc7a2377fc03a2d44322b7784a2461b4c17da09
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
Expand Down
4 changes: 3 additions & 1 deletion packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -633,13 +633,15 @@
files = (
);
inputPaths = (
"$(SRCROOT)/.xcode.local.env",
"$(SRCROOT)/.xcode.env",
);
name = "Build JS Bundle";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -e\n\nexport NODE_BINARY=node\nexport PROJECT_ROOT=\"$SRCROOT/../../\"\nexport ENTRY_FILE=\"$SRCROOT/js/RNTesterApp.ios.js\"\nexport SOURCEMAP_FILE=../sourcemap.ios.map\n# export FORCE_BUNDLING=true\n\"$SRCROOT/../../scripts/react-native-xcode.sh\"\n";
shellScript = "set -e\n\nexport PROJECT_ROOT=\"$SRCROOT/../../\"\nexport ENTRY_FILE=\"$SRCROOT/js/RNTesterApp.ios.js\"\nexport SOURCEMAP_FILE=../sourcemap.ios.map\n# export FORCE_BUNDLING=true \n\nif [ -f $SCRIPT_INPUT_FILE_0 ]; then\n source $SCRIPT_INPUT_FILE_0\nelif [ -f $SCRIPT_INPUT_FILE_1 ]; then\n source $SCRIPT_INPUT_FILE_1\nfi\n\n\"$SRCROOT/../../scripts/react-native-xcode.sh\"\n";
};
98E057AC8860597818FB485A /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
80 changes: 0 additions & 80 deletions scripts/find-node-for-xcode.sh

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/react-native-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ if [[ $DEV != true && ! -f "$ENTRY_FILE" ]]; then
exit 2
fi

# Find path to Node
# shellcheck source=/dev/null
source "$REACT_NATIVE_DIR/scripts/find-node-for-xcode.sh"

# check and assign NODE_BINARY env
# shellcheck source=/dev/null
source "$REACT_NATIVE_DIR/scripts/node-binary.sh"
Expand Down
4 changes: 3 additions & 1 deletion scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,11 @@ def use_react_native_codegen!(spec, options={})
system(prepare_command) # Always run prepare_command when a podspec uses the codegen, as CocoaPods may skip invoking this command in certain scenarios. Replace with pre_integrate_hook after updating to CocoaPods 1.11
spec.prepare_command = prepare_command

env_files = ["$PODS_ROOT/../.xcode.local.env", "$PODS_ROOT/../.xcode.env"]

spec.script_phase = {
:name => 'Generate Specs',
:input_files => input_files, # This also needs to be relative to Xcode
:input_files => input_files + env_files, # This also needs to be relative to Xcode
:output_files => ["${DERIVED_FILE_DIR}/codegen-#{library_name}.log"].concat(generated_files.map { |filename| "${PODS_TARGET_SRCROOT}/#{filename}"} ),
# The final generated files will be created when this script is invoked at Xcode build time.
:script => get_script_phases_no_codegen_discovery(
Expand Down
10 changes: 9 additions & 1 deletion scripts/react_native_pods_utils/script_phases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,18 @@ def get_script_template(react_native_path, export_vars={})
export <%= varname -%>=<%= value -%>
<% end %>
LOCAL_ENV_PATH="$PODS_ROOT/../.xcode.local.env"
ENV_PATH="$PODS_ROOT/../.xcode.env"
if [ -f $LOCAL_ENV_PATH ]; then
source $LOCAL_ENV_PATH
elif [ -f $ENV_PATH ]; then
source $ENV_PATH
fi
SCRIPT_PHASES_SCRIPT="$RCT_SCRIPT_RN_DIR/scripts/react_native_pods_utils/script_phases.sh"
/bin/sh -c "$SCRIPT_PHASES_SCRIPT"
EOS
result = ERB.new(template, 0, '->').result(binding)
# puts result
return result
end
3 changes: 0 additions & 3 deletions scripts/react_native_pods_utils/script_phases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ else
fi

find_node () {
# shellcheck disable=SC1091
source "$RCT_SCRIPT_RN_DIR/scripts/find-node-for-xcode.sh"

NODE_BINARY="${NODE_BINARY:-$(command -v node || true)}"
if [ -z "$NODE_BINARY" ]; then
error "error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable."
Expand Down
1 change: 1 addition & 0 deletions template/_gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate
ios/.xcode.local.env

# Android/IntelliJ
#
Expand Down
4 changes: 4 additions & 0 deletions template/ios/.xcode.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# PATH to the node executable. You can use the `command -v node` to check what value make sense for your set up
# This `.xcode.env` file is versioned. To customize your local environment, you can create an `.xcode.local.env`
# file that is not versioned.
export NODE_BINARY=/usr/local/bin/node
4 changes: 3 additions & 1 deletion template/ios/HelloWorld.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,15 @@
files = (
);
inputPaths = (
"$(SRCROOT)/.xcode.local.env",
"$(SRCROOT)/.xcode.env",
);
name = "Bundle React Native code and images";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -e\n\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
shellScript = "set -e\n\nif [ -f $SCRIPT_INPUT_FILE_0 ]; then\n source $SCRIPT_INPUT_FILE_0\nelif [ -f $SCRIPT_INPUT_FILE_1 ]; then\n source $SCRIPT_INPUT_FILE_1\nfi\n\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
};
00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
Expand Down

0 comments on commit ae38ffe

Please sign in to comment.