Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from facebook:master #318

Merged
merged 2 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@fbsource//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_xplat_target", "rn_xplat_cxx_library")
load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_xplat_target", "rn_xplat_cxx_library")

rn_xplat_cxx_library(
name = "jni",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@fbsource//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_target", "react_native_xplat_target", "rn_xplat_cxx_library")
load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_target", "react_native_xplat_shared_library_target", "react_native_xplat_target", "rn_xplat_cxx_library")

rn_xplat_cxx_library(
name = "jni",
Expand Down Expand Up @@ -33,7 +33,7 @@ rn_xplat_cxx_library(
],
exported_deps = [
":callinvokerholder",
"//xplat/jsi:jsi",
react_native_xplat_shared_library_target("jsi:jsi"),
react_native_xplat_target("react/nativemodule/core:core"),
react_native_target("java/com/facebook/react/reactperflogger/jni:jni"),
],
Expand Down
3 changes: 1 addition & 2 deletions ReactCommon/jsi/BUCK
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# BUILD FILE SYNTAX: SKYLARK

load("@fbsource//tools/build_defs:default_platform_defs.bzl", "APPLE", "IOS", "MACOSX")
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_xplat_dep", "rn_xplat_cxx_library")
load("//tools/build_defs/oss:rn_defs.bzl", "APPLE", "IOS", "MACOSX", "react_native_xplat_dep", "rn_xplat_cxx_library")

rn_xplat_cxx_library(
name = "jsi",
Expand Down
5 changes: 2 additions & 3 deletions ReactCommon/react/nativemodule/core/BUCK
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("@fbsource//tools/build_defs/apple:flag_defs.bzl", "OBJC_ARC_PREPROCESSOR_FLAGS", "get_preprocessor_flags_for_build_mode", "get_static_library_ios_flags")
load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "APPLE", "FBJNI_TARGET", "react_native_target", "react_native_xplat_target", "rn_xplat_cxx_library", "subdir_glob")
load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "APPLE", "FBJNI_TARGET", "OBJC_ARC_PREPROCESSOR_FLAGS", "get_preprocessor_flags_for_build_mode", "get_static_library_ios_flags", "react_native_target", "react_native_xplat_shared_library_target", "react_native_xplat_target", "rn_xplat_cxx_library", "subdir_glob")

rn_xplat_cxx_library(
name = "core",
Expand Down Expand Up @@ -83,6 +82,6 @@ rn_xplat_cxx_library(
react_native_xplat_target("reactperflogger:reactperflogger"),
],
exported_deps = [
"//xplat/jsi:jsi",
react_native_xplat_shared_library_target("jsi:jsi"),
],
)
43 changes: 10 additions & 33 deletions packages/react-native-codegen/BUCK
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
load("//tools/build_defs:fb_native_wrapper.bzl", "fb_native")
load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "APPLE", "IOS", "react_native_target", "rn_android_library", "rn_xplat_cxx_library")
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",
]

fb_native.sh_binary(
name = "codegen_rn_modules_tests",
Expand All @@ -10,8 +16,7 @@ fb_native.sh_binary(
resources = [
"src/cli/verify_with_old_codegen.js",
"src/cli/verify_with_old_codegen.sh",
"//xplat/js:setup_env",
],
] + SETUP_ENV_DEPS,
)

fb_native.sh_test(
Expand All @@ -20,34 +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",
"//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",
],
visibility = ["PUBLIC"],
)

fb_native.genrule(
name = "codegen_tests_schema",
srcs = glob(
Expand All @@ -56,7 +33,7 @@ fb_native.genrule(
"**/e2e/__test_fixtures__/modules/Native*.js",
],
),
cmd = "$(exe //xplat/js/react-native-github/packages/react-native-codegen:write_to_json) $OUT $SRCS",
cmd = "$(exe {}) $OUT $SRCS".format(react_native_root_target("packages/react-native-codegen:write_to_json")),
out = "schema-codegen_tests.json",
)

