Skip to content

Commit

Permalink
Pass node executable to codegen (facebook#33672)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#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`

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

Reviewed By: cortinico, dmitryrykun

Differential Revision: D35748497

fbshipit-source-id: 41b102de6427d6ef0ba1f8725f4b939d3b8c63db
  • Loading branch information
Riccardo Cipolleschi authored and Saadnajmi committed Jan 14, 2023
1 parent 6724401 commit 4823071
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 17 additions & 7 deletions scripts/generate-artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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']);
Expand All @@ -71,6 +77,10 @@ function isReactNativeCoreLibrary(libraryName) {
return CORE_LIBRARIES.has(libraryName);
}

function executeNodeScript(script) {
execFileSync(NODE, [script]); // [macOS] use execFileSync to help keep shell commands clean
}

function main(appRootDir, outputPath) {
if (appRootDir == null) {
console.error('Missing path to React Native application');
Expand Down Expand Up @@ -194,7 +204,7 @@ function main(appRootDir, outputPath) {
cwd: codegenCliPath,
stdio: 'inherit',
});
// [macOS]
// macOS]
}
} else if (fs.existsSync(CODEGEN_NPM_PATH)) {
codegenCliPath = CODEGEN_NPM_PATH;
Expand Down Expand Up @@ -236,8 +246,8 @@ function main(appRootDir, outputPath) {

console.log(`\n\n[Codegen] >>>>> Processing ${library.config.name}`);
// Generate one schema for the entire library...
// [macOS use execFileSync to help keep shell commands clean
execFileSync('node', [
// [macOS use execFileSync instead of execSync inside executeNodeScript
executeNodeScript([
path.join(
codegenCliPath,
'lib',
Expand All @@ -256,8 +266,8 @@ function main(appRootDir, outputPath) {
? ['--libraryType', library.config.type]
: null; // macOS]
fs.mkdirSync(pathToTempOutputDir, {recursive: true});
// [macOS use execFileSync to help keep shell commands clean
execFileSync('node', [
// [macOS use execFileSync instead of execSync inside executeNodeScript
executeNodeScript([
path.join(RN_ROOT, 'scripts', 'generate-specs-cli.js'),
'--platform',
'ios',
Expand Down Expand Up @@ -299,8 +309,8 @@ function main(appRootDir, outputPath) {

// Generate FabricComponentProvider.
// Only for iOS at this moment.
// [macOS use execFileSync to help keep shell commands clean
execFileSync('node', [
// [macOS use execFileSync instead of execSync inside executeNodeScript
executeNodeScript([
path.join(RN_ROOT, 'scripts', 'generate-provider-cli.js'),
'--platform',
'ios',
Expand Down
2 changes: 1 addition & 1 deletion scripts/react_native_pods_utils/script_phases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4823071

Please sign in to comment.