Skip to content

Commit

Permalink
Export REACT_NATIVE_PATH and fix find-node-for-xcode.sh fallback beha…
Browse files Browse the repository at this point in the history
…vior (#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
  • Loading branch information
Riccardo Cipolleschi authored and facebook-github-bot committed Apr 21, 2022
1 parent 91fc2c0 commit 705c6f5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
13 changes: 6 additions & 7 deletions packages/rn-tester/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ platform :ios, '12.4'
install! 'cocoapods', :deterministic_uuids => false

USE_FRAMEWORKS = ENV['USE_FRAMEWORKS'] == '1'
@prefix_path = "../.."

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

prefix_path = "../.."

if ENV['USE_CODEGEN_DISCOVERY'] == '1'
# Custom fabric component is only supported when using codegen discovery.
pod 'MyNativeView', :path => "NativeComponentExample"
end

use_react_native!(
path: prefix_path,
path: @prefix_path,
fabric_enabled: fabric_enabled,
hermes_enabled: hermes_enabled,
app_path: "#{Dir.pwd}",
config_file_dir: "#{Dir.pwd}/node_modules",
)
pod 'ReactCommon/turbomodule/samples', :path => "#{prefix_path}/ReactCommon"
pod 'ReactCommon/turbomodule/samples', :path => "#{@prefix_path}/ReactCommon"

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

# RNTester native modules and components
Expand All @@ -64,6 +63,6 @@ target 'RNTesterIntegrationTests' do
end

post_install do |installer|
react_native_post_install(installer)
react_native_post_install(installer, @prefix_path)
__apply_Xcode_12_5_M1_post_install_workaround(installer)
end
19 changes: 18 additions & 1 deletion scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,23 @@ def fix_config(config)
end
end

def react_native_post_install(installer)
def set_node_modules_user_settings(installer, react_native_path)
puts "Setting REACT_NATIVE build settings"
projects = installer.aggregate_targets
.map{ |t| t.user_project }
.uniq{ |p| p.path }
.push(installer.pods_project)

projects.each do |project|
project.build_configurations.each do |config|
config.build_settings["REACT_NATIVE_PATH"] = File.join("${PODS_ROOT}", "..", react_native_path)
end

project.save()
end
end

def react_native_post_install(installer, react_native_path = "../node_modules/react-native")
if has_pod(installer, 'Flipper')
flipper_post_install(installer)
end
Expand All @@ -272,6 +288,7 @@ def react_native_post_install(installer)
end
modify_flags_for_new_architecture(installer, cpp_flags)

set_node_modules_user_settings(installer, react_native_path)
end

def modify_flags_for_new_architecture(installer, cpp_flags)
Expand Down
2 changes: 1 addition & 1 deletion scripts/xcode/with-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ else
"in the ios folder. This is needed by React Native to work correctly. " \
"We fallback to the DEPRECATED behavior of finding `node`. This will be REMOVED in a future version. " \
"You can read more about this here: https://reactnative.dev/docs/environment-setup#optional-configuring-your-environment" >&2
source "../find-node-for-xcode.sh"
source "${REACT_NATIVE_PATH}/scripts/find-node-for-xcode.sh"
fi

# Execute argument, if present
Expand Down

0 comments on commit 705c6f5

Please sign in to comment.