mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
83edd0c5fe
Summary:
Instead of sourcing-in a .gradle file to setup codegen tasks in Gradle, let's define a proper `com.facebook.react.codegen` Gradle plugin, so that any Gradle project (lib/app) can include it via:
```
plugins {
id 'com.facebook.react.codegen'
}
```
The idea (not yet implemented in this commit) is to then allow those projects to add this section in the projects:
```
codegen {
enableCodegen = ...
jsRootDir = ...
}
```
This is more scalable and less hacky.
Important notes:
* The Gradle plugin should be prepared during the build, we're not going to publish it to Maven or other repo at this point.
* This setup is inspired by composite build setup explained here: https://ncorti.com/blog/gradle-plugins-and-composite-builds
* All android specific setup is added under `packages/react-native-codegen/android/` dir, but long term, we may want to move it up to `packages/react-native-codegen/` along side setup for other platforms.
* As part of this setup, the plugin will have an option (to be validated) to produce Java specs using https://github.com/square/javapoet
* This is the same library already used for React Native Android annotation processors
* This generator will not deal with parsing Flow types into schema, it will just takes in the schema and produce Java code
* We're evaluating whether JavaPoet is a better choice for Java code generation long term, vs building it in JS via string concatenation: https://github.com/facebook/react-native/blob/master/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js
* This commit produces a sample Java code, not the actual codegen output
Changelog: [Internal]
To try this out, run this Gradle task:
```
USE_CODEGEN=1 ./gradlew :ReactAndroid:generateJava
```
Reviewed By: JoshuaGross, mdvacca
Differential Revision: D22917315
fbshipit-source-id: 0b79dba939b73ff1305b4b4fd86ab897c7a48d53
185 lines
4.8 KiB
Python
185 lines
4.8 KiB
Python
load("@fbsource//tools/build_defs:fb_native_wrapper.bzl", "fb_native")
|
|
load("@fbsource//tools/build_defs:fb_xplat_cxx_binary.bzl", "fb_xplat_cxx_binary")
|
|
load("@fbsource//tools/build_defs:platform_defs.bzl", "ANDROID", "APPLE", "IOS")
|
|
load("@fbsource//tools/build_defs/oss:rn_defs.bzl", "rn_android_library", "rn_xplat_cxx_library")
|
|
load("@fbsource//tools/build_defs/third_party:yarn_defs.bzl", "yarn_workspace")
|
|
load("@fbsource//xplat/js/react-native-github/packages/react-native-codegen:DEFS.bzl", "rn_codegen_components", "rn_codegen_modules")
|
|
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_target")
|
|
|
|
fb_native.sh_binary(
|
|
name = "codegen_rn_modules_tests",
|
|
main = "src/cli/verify_with_old_codegen.sh",
|
|
visibility = ["PUBLIC"],
|
|
resources = [
|
|
"src/cli/verify_with_old_codegen.js",
|
|
"src/cli/verify_with_old_codegen.sh",
|
|
"//xplat/js:setup_env",
|
|
],
|
|
)
|
|
|
|
fb_native.sh_test(
|
|
name = "verify_all_modules_with_old_codegen",
|
|
test = "src/cli/verify_all_modules_with_old_codegen.sh",
|
|
visibility = ["PUBLIC"],
|
|
)
|
|
|
|
fb_native.sh_binary(
|
|
name = "write_to_json",
|
|
main = "src/cli/combine/combine_js_to_schema.sh",
|
|
resources = [
|
|
"src/cli/combine/combine-js-to-schema.js",
|
|
"src/cli/combine/combine_js_to_schema.sh",
|
|
":yarn-workspace",
|
|
"//xplat/js:setup_env",
|
|
],
|
|
visibility = ["PUBLIC"],
|
|
)
|
|
|
|
fb_native.sh_binary(
|
|
name = "rn_codegen",
|
|
main = "buck_tests/generate-tests.sh",
|
|
resources = glob(
|
|
[
|
|
"buck_tests/**/*.js",
|
|
"src/**/*.js",
|
|
],
|
|
) + [
|
|
"buck_tests/generate-tests.js",
|
|
"package.json",
|
|
"//xplat/js:setup_env",
|
|
"yarn.lock",
|
|
],
|
|
visibility = ["PUBLIC"],
|
|
)
|
|
|
|
fb_native.genrule(
|
|
name = "codegen_tests_schema",
|
|
srcs = glob(
|
|
[
|
|
"**/e2e/__test_fixtures__/components/*NativeComponent.js",
|
|
"**/e2e/__test_fixtures__/modules/Native*.js",
|
|
],
|
|
),
|
|
cmd = "$(exe //xplat/js/react-native-github/packages/react-native-codegen:write_to_json) $OUT $SRCS",
|
|
out = "schema-codegen_tests.json",
|
|
)
|
|
|
|
rn_codegen_components(
|
|
name = "codegen_tests",
|
|
schema_target = ":codegen_tests_schema",
|
|
)
|
|
|
|
rn_codegen_modules(
|
|
name = "codegen_tests",
|
|
native_module_spec_name = "FBReactNativeTestSpec",
|
|
schema_target = ":codegen_tests_schema",
|
|
)
|
|
|
|
fb_xplat_cxx_binary(
|
|
name = "rn_codegen_binary",
|
|
srcs = ["buck_tests/emptyFile.cpp"],
|
|
compiler_flags = [
|
|
"-fexceptions",
|
|
"-frtti",
|
|
"-std=c++14",
|
|
"-Wall",
|
|
],
|
|
platforms = (ANDROID, APPLE),
|
|
preprocessor_flags = [
|
|
"-DLOG_TAG=\"ReactNative\"",
|
|
"-DWITH_FBSYSTRACE=1",
|
|
],
|
|
visibility = ["PUBLIC"],
|
|
deps = [
|
|
":generated_components-codegen_tests",
|
|
],
|
|
)
|
|
|
|
rn_android_library(
|
|
name = "rn_codegen_library_java",
|
|
srcs = glob(
|
|
["**/*.java"],
|
|
exclude = ["android/gradlePlugin-build/**/*"],
|
|
),
|
|
visibility = [
|
|
"PUBLIC",
|
|
],
|
|
deps = [
|
|
react_native_target("java/com/facebook/react/bridge:bridge"),
|
|
react_native_target("java/com/facebook/react/common:common"),
|
|
react_native_target("java/com/facebook/react/views/view:view"),
|
|
react_native_target("java/com/facebook/react/uimanager:uimanager"),
|
|
":generated_components_java-codegen_tests",
|
|
],
|
|
)
|
|
|
|
rn_xplat_cxx_library(
|
|
name = "rn_codegen_library",
|
|
srcs = ["buck_tests/emptyFile.cpp"],
|
|
headers = [],
|
|
compiler_flags = [
|
|
"-fexceptions",
|
|
"-frtti",
|
|
"-std=c++14",
|
|
"-Wall",
|
|
],
|
|
platforms = (ANDROID, APPLE),
|
|
preprocessor_flags = [
|
|
"-DLOG_TAG=\"ReactNative\"",
|
|
"-DWITH_FBSYSTRACE=1",
|
|
],
|
|
visibility = [
|
|
"PUBLIC",
|
|
],
|
|
deps = [
|
|
":generated_components-codegen_tests",
|
|
],
|
|
)
|
|
|
|
rn_xplat_cxx_library(
|
|
name = "rn_codegen_library_mm",
|
|
srcs = ["buck_tests/emptyFile.mm"],
|
|
headers = [],
|
|
apple_sdks = (IOS,),
|
|
compiler_flags = [
|
|
"-fexceptions",
|
|
"-frtti",
|
|
"-std=c++14",
|
|
"-Wall",
|
|
],
|
|
platforms = (APPLE),
|
|
preprocessor_flags = [
|
|
"-DLOG_TAG=\"ReactNative\"",
|
|
"-DWITH_FBSYSTRACE=1",
|
|
],
|
|
visibility = [
|
|
"PUBLIC",
|
|
],
|
|
deps = [
|
|
":generated_components-codegen_tests",
|
|
":generated_objcpp_modules-codegen_tests",
|
|
],
|
|
)
|
|
|
|
yarn_workspace(
|
|
name = "yarn-workspace",
|
|
srcs = glob(
|
|
["**/*.js"],
|
|
exclude = [
|
|
"**/__fixtures__/**",
|
|
"**/__flowtests__/**",
|
|
"**/__mocks__/**",
|
|
"**/__server_snapshot_tests__/**",
|
|
"**/__tests__/**",
|
|
"**/node_modules/**",
|
|
"**/node_modules/.bin/**",
|
|
"**/.*",
|
|
"**/.*/**",
|
|
"**/.*/.*",
|
|
"**/*.xcodeproj/**",
|
|
"**/*.xcworkspace/**",
|
|
],
|
|
),
|
|
visibility = ["PUBLIC"],
|
|
)
|