mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
362511dc93
Summary: Currently, the build breaks if we move `react-native-codegen` from the template's dependencies to root. This is due to `scripts/generate-specs-cli.js` using the one installed under `node_modules` instead of the local one. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Internal] [Fixed] - `scripts/generate-specs-cli.js` should prefer the local `react-native-codegen` package Pull Request resolved: https://github.com/facebook/react-native/pull/32096 Test Plan: 1. Make the following changes ```diff diff --git a/package.json b/package.json index 847c726a69b..78da8232988 100644 --- a/package.json +++ b/package.json @@ -107,6 +107,7 @@ "promise": "^8.0.3", "prop-types": "^15.7.2", "react-devtools-core": "^4.13.0", + "react-native-codegen": "^0.0.7", "react-refresh": "^0.4.0", "regenerator-runtime": "^0.13.2", "scheduler": "^0.20.2", diff --git a/template/package.json b/template/package.json index 715614112ac..5e0762b1b25 100644 --- a/template/package.json +++ b/template/package.json @@ -21,7 +21,6 @@ "eslint": "7.14.0", "jest": "^26.6.3", "metro-react-native-babel-preset": "^0.66.2", - "react-native-codegen": "^0.0.7", "react-test-renderer": "17.0.2" }, "jest": { ``` 2. Run `scripts/test-manual-e2e.sh` ## Expected Behavior Task `:ReactAndroid:buildReactNdkLib` succeeds. ## Actual Behavior ``` > Task :ReactAndroid:buildReactNdkLib FAILED make: Entering directory '~/Source/react-native/ReactAndroid/src/main/jni/react/jni' fcntl(): Bad file descriptor make: Leaving directory '~/Source/react-native/ReactAndroid/src/main/jni/react/jni' ~/Library/Android/sdk/ndk/21.4.7075529/build/core/build-binary.mk:651: Android NDK: Module react_codegen_rncore depends on undefined modules: react_render_components_view ~/Library/Android/sdk/ndk/21.4.7075529/build/core/build-binary.mk:664: *** Android NDK: Note that old versions of ndk-build silently ignored this error case. If your project worked on those versions, the missing libraries were not needed and you can remove those dependencies from the module to fix your build. Alternatively, set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies. . Stop. FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':ReactAndroid:buildReactNdkLib'. > Process 'command '~/Library/Android/sdk/ndk/21.4.7075529/ndk-build'' finished with non-zero exit value 2 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/6.9/userguide/command_line_interface.html#sec:command_line_warnings BUILD FAILED in 19s 20 actionable tasks: 20 executed Couldn't generate artifacts ``` Reviewed By: ShikaSD Differential Revision: D30581194 Pulled By: hramos fbshipit-source-id: 3f7a707b33377042502e50887856ff5641fdd52c
95 lines
2.4 KiB
JavaScript
95 lines
2.4 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
let RNCodegen;
|
|
try {
|
|
RNCodegen = require('../packages/react-native-codegen/lib/generators/RNCodegen.js');
|
|
} catch (e) {
|
|
RNCodegen = require('react-native-codegen/lib/generators/RNCodegen.js');
|
|
if (!RNCodegen) {
|
|
throw 'RNCodegen not found.';
|
|
}
|
|
}
|
|
|
|
const fs = require('fs');
|
|
const mkdirp = require('mkdirp');
|
|
const path = require('path');
|
|
|
|
const GENERATORS = {
|
|
android: ['componentsAndroid', 'modulesAndroid'],
|
|
ios: ['componentsIOS', 'modulesIOS'],
|
|
};
|
|
|
|
function generateSpec(
|
|
platform,
|
|
schemaPath,
|
|
outputDirectory,
|
|
libraryName,
|
|
packageName,
|
|
) {
|
|
const schemaText = fs.readFileSync(schemaPath, 'utf-8');
|
|
|
|
if (schemaText == null) {
|
|
throw new Error(`Can't find schema at ${schemaPath}`);
|
|
}
|
|
|
|
if (!outputDirectory) {
|
|
outputDirectory = path.resolve(__dirname, '..', 'Libraries', libraryName);
|
|
}
|
|
mkdirp.sync(outputDirectory);
|
|
|
|
let schema;
|
|
try {
|
|
schema = JSON.parse(schemaText);
|
|
} catch (err) {
|
|
throw new Error(`Can't parse schema to JSON. ${schemaPath}`);
|
|
}
|
|
|
|
RNCodegen.generate(
|
|
{
|
|
libraryName,
|
|
schema,
|
|
outputDirectory,
|
|
packageName,
|
|
},
|
|
{
|
|
generators: GENERATORS[platform],
|
|
},
|
|
);
|
|
|
|
if (platform === 'android') {
|
|
// Move all components C++ files to a structured jni folder for now.
|
|
// Note: this should've been done by RNCodegen's generators, but:
|
|
// * the generators don't support platform option yet
|
|
// * this subdir structure is Android-only, not applicable to iOS
|
|
const files = fs.readdirSync(outputDirectory);
|
|
const jniOutputDirectory = `${outputDirectory}/jni/react/renderer/components/${libraryName}`;
|
|
mkdirp.sync(jniOutputDirectory);
|
|
files
|
|
.filter(f => f.endsWith('.h') || f.endsWith('.cpp'))
|
|
.forEach(f => {
|
|
fs.renameSync(`${outputDirectory}/${f}`, `${jniOutputDirectory}/${f}`);
|
|
});
|
|
}
|
|
}
|
|
|
|
function main() {
|
|
const args = process.argv.slice(2);
|
|
const platform = args[0];
|
|
const schemaPath = args[1];
|
|
const outputDir = args[2];
|
|
const libraryName = args[3] || 'FBReactNativeSpec';
|
|
const javaPackageName = args[4] || 'com.facebook.fbreact.specs';
|
|
generateSpec(platform, schemaPath, outputDir, libraryName, javaPackageName);
|
|
}
|
|
|
|
main();
|