mirror of
https://github.com/facebook/react-native.git
synced 2024-11-22 06:29:46 +00:00
c085068d7b
Summary: Introduced `architecture.gradle` that sets up pluggable build-time codegen steps for Gradle so that: * Libraries, including core ReactAndroid, can produce the new architecture codegen (NativeModule **Java** specs in this diff) during build time * Hosting app (e.g. RNTester) can produce its own set of codegen specs separately **Please note that this is still work in progress, hence app templates have not been updated to use it yet.** In order to activate this setup, the env variable `USE_CODEGEN=1` must be set. Eventually, this var will be removed from the logic. With this change, RNTester: * Will see all the generated specs populated in the Gradle build dir, which should be equivalent to the currently [**checked in version**](https://github.com/facebook/react-native/tree/master/ReactAndroid/src/main/java/com/facebook/fbreact/specs). * The specs will compile, but **have not been validated** vs the existing NativeModule .java classes through out the core -- that will be the next step * The specs are under `com.facebook.fbreact.specs.beta` namespace, which will be configurable in the future. `.beta` is added to avoid conflict with the existing files in the repo. ### Is this all we need to enable TurboModule in Android? No. There are a few more pieces needed: * C++ codegen output for JNI layer for each NativeModule spec * The C++ module lookup for TurboModule Manager * The JNI build setup in Gradle for these C++ output * Toggle to enable TurboModule system in the entire app Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D22838581 fbshipit-source-id: d972e2fbb37bdbd3354e72b014fc8bb27a33b9ac
89 lines
2.4 KiB
Groovy
89 lines
2.4 KiB
Groovy
/*
|
|
* 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.
|
|
*/
|
|
|
|
|
|
def codegenDir = "$rootDir/packages/react-native-codegen";
|
|
def codegenGenerateSchemaCli = "$codegenDir/lib/cli/combine/combine-js-to-schema-cli.js";
|
|
def codegenGenerateNativeModuleSpecsCli = "$rootDir/scripts/generate-native-modules-specs-cli.js";
|
|
def schemaFile = "schema.json";
|
|
|
|
// TODO: Consider building Gradle plugin instead.
|
|
|
|
/**
|
|
* The config is derived from app-level `project.react`.
|
|
*/
|
|
ext.generateNativeArtifactsFromJavaScript = { Map config ->
|
|
def nodeExecutableAndArgs = config.nodeExecutableAndArgs ?: ["node"];
|
|
def jsRootDir = config.jsRootDir ?: config.root;
|
|
|
|
if (!config.enableCodegen) {
|
|
return;
|
|
}
|
|
|
|
// 1. Create build dir
|
|
def generatedSrcDir = file("$buildDir/generated/source/codegen");
|
|
|
|
// 2. Produce schema from JS files.
|
|
task generateCodegenSchemaFromJavaScript(type: Exec) {
|
|
doFirst {
|
|
generatedSrcDir.deleteDir()
|
|
generatedSrcDir.mkdirs()
|
|
}
|
|
|
|
def schemaOutputFile = file("$generatedSrcDir/$schemaFile");
|
|
|
|
inputs.files fileTree(dir: codegenDir)
|
|
inputs.files fileTree(dir: jsRootDir)
|
|
outputs.file(schemaOutputFile)
|
|
|
|
def execCommands = ["yarn"] + nodeExecutableAndArgs + [
|
|
codegenGenerateSchemaCli,
|
|
"$schemaOutputFile",
|
|
jsRootDir,
|
|
];
|
|
commandLine execCommands
|
|
|
|
ext.schema = {
|
|
schemaOutputFile
|
|
}
|
|
}
|
|
|
|
// 3. Generate Java code from schema
|
|
task generateCodegenArtifactsFromSchema(dependsOn: 'generateCodegenSchemaFromJavaScript', type: Exec) {
|
|
|
|
def generatedSchema = tasks.generateCodegenSchemaFromJavaScript.schema();
|
|
def javaPackageName = config.codegenJavaPackageName ?: "com.facebook.fbreact.specs.beta";
|
|
def javaPackageDir = javaPackageName.replace(".", "/");
|
|
def outputDir = file("$generatedSrcDir/java/$javaPackageDir");
|
|
|
|
inputs.files fileTree(dir: codegenDir)
|
|
inputs.files generatedSchema
|
|
outputs.dir(outputDir)
|
|
|
|
def execCommands = ["yarn"] + nodeExecutableAndArgs + [
|
|
codegenGenerateNativeModuleSpecsCli,
|
|
"android",
|
|
"$generatedSchema",
|
|
"$outputDir",
|
|
];
|
|
commandLine execCommands
|
|
}
|
|
|
|
// 4. add deps + srcs
|
|
preBuild.dependsOn generateCodegenArtifactsFromSchema
|
|
|
|
android {
|
|
sourceSets {
|
|
main {
|
|
java {
|
|
srcDirs += "$generatedSrcDir/java"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|