Skip to content

Commit 0162958

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Add option to force all codegen output into the provided directory (#55996)
Summary: Pull Request resolved: #55996 Changelog: [Internal] Adds a new, optional, flag to the `generate-codegen-artifacts` script, which forces React Native Core artifacts to be generated in the output path set from the CLI instead of inside React Native. This will allow the C++ API snapshot generator to get entire codegen output for a given platform in a single place. Reviewed By: cipolleschi Differential Revision: D95788767 fbshipit-source-id: 36f8974ecb3aedbe27dd3bc246c09a80051ff67c
1 parent 7d80d6e commit 0162958

3 files changed

Lines changed: 34 additions & 5 deletions

File tree

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ function generateNativeCode(
2222
schemaInfos /*: $ReadOnlyArray<$FlowFixMe> */,
2323
includesGeneratedCode /*: boolean */,
2424
platform /*: string */,
25+
forceOutputPath /*: boolean */ = false,
2526
) /*: Array<void> */ {
2627
return schemaInfos.map(schemaInfo => {
27-
generateCode(outputPath, schemaInfo, includesGeneratedCode, platform);
28+
generateCode(
29+
outputPath,
30+
schemaInfo,
31+
includesGeneratedCode,
32+
platform,
33+
forceOutputPath,
34+
);
2835
});
2936
}
3037

@@ -33,6 +40,7 @@ function generateCode(
3340
schemaInfo /*: $FlowFixMe */,
3441
includesGeneratedCode /*: boolean */,
3542
platform /*: string */,
43+
forceOutputPath /*: boolean */ = false,
3644
) {
3745
if (shouldSkipGenerationForFBReactNativeSpec(schemaInfo, platform)) {
3846
codegenLog(
@@ -60,8 +68,9 @@ function generateCode(
6068
);
6169

6270
// Finally, copy artifacts to the final output directory.
63-
const outputDir =
64-
reactNativeCoreLibraryOutputPath(libraryName, platform) ?? outputPath;
71+
const outputDir = forceOutputPath
72+
? outputPath
73+
: (reactNativeCoreLibraryOutputPath(libraryName, platform) ?? outputPath);
6574
fs.mkdirSync(outputDir, {recursive: true});
6675
cpSyncRecursiveIfChanged(tmpOutputDir, outputDir);
6776
codegenLog(`Generated artifacts: ${outputDir}`);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function execute(
6666
optionalBaseOutputPath /*: ?string */,
6767
source /*: string */,
6868
runReactNativeCodegen /*: boolean */ = true,
69+
forceOutputPath /*: boolean */ = false,
6970
) {
7071
try {
7172
codegenLog(`Analyzing ${path.join(projectRoot, 'package.json')}`);
@@ -146,6 +147,7 @@ function execute(
146147
),
147148
pkgJsonIncludesGeneratedCode(pkgJson),
148149
platform,
150+
forceOutputPath,
149151
);
150152
}
151153

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,26 @@ const argv = yargs
3131
description: 'Whether the script is invoked from an `app` or a `library`',
3232
default: 'app',
3333
})
34+
.option('f', {
35+
alias: 'forceOutputPath',
36+
description:
37+
'Whether to force React Native Core artifacts to output to the specified path',
38+
type: 'boolean',
39+
default: false,
40+
})
3441
.usage('Usage: $0 -p [path to app] -t [target platform] -o [output path]')
3542
.demandOption(['p', 't']).argv;
3643

37-
// $FlowFixMe[prop-missing]
38-
executor.execute(argv.path, argv.targetPlatform, argv.outputPath, argv.source);
44+
executor.execute(
45+
// $FlowFixMe[prop-missing]
46+
argv.path,
47+
// $FlowFixMe[prop-missing]
48+
argv.targetPlatform,
49+
// $FlowFixMe[prop-missing]
50+
argv.outputPath,
51+
// $FlowFixMe[prop-missing]
52+
argv.source,
53+
true, // runReactNativeCodegen
54+
// $FlowFixMe[prop-missing]
55+
argv.forceOutputPath,
56+
);

0 commit comments

Comments
 (0)