Pass node executable to codegen (#33672)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/33672

This pr adds a parameter to the `create-artifacts.js` script to accept the path to a node executable, falling back to `node` in case the parameter has not been passed.
Then, it passes the NODE_BINARY to the script in the `script_phases.sh` script.

This PR decouples the `node` environment from the system one and fixes a build issue in the new architecture when the environment has no `node`

## Changelog

[iOS][Changed] - Update CodeGen scripts to accept custom node executable

Reviewed By: cortinico, dmitryrykun

Differential Revision: D35748497

fbshipit-source-id: 41b102de6427d6ef0ba1f8725f4b939d3b8c63db
This commit is contained in:
Riccardo Cipolleschi
2022-04-21 06:59:17 -07:00
committed by Facebook GitHub Bot
parent 705c6f57d6
commit 323db75c36
2 changed files with 17 additions and 7 deletions
+16 -6
View File
@@ -54,6 +54,11 @@ const argv = yargs
description:
'Path where codegen config files are located (e.g. node_modules dir).',
})
.option('n', {
alias: 'nodeBinary',
default: 'node',
description: 'Path to the node executable.',
})
.usage('Usage: $0 -p [path to app]')
.demandOption(['p']).argv;
@@ -62,6 +67,7 @@ const CODEGEN_CONFIG_FILENAME = argv.f;
const CODEGEN_CONFIG_FILE_DIR = argv.c;
const CODEGEN_CONFIG_KEY = argv.k;
const CODEGEN_FABRIC_ENABLED = argv.e;
const NODE = argv.n;
const CODEGEN_REPO_PATH = `${RN_ROOT}/packages/react-native-codegen`;
const CODEGEN_NPM_PATH = `${RN_ROOT}/../react-native-codegen`;
const CORE_LIBRARIES = new Set(['rncore', 'FBReactNativeSpec']);
@@ -71,6 +77,10 @@ function isReactNativeCoreLibrary(libraryName) {
return CORE_LIBRARIES.has(libraryName);
}
function executeNodeScript(script) {
execSync(`${NODE} ${script}`);
}
function main(appRootDir, outputPath) {
if (appRootDir == null) {
console.error('Missing path to React Native application');
@@ -234,8 +244,8 @@ function main(appRootDir, outputPath) {
console.log(`\n\n[Codegen] >>>>> Processing ${library.config.name}`);
// Generate one schema for the entire library...
execSync(
`node ${path.join(
executeNodeScript(
`${path.join(
codegenCliPath,
'lib',
'cli',
@@ -250,8 +260,8 @@ function main(appRootDir, outputPath) {
? `--libraryType ${library.config.type}`
: '';
fs.mkdirSync(pathToTempOutputDir, {recursive: true});
execSync(
`node ${path.join(
executeNodeScript(
`${path.join(
RN_ROOT,
'scripts',
'generate-specs-cli.js',
@@ -284,8 +294,8 @@ function main(appRootDir, outputPath) {
// Generate FabricComponentProvider.
// Only for iOS at this moment.
execSync(
`node ${path.join(
executeNodeScript(
`${path.join(
RN_ROOT,
'scripts',
'generate-provider-cli.js',
@@ -100,7 +100,7 @@ generateCodegenArtifactsFromSchema () {
generateArtifacts () {
describe "Generating codegen artifacts"
pushd "$RCT_SCRIPT_RN_DIR" >/dev/null || exit 1
"$NODE_BINARY" "scripts/generate-artifacts.js" --path "$RCT_SCRIPT_APP_PATH" --outputPath "$TEMP_OUTPUT_DIR" --fabricEnabled "$RCT_SCRIPT_FABRIC_ENABLED" --configFileDir "$RCT_SCRIPT_CONFIG_FILE_DIR"
"$NODE_BINARY" "scripts/generate-artifacts.js" --path "$RCT_SCRIPT_APP_PATH" --outputPath "$TEMP_OUTPUT_DIR" --fabricEnabled "$RCT_SCRIPT_FABRIC_ENABLED" --configFileDir "$RCT_SCRIPT_CONFIG_FILE_DIR" --nodeBinary "$NODE_BINARY"
popd >/dev/null || exit 1
}