diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateReactCodegenPodspec.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateReactCodegenPodspec.js index f12e7c4a4062..70221d3c988a 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateReactCodegenPodspec.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateReactCodegenPodspec.js @@ -82,10 +82,16 @@ function codegenScripts(appPath /*: string */, baseOutputPath /*: string */) { baseOutputPath, REACT_NATIVE_PACKAGE_ROOT_FOLDER, ); + // Use PODFILE_DIR (set by react_native_post_install) to locate the Podfile + // directory. PODS_ROOT/.. does not work when Pods/ is a symlink. return `<<-SCRIPT -pushd "$PODS_ROOT/../" > /dev/null -RCT_SCRIPT_POD_INSTALLATION_ROOT=$(pwd) -popd >/dev/null +if [ -n "$PODFILE_DIR" ]; then + RCT_SCRIPT_POD_INSTALLATION_ROOT="$PODFILE_DIR" +else + pushd "$PODS_ROOT/../" > /dev/null + RCT_SCRIPT_POD_INSTALLATION_ROOT=$(pwd) + popd >/dev/null +fi export RCT_SCRIPT_RN_DIR="$RCT_SCRIPT_POD_INSTALLATION_ROOT/${relativeReactNativeRootFolder}" export RCT_SCRIPT_APP_PATH="$RCT_SCRIPT_POD_INSTALLATION_ROOT/${relativeAppPath.length === 0 ? '.' : relativeAppPath}" diff --git a/packages/react-native/scripts/react_native_pods.rb b/packages/react-native/scripts/react_native_pods.rb index d647270c2243..3296a20bbd55 100644 --- a/packages/react-native/scripts/react_native_pods.rb +++ b/packages/react-native/scripts/react_native_pods.rb @@ -531,7 +531,16 @@ def react_native_post_install( ReactNativePodsUtils.fix_library_search_paths(installer) ReactNativePodsUtils.update_search_paths(installer) ReactNativePodsUtils.set_build_setting(installer, build_setting: "USE_HERMES", value: use_hermes()) - ReactNativePodsUtils.set_build_setting(installer, build_setting: "REACT_NATIVE_PATH", value: File.join("${PODS_ROOT}", "..", react_native_path)) + # Compute REACT_NATIVE_PATH relative to PODS_ROOT using real (physical) + # paths, so the relative traversal is correct even when Pods/ is a symlink. + pods_dir_real = Pathname.new(Pod::Config.instance.sandbox_root.to_s).realpath + rn_absolute = File.expand_path(react_native_path, Pod::Config.instance.installation_root.to_s) + rn_real = Pathname.new(rn_absolute).realpath + rn_relative_to_pods = rn_real.relative_path_from(pods_dir_real) + ReactNativePodsUtils.set_build_setting(installer, build_setting: "REACT_NATIVE_PATH", value: File.join("${PODS_ROOT}", rn_relative_to_pods.to_s)) + # Store the Podfile directory as a build setting so that shell scripts can + # locate it without relying on PODS_ROOT/.. (breaks when Pods/ is a symlink). + ReactNativePodsUtils.set_build_setting(installer, build_setting: "PODFILE_DIR", value: Pod::Config.instance.installation_root.to_s) ReactNativePodsUtils.set_build_setting(installer, build_setting: "SWIFT_ACTIVE_COMPILATION_CONDITIONS", value: ['$(inherited)', 'DEBUG'], config_name: "Debug") if (ENV['RCT_REMOVE_LEGACY_ARCH'] == '1') diff --git a/packages/react-native/scripts/react_native_pods_utils/script_phases.rb b/packages/react-native/scripts/react_native_pods_utils/script_phases.rb index f5dd2ed70831..b3bd2f997f3f 100644 --- a/packages/react-native/scripts/react_native_pods_utils/script_phases.rb +++ b/packages/react-native/scripts/react_native_pods_utils/script_phases.rb @@ -35,9 +35,15 @@ def get_script_phases_no_codegen_discovery(options) def get_script_template(react_native_path, export_vars={}) template =<<~EOS - pushd "$PODS_ROOT/../" > /dev/null - RCT_SCRIPT_POD_INSTALLATION_ROOT=$(pwd) - popd >/dev/null + # Use PODFILE_DIR (set by react_native_post_install) to locate the + # Podfile directory. PODS_ROOT/.. does not work when Pods/ is a symlink. + if [ -n "$PODFILE_DIR" ]; then + RCT_SCRIPT_POD_INSTALLATION_ROOT="$PODFILE_DIR" + else + pushd "$PODS_ROOT/../" > /dev/null + RCT_SCRIPT_POD_INSTALLATION_ROOT=$(pwd) + popd >/dev/null + fi <% export_vars.each do |(varname, value)| %> export <%= varname -%>=<%= value -%> <% end %> diff --git a/packages/react-native/scripts/xcode/with-environment.sh b/packages/react-native/scripts/xcode/with-environment.sh index d2ddf3c02cab..e25f5af4edfc 100755 --- a/packages/react-native/scripts/xcode/with-environment.sh +++ b/packages/react-native/scripts/xcode/with-environment.sh @@ -17,7 +17,13 @@ NODE_BINARY=$(command -v node || echo "") export NODE_BINARY # Override the default with the global environment -ENV_PATH="$PODS_ROOT/../.xcode.env" +# Use PODFILE_DIR (set by react_native_post_install) to locate .xcode.env. +# PODS_ROOT/.. does not work when Pods/ is a symlink. +if [ -n "$PODFILE_DIR" ]; then + ENV_PATH="$PODFILE_DIR/.xcode.env" +else + ENV_PATH="$PODS_ROOT/../.xcode.env" +fi if [ -f "$ENV_PATH" ]; then source "$ENV_PATH" fi