Set up buck to generate native code for rncore
Summary: Refactoring the codegen buck target from being used just for testing to a way that can be depended on for the real fabric target to replace the existing component code. After this change, we can build a target for react native to use the codegen to create the native files for Switch. A follow up diff will be necessary to hook this up and actually replace the native files for switch. Reviewed By: mdvacca Differential Revision: D13662363 fbshipit-source-id: 599dd9ed9ca24ffb5c5784396f4bee7457d94d6d
This commit is contained in:
parent
b98964ba39
commit
8f1003fb9f
|
@ -0,0 +1,94 @@
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @format
|
||||||
|
* @flow
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
import type {SchemaType} from '../../../codegen/src/CodegenSchema.js';
|
||||||
|
|
||||||
|
const SwitchSchema: SchemaType = {
|
||||||
|
modules: {
|
||||||
|
Switch: {
|
||||||
|
components: {
|
||||||
|
Switch: {
|
||||||
|
extendsProps: [
|
||||||
|
{
|
||||||
|
type: 'ReactNativeBuiltInType',
|
||||||
|
knownTypeName: 'ReactNativeCoreViewProps',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
events: [
|
||||||
|
{
|
||||||
|
name: 'onChange',
|
||||||
|
optional: true,
|
||||||
|
bubblingType: 'bubble',
|
||||||
|
typeAnnotation: {
|
||||||
|
type: 'EventTypeAnnotation',
|
||||||
|
argument: {
|
||||||
|
type: 'ObjectTypeAnnotation',
|
||||||
|
properties: [
|
||||||
|
{
|
||||||
|
type: 'BooleanTypeAnnotation',
|
||||||
|
name: 'value',
|
||||||
|
optional: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
props: [
|
||||||
|
{
|
||||||
|
name: 'disabled',
|
||||||
|
optional: true,
|
||||||
|
typeAnnotation: {
|
||||||
|
type: 'BooleanTypeAnnotation',
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'value',
|
||||||
|
optional: true,
|
||||||
|
typeAnnotation: {
|
||||||
|
type: 'BooleanTypeAnnotation',
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'tintColor',
|
||||||
|
optional: true,
|
||||||
|
typeAnnotation: {
|
||||||
|
type: 'NativePrimitiveTypeAnnotation',
|
||||||
|
name: 'ColorPrimitive',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'onTintColor',
|
||||||
|
optional: true,
|
||||||
|
typeAnnotation: {
|
||||||
|
type: 'NativePrimitiveTypeAnnotation',
|
||||||
|
name: 'ColorPrimitive',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'thumbTintColor',
|
||||||
|
optional: true,
|
||||||
|
typeAnnotation: {
|
||||||
|
type: 'NativePrimitiveTypeAnnotation',
|
||||||
|
name: 'ColorPrimitive',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = SwitchSchema;
|
50
codegen/BUCK
50
codegen/BUCK
|
@ -13,6 +13,16 @@ fb_native.sh_binary(
|
||||||
"src/generators/__test_fixtures__/fixtures.js",
|
"src/generators/__test_fixtures__/fixtures.js",
|
||||||
"xplat//js:setup_env",
|
"xplat//js:setup_env",
|
||||||
],
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
fb_native.sh_binary(
|
||||||
|
name = "write_to_json",
|
||||||
|
main = "buck_tests/combine_js_to_schema.sh",
|
||||||
|
resources = [
|
||||||
|
"buck_tests/combine-js-to-schema.js",
|
||||||
|
"buck_tests/combine_js_to_schema.sh",
|
||||||
|
"xplat//js:setup_env",
|
||||||
|
],
|
||||||
visibility = ["PUBLIC"],
|
visibility = ["PUBLIC"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -89,16 +99,16 @@ fb_xplat_cxx_binary(
|
||||||
],
|
],
|
||||||
visibility = ["PUBLIC"],
|
visibility = ["PUBLIC"],
|
||||||
deps = [
|
deps = [
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_BOOLEAN_PROP",
|
":generated_components-SINGLE_COMPONENT_WITH_BOOLEAN_PROP",
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_COLOR_PROP",
|
":generated_components-SINGLE_COMPONENT_WITH_COLOR_PROP",
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_ENUM_PROP",
|
":generated_components-SINGLE_COMPONENT_WITH_ENUM_PROP",
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_EVENT_NESTED_OBJECT_PROPS",
|
":generated_components-SINGLE_COMPONENT_WITH_EVENT_NESTED_OBJECT_PROPS",
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_EVENT_PROPS",
|
":generated_components-SINGLE_COMPONENT_WITH_EVENT_PROPS",
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_FLOAT_PROPS",
|
":generated_components-SINGLE_COMPONENT_WITH_FLOAT_PROPS",
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_INTEGER_PROPS",
|
":generated_components-SINGLE_COMPONENT_WITH_INTEGER_PROPS",
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_STRING_PROP",
|
":generated_components-SINGLE_COMPONENT_WITH_STRING_PROP",
|
||||||
":generated_fixture_library-TWO_COMPONENTS_DIFFERENT_FILES",
|
":generated_components-TWO_COMPONENTS_DIFFERENT_FILES",
|
||||||
":generated_fixture_library-TWO_COMPONENTS_SAME_FILE",
|
":generated_components-TWO_COMPONENTS_SAME_FILE",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -121,15 +131,15 @@ rn_xplat_cxx_library(
|
||||||
"PUBLIC",
|
"PUBLIC",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_BOOLEAN_PROP",
|
":generated_components-SINGLE_COMPONENT_WITH_BOOLEAN_PROP",
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_COLOR_PROP",
|
":generated_components-SINGLE_COMPONENT_WITH_COLOR_PROP",
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_ENUM_PROP",
|
":generated_components-SINGLE_COMPONENT_WITH_ENUM_PROP",
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_EVENT_NESTED_OBJECT_PROPS",
|
":generated_components-SINGLE_COMPONENT_WITH_EVENT_NESTED_OBJECT_PROPS",
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_EVENT_PROPS",
|
":generated_components-SINGLE_COMPONENT_WITH_EVENT_PROPS",
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_FLOAT_PROPS",
|
":generated_components-SINGLE_COMPONENT_WITH_FLOAT_PROPS",
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_INTEGER_PROPS",
|
":generated_components-SINGLE_COMPONENT_WITH_INTEGER_PROPS",
|
||||||
":generated_fixture_library-SINGLE_COMPONENT_WITH_STRING_PROP",
|
":generated_components-SINGLE_COMPONENT_WITH_STRING_PROP",
|
||||||
":generated_fixture_library-TWO_COMPONENTS_DIFFERENT_FILES",
|
":generated_components-TWO_COMPONENTS_DIFFERENT_FILES",
|
||||||
":generated_fixture_library-TWO_COMPONENTS_SAME_FILE",
|
":generated_components-TWO_COMPONENTS_SAME_FILE",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
load("@fbsource//tools/build_defs:default_platform_defs.bzl", "ANDROID", "APPLE")
|
|
||||||
load("@fbsource//tools/build_defs:fb_native_wrapper.bzl", "fb_native")
|
load("@fbsource//tools/build_defs:fb_native_wrapper.bzl", "fb_native")
|
||||||
|
load("@fbsource//tools/build_defs/apple:flag_defs.bzl", "get_debug_preprocessor_flags")
|
||||||
load(
|
load(
|
||||||
"//tools/build_defs/oss:rn_defs.bzl",
|
"//tools/build_defs/oss:rn_defs.bzl",
|
||||||
|
"ANDROID",
|
||||||
|
"APPLE",
|
||||||
|
"get_apple_compiler_flags",
|
||||||
|
"get_apple_inspector_flags",
|
||||||
"react_native_xplat_target",
|
"react_native_xplat_target",
|
||||||
"rn_xplat_cxx_library",
|
"rn_xplat_cxx_library",
|
||||||
)
|
)
|
||||||
|
@ -9,26 +13,32 @@ load(
|
||||||
def rn_codegen_test(
|
def rn_codegen_test(
|
||||||
fixture_name = ""):
|
fixture_name = ""):
|
||||||
copy_schema_name = "copy_schema-{}".format(fixture_name)
|
copy_schema_name = "copy_schema-{}".format(fixture_name)
|
||||||
generate_fixtures_rule_name = "generate_fixtures-{}".format(fixture_name)
|
|
||||||
generate_component_descriptor_h_name = "generate_component_descriptor_h-{}".format(fixture_name)
|
|
||||||
generate_event_emitter_cpp_name = "generate_event_emitter_cpp-{}".format(fixture_name)
|
|
||||||
generate_event_emitter_h_name = "generate_event_emitter_h-{}".format(fixture_name)
|
|
||||||
generate_props_cpp_name = "generate_props_cpp-{}".format(fixture_name)
|
|
||||||
generate_props_h_name = "generated_props_h-{}".format(fixture_name)
|
|
||||||
generate_shadow_node_h_name = "generated_shadow_node_h-{}".format(fixture_name)
|
|
||||||
|
|
||||||
fb_native.genrule(
|
fb_native.genrule(
|
||||||
name = copy_schema_name,
|
name = copy_schema_name,
|
||||||
srcs = [],
|
srcs = [],
|
||||||
cmd = "$(exe :copy_fixture_schema) {} $OUT".format(fixture_name),
|
cmd = "$(exe xplat//js/react-native-github/codegen:copy_fixture_schema) {} $OUT".format(fixture_name),
|
||||||
out = "schema-{}.json".format(fixture_name),
|
out = "schema-{}.json".format(fixture_name),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
rn_codegen(fixture_name, ":{}".format(copy_schema_name))
|
||||||
|
|
||||||
|
def rn_codegen(
|
||||||
|
name = "",
|
||||||
|
schema_target = ""):
|
||||||
|
generate_fixtures_rule_name = "generate_fixtures-{}".format(name)
|
||||||
|
generate_component_descriptor_h_name = "generate_component_descriptor_h-{}".format(name)
|
||||||
|
generate_event_emitter_cpp_name = "generate_event_emitter_cpp-{}".format(name)
|
||||||
|
generate_event_emitter_h_name = "generate_event_emitter_h-{}".format(name)
|
||||||
|
generate_props_cpp_name = "generate_props_cpp-{}".format(name)
|
||||||
|
generate_props_h_name = "generated_props_h-{}".format(name)
|
||||||
|
generate_shadow_node_h_name = "generated_shadow_node_h-{}".format(name)
|
||||||
|
|
||||||
fb_native.genrule(
|
fb_native.genrule(
|
||||||
name = generate_fixtures_rule_name,
|
name = generate_fixtures_rule_name,
|
||||||
srcs = [],
|
srcs = [],
|
||||||
cmd = "$(exe :rn_codegen) $(location :{}) {} $OUT".format(copy_schema_name, fixture_name),
|
cmd = "$(exe xplat//js/react-native-github/codegen:rn_codegen) $(location {}) {} $OUT".format(schema_target, name),
|
||||||
out = "codegenfiles-{}".format(fixture_name),
|
out = "codegenfiles-{}".format(name),
|
||||||
)
|
)
|
||||||
|
|
||||||
fb_native.genrule(
|
fb_native.genrule(
|
||||||
|
@ -69,7 +79,7 @@ def rn_codegen_test(
|
||||||
|
|
||||||
# libs
|
# libs
|
||||||
rn_xplat_cxx_library(
|
rn_xplat_cxx_library(
|
||||||
name = "generated_fixture_library-{}".format(fixture_name),
|
name = "generated_components-{}".format(name),
|
||||||
srcs = [
|
srcs = [
|
||||||
":{}".format(generate_event_emitter_cpp_name),
|
":{}".format(generate_event_emitter_cpp_name),
|
||||||
":{}".format(generate_props_cpp_name),
|
":{}".format(generate_props_cpp_name),
|
||||||
|
@ -86,19 +96,31 @@ def rn_codegen_test(
|
||||||
"Props.h": ":{}".format(generate_props_h_name),
|
"Props.h": ":{}".format(generate_props_h_name),
|
||||||
"ShadowNodes.h": ":{}".format(generate_shadow_node_h_name),
|
"ShadowNodes.h": ":{}".format(generate_shadow_node_h_name),
|
||||||
},
|
},
|
||||||
header_namespace = "react/components/{}".format(fixture_name),
|
header_namespace = "react/components/{}".format(name),
|
||||||
compiler_flags = [
|
compiler_flags = [
|
||||||
"-fexceptions",
|
"-fexceptions",
|
||||||
"-frtti",
|
"-frtti",
|
||||||
"-std=c++14",
|
"-std=c++14",
|
||||||
"-Wall",
|
"-Wall",
|
||||||
],
|
],
|
||||||
|
fbobjc_compiler_flags = get_apple_compiler_flags(),
|
||||||
|
fbobjc_preprocessor_flags = get_debug_preprocessor_flags() + get_apple_inspector_flags(),
|
||||||
platforms = (ANDROID, APPLE),
|
platforms = (ANDROID, APPLE),
|
||||||
preprocessor_flags = [
|
preprocessor_flags = [
|
||||||
"-DLOG_TAG=\"ReactNative\"",
|
"-DLOG_TAG=\"ReactNative\"",
|
||||||
"-DWITH_FBSYSTRACE=1",
|
"-DWITH_FBSYSTRACE=1",
|
||||||
],
|
],
|
||||||
|
visibility = ["PUBLIC"],
|
||||||
deps = [
|
deps = [
|
||||||
|
"xplat//fbsystrace:fbsystrace",
|
||||||
|
"xplat//folly:headers_only",
|
||||||
|
"xplat//folly:memory",
|
||||||
|
"xplat//folly:molly",
|
||||||
|
"xplat//third-party/glog:glog",
|
||||||
|
"xplat//yoga:yoga",
|
||||||
|
react_native_xplat_target("fabric/debug:debug"),
|
||||||
|
react_native_xplat_target("fabric/core:core"),
|
||||||
|
react_native_xplat_target("fabric/graphics:graphics"),
|
||||||
react_native_xplat_target("fabric/components/view:view"),
|
react_native_xplat_target("fabric/components/view:view"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @flow
|
||||||
|
* @format
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
if (args.length !== 2) {
|
||||||
|
throw new Error(
|
||||||
|
'Expected to receive the input path and output path as arguments',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const src = args[0];
|
||||||
|
const outputPath = args[1];
|
||||||
|
|
||||||
|
let file;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Eventually this will be replaced with a script that reads and parses
|
||||||
|
// the file via ast
|
||||||
|
// $FlowFixMe Can't require dynamic variables
|
||||||
|
file = require(src);
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(`Can't require file at ${src}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(outputPath, JSON.stringify(file, null, 2));
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -u
|
||||||
|
|
||||||
|
THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
|
||||||
|
|
||||||
|
# shellcheck source=xplat/js/env-utils/setup_env_vars.sh
|
||||||
|
source "$THIS_DIR/../../../env-utils/setup_env_vars.sh"
|
||||||
|
|
||||||
|
exec "$FLOW_NODE_BINARY" "$THIS_DIR/combine-js-to-schema.js" "$@"
|
Loading…
Reference in New Issue