Skip to content

Commit 1d8d46b

Browse files
zoontekreact-native-bot
authored andcommitted
Make PODFILE_DIR build setting portable across machines (#56732)
Summary: `PODFILE_DIR` was being set to `Pod::Config.instance.installation_root.to_s`, which bakes the contributor's absolute path (e.g. `/Users/alice/Projects/MyApp/ios`) into `project.pbxproj` — every `pod install` on a different machine churns the diff, and a checked-in pbxproj points at someone else's filesystem. Set `PODFILE_DIR` per-project via Xcode variable substitution: `$(SRCROOT)` for user projects, `$(SRCROOT)/..` for the Pods project. Resolved value is identical at build time; the persisted string is now machine-independent. ## Changelog: [IOS] [FIXED] - Persist `PODFILE_DIR` as `$(SRCROOT)`-relative so `project.pbxproj` is portable across machines Pull Request resolved: #56732 Test Plan: 1. `pod install`, inspect host-app and Pods `pbxproj`: `PODFILE_DIR` should be `$(SRCROOT)` and `$(SRCROOT)/..`, not an absolute path. 2. Build the app and confirm consumers of `${PODFILE_DIR}` still resolve correctly (`with-environment.sh`, codegen script phases). Reviewed By: christophpurrer Differential Revision: D104398698 Pulled By: cipolleschi fbshipit-source-id: e00f027d5c3570ac1a9c78b54fdbdaf81f98f17f
1 parent 6b54fca commit 1d8d46b

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

packages/react-native/scripts/codegen/generate-artifacts-executor/generateReactCodegenPodspec.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,13 @@ function getInputFiles(appPath /*: string */, appPkgJson /*: $FlowFixMe */) {
4949
return '[]';
5050
}
5151

52+
// Normalize appPath so any "Pods/.." segment is collapsed before find runs.
53+
// Otherwise every find result inherits the search-root prefix containing
54+
// "/Pods/" and gets dropped by the exclusion filter below.
55+
const resolvedAppPath = path.resolve(appPath);
56+
5257
const xcodeproj = String(
53-
execSync(`find ${appPath} -type d -name "*.xcodeproj"`),
58+
execSync(`find ${resolvedAppPath} -type d -name "*.xcodeproj"`),
5459
)
5560
.trim()
5661
.split('\n')
@@ -61,12 +66,12 @@ function getInputFiles(appPath /*: string */, appPkgJson /*: $FlowFixMe */) {
6166
)[0];
6267
if (!xcodeproj) {
6368
throw new Error(
64-
`Cannot find .xcodeproj file inside ${appPath}. This is required to determine codegen spec paths relative to native project.`,
69+
`Cannot find .xcodeproj file inside ${resolvedAppPath}. This is required to determine codegen spec paths relative to native project.`,
6570
);
6671
}
6772
const jsFiles = '-name "Native*.js" -or -name "*NativeComponent.js"';
6873
const tsFiles = '-name "Native*.ts" -or -name "*NativeComponent.ts"';
69-
const findCommand = `find ${path.join(appPath, jsSrcsDir)} -type f -not -path "*/__mocks__/*" -and \\( ${jsFiles} -or ${tsFiles} \\)`;
74+
const findCommand = `find ${path.join(resolvedAppPath, jsSrcsDir)} -type f -not -path "*/__mocks__/*" -and \\( ${jsFiles} -or ${tsFiles} \\)`;
7075
const list = String(execSync(findCommand))
7176
.trim()
7277
.split('\n')

packages/react-native/scripts/react_native_pods.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,21 @@ def react_native_post_install(
539539
rn_relative_to_pods = rn_real.relative_path_from(pods_dir_real)
540540
ReactNativePodsUtils.set_build_setting(installer, build_setting: "REACT_NATIVE_PATH", value: File.join("${PODS_ROOT}", rn_relative_to_pods.to_s))
541541
# Store the Podfile directory as a build setting so that shell scripts can
542-
# locate it without relying on PODS_ROOT/.. (breaks when Pods/ is a symlink).
543-
ReactNativePodsUtils.set_build_setting(installer, build_setting: "PODFILE_DIR", value: Pod::Config.instance.installation_root.to_s)
542+
# locate it without hardcoding an absolute path. Use Xcode variable
543+
# substitution per-project so the value persisted in project.pbxproj is
544+
# portable across machines: $(SRCROOT) is the Podfile dir for user projects
545+
# (also avoids the PODS_ROOT/.. traversal that breaks when Pods/ is a
546+
# symlink), and $(SRCROOT)/.. for the Pods project.
547+
installer.aggregate_targets.map(&:user_project).uniq(&:path).each do |user_project|
548+
user_project.build_configurations.each do |config|
549+
config.build_settings['PODFILE_DIR'] = '$(SRCROOT)'
550+
end
551+
user_project.save
552+
end
553+
installer.pods_project.build_configurations.each do |config|
554+
config.build_settings['PODFILE_DIR'] = '$(SRCROOT)/..'
555+
end
556+
installer.pods_project.save
544557
ReactNativePodsUtils.set_build_setting(installer, build_setting: "SWIFT_ACTIVE_COMPILATION_CONDITIONS", value: ['$(inherited)', 'DEBUG'], config_name: "Debug")
545558

546559
if (ENV['RCT_REMOVE_LEGACY_ARCH'] == '1')

0 commit comments

Comments
 (0)