Expand Down
96 changes: 90 additions & 6 deletions packages/react-native-codegen/DEFS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load(
"APPLE",
"CXX",
"IOS",
"IS_OSS_BUILD",
"MACOSX",
"YOGA_CXX_TARGET",
"fb_apple_library",
Expand All @@ -14,13 +15,96 @@ load(
"get_apple_inspector_flags",
"get_preprocessor_flags_for_build_mode",
"react_native_dep",
"react_native_root_target",
"react_native_target",
"react_native_xplat_shared_library_target",
"react_native_xplat_target",
"react_native_xplat_target_apple",
"rn_android_library",
"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 = "",
Expand All @@ -36,7 +120,7 @@ def rn_codegen_modules(
fb_native.genrule(
name = generate_fixtures_rule_name,
srcs = native.glob(["src/generators/**/*.js"]),
cmd = "$(exe //xplat/js/react-native-github/packages/react-native-codegen:rn_codegen) $(location {}) {} $OUT {}".format(schema_target, name, native_module_spec_name),
cmd = "$(exe {}) $(location {}) {} $OUT {}".format(react_native_root_target("packages/react-native-codegen:rn_codegen"), schema_target, name, native_module_spec_name),
out = "codegenfiles-{}".format(name),
labels = ["codegen_rule"],
)
Expand Down Expand Up @@ -80,8 +164,8 @@ def rn_codegen_modules(
labels = ["codegen_rule"],
visibility = ["PUBLIC"],
deps = [
"//fbandroid/third-party/java/jsr-305:jsr-305",
"//fbandroid/third-party/java/jsr-330:jsr-330",
react_native_dep("third-party/java/jsr-305:jsr-305"),
react_native_dep("third-party/java/jsr-330:jsr-330"),
react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/common:common"),
],
Expand Down Expand Up @@ -117,7 +201,7 @@ def rn_codegen_modules(
],
deps = [],
exported_deps = [
"//xplat/jsi:jsi",
react_native_xplat_shared_library_target("jsi:jsi"),
react_native_xplat_target("react/nativemodule/core:core"),
],
platforms = (ANDROID,),
Expand Down Expand Up @@ -188,7 +272,7 @@ def rn_codegen_components(
fb_native.genrule(
name = generate_fixtures_rule_name,
srcs = native.glob(["src/generators/**/*.js"]),
cmd = "$(exe //xplat/js/react-native-github/packages/react-native-codegen:rn_codegen) $(location {}) {} $OUT {}".format(schema_target, name, name),
cmd = "$(exe {}) $(location {}) {} $OUT {}".format(react_native_root_target("packages/react-native-codegen:rn_codegen"), schema_target, name, name),
out = "codegenfiles-{}".format(name),
labels = ["codegen_rule"],
)
Expand Down Expand Up @@ -417,7 +501,7 @@ def rn_codegen_cxx_modules(
fb_native.genrule(
name = generate_fixtures_rule_name,
srcs = native.glob(["src/generators/**/*.js"]),
cmd = "$(exe //xplat/js/react-native-github/packages/react-native-codegen:rn_codegen) $(location {}) {} $OUT {}".format(schema_target, name, name),
cmd = "$(exe {}) $(location {}) {} $OUT {}".format(react_native_root_target("packages/react-native-codegen:rn_codegen"), schema_target, name, name),
out = "codegenfiles-{}".format(name),
labels = ["codegen_rule"],
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
17 changes: 16 additions & 1 deletion tools/build_defs/oss/rn_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@ _DEBUG_PREPROCESSOR_FLAGS = []

_APPLE_COMPILER_FLAGS = []

def get_apple_compiler_flags():
return _APPLE_COMPILER_FLAGS

def get_preprocessor_flags_for_build_mode():
return _DEBUG_PREPROCESSOR_FLAGS

def get_apple_compiler_flags():
def get_static_library_ios_flags():
return _APPLE_COMPILER_FLAGS

OBJC_ARC_PREPROCESSOR_FLAGS = [
"-fobjc-arc",
"-fno-objc-arc-exceptions",
"-Qunused-arguments",
]

IS_OSS_BUILD = True

GLOG_DEP = "//ReactAndroid/build/third-party-ndk/glog:glog"
Expand Down Expand Up @@ -82,6 +91,12 @@ def react_native_xplat_target(path):
def react_native_xplat_target_apple(path):
return react_native_xplat_target(path) + "Apple"

def react_native_root_target(path):
return "//" + path

def react_native_xplat_shared_library_target(path):
return react_native_xplat_target(path)

# Example: react_native_tests_target('java/com/facebook/react/modules:modules')
def react_native_tests_target(path):
return "//ReactAndroid/src/test/" + path
Expand Down
7 changes: 6 additions & 1 deletion tools/build_defs/third_party/yarn_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@

def yarn_workspace(name, srcs = [], transform_ignore = None, visibility = None):
# Noop for OSS vs FB build compatibility for now
unused = True
native.genrule(
name = name,
cmd = "echo {} > $OUT".format(name),
out = "{}.txt".format(name),
visibility = visibility,
)