From 7edba7b57a53b71625d962ee90cd23cb3c811b84 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Tue, 28 Oct 2025 10:45:33 -0700 Subject: [PATCH] Fix outputs when iOS artifacts generator is run from Xcode script phase (#54066) Summary: An earlier change (0.79 and onwards, I believe?) runs the iOS artifacts code generator script in Xcode as well as from Cocoapods. This duplication runs it twice, but the second step isn't able to load the new `autolinking.json` correctly; See: https://github.com/facebook/react-native/pull/53503 This PR "double" fixes this by: - simply passing the "real" output directory to the artifacts generator in (`script_phases.sh`) where it's called by Xcode, rather than a temporary directory - preferring `$RCT_SCRIPT_OUTPUT_DIR` if it's set as an environment variable in the artifacts generator (which it is by `script_phases.sh`) While this is technically redundant, future changes here make this feel like a safer option, since both conventions overlap in these two places, and the double fix may prevent a regression here in the shortterm and convey what this path is supposed to be in both places. ## Changelog: [IOS] [FIXED] - Fix autolinking-generated react-native-config output not being used in ReactCodegen script phase due to temp output directory Pull Request resolved: https://github.com/facebook/react-native/pull/54066 Test Plan: - Prefer `$RCT_SCRIPT_OUTPUT_DIR` env var for finding `build/generated/autolinking/autolinking.json` - Always use real `$RCT_SCRIPT_OUTPUT_DIR` as output in `withCodegenDiscovery` in `react_native_pods_utils/script_phases.sh` (which is called by Xcode rather than Cocoapods to invoke the artifacts generator) since the temporary output directory isn't necessary Reviewed By: javache Differential Revision: D85673625 Pulled By: cipolleschi fbshipit-source-id: 9d297fb0ee24f52a0bb7c5a8f41bf770bf63b18f --- .../scripts/codegen/generate-artifacts-executor/index.js | 9 ++++++++- .../scripts/react_native_pods_utils/script_phases.sh | 4 +--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js index c64c256a459..c1da8fab315 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js @@ -88,8 +88,15 @@ function execute( const reactNativeConfig = readReactNativeConfig( projectRoot, - baseOutputPath, + // NOTE: Used to load `build/generated/autolinking/autolinking.json` generated by `scripts/cocoapods/autolinking.rb` + // If we have RCT_SCRIPT_OUTPUT_DIR (set in `react_native_pods_utils/script_phases.sh`, it takes precedence, otherwise + // we search for the `autolinking.json` output in the `baseOutputPath` + process.env.RCT_SCRIPT_OUTPUT_DIR != null && + process.env.RCT_SCRIPT_OUTPUT_DIR.length > 0 + ? process.env.RCT_SCRIPT_OUTPUT_DIR + : baseOutputPath, ); + const codegenEnabledLibraries = findCodegenEnabledLibraries( pkgJson, projectRoot, diff --git a/packages/react-native/scripts/react_native_pods_utils/script_phases.sh b/packages/react-native/scripts/react_native_pods_utils/script_phases.sh index 92325f1ad07..0878b9d6a8c 100755 --- a/packages/react-native/scripts/react_native_pods_utils/script_phases.sh +++ b/packages/react-native/scripts/react_native_pods_utils/script_phases.sh @@ -96,7 +96,7 @@ generateCodegenArtifactsFromSchema () { generateArtifacts () { describe "Generating codegen artifacts" pushd "$RCT_SCRIPT_RN_DIR" >/dev/null || exit 1 - "$NODE_BINARY" "scripts/generate-codegen-artifacts.js" --path "$RCT_SCRIPT_APP_PATH" --outputPath "$TEMP_OUTPUT_DIR" --targetPlatform "ios" + "$NODE_BINARY" "scripts/generate-codegen-artifacts.js" --path "$RCT_SCRIPT_APP_PATH" --outputPath "$RCT_SCRIPT_OUTPUT_DIR" --targetPlatform "ios" popd >/dev/null || exit 1 } @@ -110,11 +110,9 @@ moveOutputs () { } withCodegenDiscovery () { - setup_dirs find_node find_codegen generateArtifacts - moveOutputs } noCodegenDiscovery () {