Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
11 changes: 10 additions & 1 deletion packages/react-native/scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
8 changes: 7 additions & 1 deletion packages/react-native/scripts/xcode/with-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading