Skip to content

Commit 705c6f5

Browse files
Riccardo Cipolleschifacebook-github-bot
Riccardo Cipolleschi
authored andcommitted
Export REACT_NATIVE_PATH and fix find-node-for-xcode.sh fallback behavior (#33674)
Summary: Pull Request resolved: #33674 ## Issue In D35317070 (0480f56) we introduced a way to configuring the Xcode environment via he `.xcode.env`, falling back to the old `find-node-for-xcode.sh` behavior in case of a misconfiguration. Unfortunately, there were an issue with the new architecture for which the pods were not able to locate the `find-node-for-xcode.sh`, crashing while building the new architecture. ## Solution This Diff solves the issue in two steps: 1. it exposes to the project the REACT_NATIVE_PATH like Android does here: D35451821 (f8d7e0a) 2. it leverages this new variables to reach the script ## Changelog [iOS][Changed] - Fixed the fallback behavior when the `.xcode.env` file is missing, actually using the old `find-node-for-xcode.sh` script Reviewed By: dmitryrykun Differential Revision: D35779165 fbshipit-source-id: 393ef9a0b98d32d9cf226f7d109fdefd772e5120
1 parent 91fc2c0 commit 705c6f5

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

packages/rn-tester/Podfile

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ platform :ios, '12.4'
88
install! 'cocoapods', :deterministic_uuids => false
99

1010
USE_FRAMEWORKS = ENV['USE_FRAMEWORKS'] == '1'
11+
@prefix_path = "../.."
1112

1213
if USE_FRAMEWORKS
1314
puts "Installing pods with use_frameworks!"
@@ -21,25 +22,23 @@ def pods(options = {})
2122
hermes_enabled = ENV['USE_HERMES'] == '1'
2223
puts "Building RNTester with Fabric #{fabric_enabled ? "enabled" : "disabled"}.#{hermes_enabled ? " Using Hermes engine." : ""}"
2324

24-
prefix_path = "../.."
25-
2625
if ENV['USE_CODEGEN_DISCOVERY'] == '1'
2726
# Custom fabric component is only supported when using codegen discovery.
2827
pod 'MyNativeView', :path => "NativeComponentExample"
2928
end
3029

3130
use_react_native!(
32-
path: prefix_path,
31+
path: @prefix_path,
3332
fabric_enabled: fabric_enabled,
3433
hermes_enabled: hermes_enabled,
3534
app_path: "#{Dir.pwd}",
3635
config_file_dir: "#{Dir.pwd}/node_modules",
3736
)
38-
pod 'ReactCommon/turbomodule/samples', :path => "#{prefix_path}/ReactCommon"
37+
pod 'ReactCommon/turbomodule/samples', :path => "#{@prefix_path}/ReactCommon"
3938

4039
# Additional Pods which aren't included in the default Podfile
41-
pod 'React-RCTPushNotification', :path => "#{prefix_path}/Libraries/PushNotificationIOS"
42-
pod 'Yoga', :path => "#{prefix_path}/ReactCommon/yoga", :modular_headers => true
40+
pod 'React-RCTPushNotification', :path => "#{@prefix_path}/Libraries/PushNotificationIOS"
41+
pod 'Yoga', :path => "#{@prefix_path}/ReactCommon/yoga", :modular_headers => true
4342
# Additional Pods which are classed as unstable
4443

4544
# RNTester native modules and components
@@ -64,6 +63,6 @@ target 'RNTesterIntegrationTests' do
6463
end
6564

6665
post_install do |installer|
67-
react_native_post_install(installer)
66+
react_native_post_install(installer, @prefix_path)
6867
__apply_Xcode_12_5_M1_post_install_workaround(installer)
6968
end

scripts/react_native_pods.rb

+18-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,23 @@ def fix_config(config)
258258
end
259259
end
260260

261-
def react_native_post_install(installer)
261+
def set_node_modules_user_settings(installer, react_native_path)
262+
puts "Setting REACT_NATIVE build settings"
263+
projects = installer.aggregate_targets
264+
.map{ |t| t.user_project }
265+
.uniq{ |p| p.path }
266+
.push(installer.pods_project)
267+
268+
projects.each do |project|
269+
project.build_configurations.each do |config|
270+
config.build_settings["REACT_NATIVE_PATH"] = File.join("${PODS_ROOT}", "..", react_native_path)
271+
end
272+
273+
project.save()
274+
end
275+
end
276+
277+
def react_native_post_install(installer, react_native_path = "../node_modules/react-native")
262278
if has_pod(installer, 'Flipper')
263279
flipper_post_install(installer)
264280
end
@@ -272,6 +288,7 @@ def react_native_post_install(installer)
272288
end
273289
modify_flags_for_new_architecture(installer, cpp_flags)
274290

291+
set_node_modules_user_settings(installer, react_native_path)
275292
end
276293

277294
def modify_flags_for_new_architecture(installer, cpp_flags)

scripts/xcode/with-environment.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ else
3838
"in the ios folder. This is needed by React Native to work correctly. " \
3939
"We fallback to the DEPRECATED behavior of finding `node`. This will be REMOVED in a future version. " \
4040
"You can read more about this here: https://reactnative.dev/docs/environment-setup#optional-configuring-your-environment" >&2
41-
source "../find-node-for-xcode.sh"
41+
source "${REACT_NATIVE_PATH}/scripts/find-node-for-xcode.sh"
4242
fi
4343

4444
# Execute argument, if present

0 commit comments

Comments
 (0)