Skip to content

Commit

Permalink
Codegen: Make react-native-codegen BUCK deps OSS-compatible
Browse files Browse the repository at this point in the history
Summary:
Added a few FB vs OSS polyfills:
* react_native_root_target() to refer to the root FB react-native-github/ dir or repo dir in OSS
* react_native_xplat_synced_target() for anything xplat
* a few others

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24437245

fbshipit-source-id: ee290a87a98a8e9be67b102a96f2faac2a2cb92b
  • Loading branch information
fkgozali authored and facebook-github-bot committed Oct 23, 2020
1 parent f8eaab4 commit 7cfc7d6
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 24 deletions.
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"),
],
)
17 changes: 9 additions & 8 deletions packages/react-native-codegen/BUCK
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
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")

SETUP_ENV_DEPS = [] if IS_OSS_BUILD else [
"//xplat/js:setup_env",
]

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",
],
] + SETUP_ENV_DEPS,
)

fb_native.sh_test(
Expand All @@ -27,8 +30,7 @@ fb_native.sh_binary(
"src/cli/combine/combine-js-to-schema.js",
"src/cli/combine/combine_js_to_schema.sh",
":yarn-workspace",
"//xplat/js:setup_env",
],
] + SETUP_ENV_DEPS,
visibility = ["PUBLIC"],
)

Expand All @@ -43,8 +45,7 @@ fb_native.sh_binary(
) + [
"buck_tests/generate-tests.js",
"package.json",
"//xplat/js:setup_env",
],
] + SETUP_ENV_DEPS,
visibility = ["PUBLIC"],
)

Expand All @@ -56,7 +57,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
14 changes: 8 additions & 6 deletions packages/react-native-codegen/DEFS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ 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",
Expand All @@ -36,7 +38,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 +82,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 +119,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 +190,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 +419,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
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,
)

0 comments on commit 7cfc7d6

Please sign in to comment.