fix(codegen): empty ReactCodegen input_files when no Native spec files found - #57759
fix(codegen): empty ReactCodegen input_files when no Native spec files found#57759Levin-nik wants to merge 1 commit into
Conversation
…s found getInputFiles() produced a bogus directory entry in the ReactCodegen "Generate Specs" script phase input_files when an app's codegenConfig.jsSrcsDir contained no Native*/*NativeComponent spec files. Because that directory typically holds the iOS build output (e.g. ios/build, common with -derivedDataPath inside the project, as Detox/CI use), Xcode detected a dependency cycle on incremental builds: Cycle in dependencies between targets 'ReactCodegen' and '<Pod>' Clean builds passed (output dir did not exist yet), so the failure only surfaced on the 2nd and later builds. Filter empty entries from the find result so an empty match yields []. Behavior is unchanged when real spec files are present. Test Plan: in a New Arch app, set codegenConfig.jsSrcsDir to a dir without Native*/*NativeComponent files, run `pod install`, then build twice with `-derivedDataPath ios/build`. Before: 2nd build fails with the cycle error. After: both builds pass. With real Native* specs, input_files is unchanged.
|
Hi @Levin-nik! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
When an app's
codegenConfig.jsSrcsDircontains no files matching the codegenspec naming convention (
Native*.ts/Native*.js/*NativeComponent.ts/*NativeComponent.js),getInputFiles()ingenerateReactCodegenPodspec.jsemits a directory pathfor the
[CP-User] Generate Specsscript phase'sinput_files, instead of anempty list.
This causes an intermittent Xcode build failure on incremental builds:
Root cause
When
findmatches no spec files,execSyncreturns an empty string and"".split('\n')yields[""]. The.mapthen runs once withfilepath === "", andpath.relative(xcodeproj, "")resolves to a relativepath to the project/app root (e.g.
..). As a resultinput_filesbecomes["${PODS_ROOT}/.."]— a directory.That directory typically contains the iOS build output (e.g.
ios/build, when-derivedDataPathis set inside the project — common in Detox/CI configs). Thepods that produce those artifacts depend on
ReactCodegen, so Xcode detects adependency cycle. Clean builds pass (the output dir doesn't exist yet), so the
failure only surfaces on the 2nd and later builds, which makes it look
intermittent and hard to reproduce.
Fix
Drop empty entries so an empty
findresult yields[]→input_files: []:const list = String(execSync(findCommand)) .trim() .split('\n') + .filter(Boolean) .sort() .map(filepath => `"\${PODS_ROOT}/${path.relative(xcodeproj, filepath)}"`) .join(',\n'); return `[${list}]`;For apps that do have
Native*spec files, behavior is unchanged — real pathsare truthy and are kept. This is also consistent with the existing
.filter(...)already used for
xcodeprojdiscovery in the same function.Changelog
Changelog: [iOS] [Fixed] - Fixed intermittent "Cycle in dependencies between targets 'ReactCodegen' and ..." Xcode build error that occurred on incremental iOS builds when an app's
codegenConfig.jsSrcsDircontained noNative*/*NativeComponentspec files.Test Plan
Reproducer (on a New Arch app):
codegenConfig.jsSrcsDirto a directory with noNative*/*NativeComponentfiles (or empty).cd ios && pod install.build/generated/ios/ReactCodegen.podspec:'input_files' => ["${PODS_ROOT}/.."](a directory).'input_files' => [].xcodebuild -workspace ios/MyApp.xcworkspace -scheme MyApp -configuration Debug -sdk iphonesimulator -derivedDataPath ios/buildRegression: in an app with real
Native*.tsspecs, confirminput_filesstilllists the spec files and the generated codegen output is identical.
Fixes #57760