Codegen Buck: fork schema generator target for FB vs OSS via rn_codegen_cli()
Summary: Introduced a helper macro `rn_codegen_cli()` that defines ":write_to_json" and ":rn_codegen" targets differently based on the environment. When run at FB, it uses FB-specific setup. When run in OSS as a standalone repo, we use `yarn install` and `yarn run build` directly, then use `node` to run the output CLI. This way, the same target can be used in both environments on other Buck targets. Motivation: we need this to define rn_codegen_modules() to use codegen to produce Java TurboModule specs, that can be built by CircleCI (we build ReactAndroid via Buck as well). That way we can finally removed the checked-in .java spec files. Changelog: [Internal] Reviewed By: hramos Differential Revision: D24442468 fbshipit-source-id: b1e5fce275100cfe3a1b3ae6d61c1c6d4b25651b
This commit is contained in:
Родитель
7cfc7d65f7
Коммит
16044b3c2a
|
@ -1,7 +1,9 @@
|
|||
load("//tools/build_defs:fb_native_wrapper.bzl", "fb_native")
|
||||
load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "APPLE", "IOS", "IS_OSS_BUILD", "react_native_root_target", "react_native_target", "rn_android_library", "rn_xplat_cxx_library")
|
||||
load("//tools/build_defs/third_party:yarn_defs.bzl", "yarn_workspace")
|
||||
load(":DEFS.bzl", "rn_codegen_components", "rn_codegen_modules")
|
||||
load(":DEFS.bzl", "rn_codegen_cli", "rn_codegen_components", "rn_codegen_modules")
|
||||
|
||||
rn_codegen_cli()
|
||||
|
||||
SETUP_ENV_DEPS = [] if IS_OSS_BUILD else [
|
||||
"//xplat/js:setup_env",
|
||||
|
@ -23,32 +25,6 @@ fb_native.sh_test(
|
|||
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",
|
||||
] + SETUP_ENV_DEPS,
|
||||
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",
|
||||
] + SETUP_ENV_DEPS,
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
|
||||
fb_native.genrule(
|
||||
name = "codegen_tests_schema",
|
||||
srcs = glob(
|
||||
|
|
|
@ -6,6 +6,7 @@ load(
|
|||
"APPLE",
|
||||
"CXX",
|
||||
"IOS",
|
||||
"IS_OSS_BUILD",
|
||||
"MACOSX",
|
||||
"YOGA_CXX_TARGET",
|
||||
"fb_apple_library",
|
||||
|
@ -23,6 +24,87 @@ load(
|
|||
"rn_xplat_cxx_library",
|
||||
)
|
||||
|
||||
# Call this in the react-native-codegen/BUCK file
|
||||
def rn_codegen_cli():
|
||||
if not IS_OSS_BUILD:
|
||||
# FB Internal Setup
|
||||
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 = native.glob(
|
||||
[
|
||||
"buck_tests/**/*.js",
|
||||
"src/**/*.js",
|
||||
],
|
||||
) + [
|
||||
"buck_tests/generate-tests.js",
|
||||
"package.json",
|
||||
"//xplat/js:setup_env",
|
||||
],
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
else:
|
||||
# OSS setup, assumes yarn and node (v12.0.0+) are installed.
|
||||
fb_native.genrule(
|
||||
name = "setup_cli",
|
||||
srcs = native.glob([
|
||||
"scripts/**/*",
|
||||
"src/**/*",
|
||||
], exclude = [
|
||||
"__tests__/**/*",
|
||||
]) + [
|
||||
".babelrc",
|
||||
".prettierrc",
|
||||
"package.json",
|
||||
],
|
||||
out = "build",
|
||||
bash = r"""
|
||||
set -euo pipefail
|
||||
mkdir -p "$OUT"
|
||||
cp -r "$SRCDIR/" "$OUT/"
|
||||
cd "$OUT"
|
||||
yarn install 2> >(grep -v '^warning' 1>&2)
|
||||
yarn run build
|
||||
""",
|
||||
)
|
||||
|
||||
fb_native.sh_binary(
|
||||
name = "write_to_json",
|
||||
main = "scripts/buck-oss/combine_js_to_schema.sh",
|
||||
resources = [
|
||||
":setup_cli",
|
||||
],
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
|
||||
# TODO: This doesn't work yet...
|
||||
fb_native.sh_binary(
|
||||
name = "rn_codegen",
|
||||
main = "buck_tests/generate-tests.sh",
|
||||
resources = native.glob(
|
||||
[
|
||||
"buck_tests/**/*.js",
|
||||
"src/**/*.js",
|
||||
],
|
||||
) + [
|
||||
"buck_tests/generate-tests.js",
|
||||
"package.json",
|
||||
],
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
|
||||
def rn_codegen_modules(
|
||||
native_module_spec_name,
|
||||
name = "",
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/bash
|
||||
# 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.
|
||||
|
||||
# Note: To be invoked by Buck sh_binary() in OSS environment.
|
||||
# DO NOT USE outside of Buck!
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
pushd "$BUCK_DEFAULT_RUNTIME_RESOURCES" >/dev/null
|
||||
node "build/lib/cli/combine/combine-js-to-schema-cli.js" "$@"
|
||||
popd >/dev/null
|
Загрузка…
Ссылка в новой задаче