Skip to content

Commit

Permalink
Switch native codegen over to flow parser
Browse files Browse the repository at this point in the history
Summary:
This diff switches the native codegen over to the flow parser

It does this by:
- Creating a new e2e directory
- Migrating the schema.js fixtures to flow types in  e2e/
- Updating the buck tests to use the flow type fixtures
- Finally, updating the rest of rn_codegen to use *NativeComponent instead of *Schema.js

Removing all of the schemas in the next diff to keep this one clean

Reviewed By: cpojer

Differential Revision: D15960603

fbshipit-source-id: 3df28b31e618491301578ab7f6e28a80f55404b2
  • Loading branch information
rickhanlonii authored and facebook-github-bot committed Jun 27, 2019
1 parent ea817fd commit 98b03fa
Show file tree
Hide file tree
Showing 24 changed files with 472 additions and 240 deletions.
113 changes: 15 additions & 98 deletions packages/react-native-codegen/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@ 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/oss:rn_defs.bzl", "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_test")

fb_native.sh_binary(
name = "copy_fixture_schema",
main = "buck_tests/copy_fixture.sh",
resources = [
"buck_tests/copy-fixture.js",
"buck_tests/copy_fixture.sh",
"fbsource//xplat/js:setup_env",
"src/generators/__test_fixtures__/fixtures.js",
],
)
load("@fbsource//xplat/js/react-native-github/packages/react-native-codegen:DEFS.bzl", "rn_codegen")

fb_native.sh_binary(
name = "write_to_json",
Expand Down Expand Up @@ -44,64 +33,20 @@ fb_native.sh_binary(
visibility = ["PUBLIC"],
)

rn_codegen_test(
fixture_name = "INTERFACE_ONLY",
)

rn_codegen_test(
fixture_name = "BOOLEAN_PROP",
)

rn_codegen_test(
fixture_name = "STRING_PROP",
)

rn_codegen_test(
fixture_name = "INTEGER_PROPS",
)

rn_codegen_test(
fixture_name = "FLOAT_PROPS",
)

rn_codegen_test(
fixture_name = "COLOR_PROP",
)

rn_codegen_test(
fixture_name = "IMAGE_PROP",
)

rn_codegen_test(
fixture_name = "POINT_PROP",
)

rn_codegen_test(
fixture_name = "ARRAY_PROPS",
)

rn_codegen_test(
fixture_name = "MULTI_NATIVE_PROP",
)

rn_codegen_test(
fixture_name = "ENUM_PROP",
)

rn_codegen_test(
fixture_name = "EVENT_PROPS",
)

rn_codegen_test(
fixture_name = "EVENT_NESTED_OBJECT_PROPS",
)

rn_codegen_test(
fixture_name = "TWO_COMPONENTS_SAME_FILE",
fb_native.genrule(
name = "codegen_tests_schema",
srcs = glob(
[
"**/e2e/__test_fixtures__/*NativeComponent.js",
],
),
cmd = "$(exe fbsource//xplat/js/react-native-github/packages/react-native-codegen:write_to_json) $OUT $SRCS",
out = "schema-codegen_tests.json",
)

rn_codegen_test(
fixture_name = "TWO_COMPONENTS_DIFFERENT_FILES",
rn_codegen(
name = "codegen_tests",
schema_target = ":codegen_tests_schema",
)

fb_xplat_cxx_binary(
Expand All @@ -120,21 +65,7 @@ fb_xplat_cxx_binary(
],
visibility = ["PUBLIC"],
deps = [
":generated_components-ARRAY_PROPS",
":generated_components-BOOLEAN_PROP",
":generated_components-COLOR_PROP",
":generated_components-ENUM_PROP",
":generated_components-EVENT_NESTED_OBJECT_PROPS",
":generated_components-EVENT_PROPS",
":generated_components-FLOAT_PROPS",
":generated_components-IMAGE_PROP",
":generated_components-INTEGER_PROPS",
":generated_components-INTERFACE_ONLY",
":generated_components-MULTI_NATIVE_PROP",
":generated_components-POINT_PROP",
":generated_components-STRING_PROP",
":generated_components-TWO_COMPONENTS_DIFFERENT_FILES",
":generated_components-TWO_COMPONENTS_SAME_FILE",
":generated_components-codegen_tests",
],
)

Expand All @@ -157,21 +88,7 @@ rn_xplat_cxx_library(
"PUBLIC",
],
deps = [
":generated_components-ARRAY_PROPS",
":generated_components-BOOLEAN_PROP",
":generated_components-COLOR_PROP",
":generated_components-ENUM_PROP",
":generated_components-EVENT_NESTED_OBJECT_PROPS",
":generated_components-EVENT_PROPS",
":generated_components-FLOAT_PROPS",
":generated_components-IMAGE_PROP",
":generated_components-INTEGER_PROPS",
":generated_components-INTERFACE_ONLY",
":generated_components-MULTI_NATIVE_PROP",
":generated_components-POINT_PROP",
":generated_components-STRING_PROP",
":generated_components-TWO_COMPONENTS_DIFFERENT_FILES",
":generated_components-TWO_COMPONENTS_SAME_FILE",
":generated_components-codegen_tests",
],
)

Expand Down
13 changes: 0 additions & 13 deletions packages/react-native-codegen/DEFS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@ load(
"rn_xplat_cxx_library",
)

def rn_codegen_test(
fixture_name = ""):
copy_schema_name = "copy_schema-{}".format(fixture_name)

fb_native.genrule(
name = copy_schema_name,
srcs = [],
cmd = "$(exe fbsource//xplat/js/react-native-github/packages/react-native-codegen:copy_fixture_schema) {} $OUT".format(fixture_name),
out = "schema-{}.json".format(fixture_name),
)

rn_codegen(fixture_name, ":{}".format(copy_schema_name))

def rn_codegen(
name = "",
schema_target = ""):
Expand Down
33 changes: 0 additions & 33 deletions packages/react-native-codegen/buck_tests/copy-fixture.js

This file was deleted.

11 changes: 0 additions & 11 deletions packages/react-native-codegen/buck_tests/copy_fixture.sh

This file was deleted.

18 changes: 3 additions & 15 deletions packages/react-native-codegen/buck_tests/emptyFile.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
#import <react/components/ARRAY_PROPS/ComponentDescriptors.h>
#import <react/components/INTERFACE_ONLY/ComponentDescriptors.h>
#import <react/components/BOOLEAN_PROP/ComponentDescriptors.h>
#import <react/components/STRING_PROP/ComponentDescriptors.h>
#import <react/components/INTEGER_PROPS/ComponentDescriptors.h>
#import <react/components/FLOAT_PROPS/ComponentDescriptors.h>
#import <react/components/COLOR_PROP/ComponentDescriptors.h>
#import <react/components/IMAGE_PROP/ComponentDescriptors.h>
#import <react/components/POINT_PROP/ComponentDescriptors.h>
#import <react/components/MULTI_NATIVE_PROP/ComponentDescriptors.h>
#import <react/components/ENUM_PROP/ComponentDescriptors.h>
#import <react/components/EVENT_NESTED_OBJECT_PROPS/ComponentDescriptors.h>
#import <react/components/EVENT_PROPS/ComponentDescriptors.h>
#import <react/components/TWO_COMPONENTS_SAME_FILE/ComponentDescriptors.h>
#import <react/components/TWO_COMPONENTS_DIFFERENT_FILES/ComponentDescriptors.h>
#import <react/components/codegen_tests/ComponentDescriptors.h>

// TODO: Import every prop and event to asset they're generated

int main(){
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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 {
PointValue,
ColorValue,
} from '../../../../Libraries/StyleSheet/StyleSheetTypes';
import type {ImageSource} from '../../../../Libraries/Image/ImageSource';
import type {
Int32,
Float,
WithDefault,
} from '../../../../Libraries/Types/CodegenTypes';
import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent';

type NativeProps = $ReadOnly<{|
...ViewProps,

// Props
names?: $ReadOnlyArray<string>,
disableds?: $ReadOnlyArray<boolean>,
progress?: $ReadOnlyArray<Int32>,
radii?: $ReadOnlyArray<Float>,
colors?: $ReadOnlyArray<ColorValue>,
srcs?: $ReadOnlyArray<ImageSource>,
points?: $ReadOnlyArray<PointValue>,
sizes?: WithDefault<$ReadOnlyArray<'small' | 'large'>, 'small'>,
|}>;

export default codegenNativeComponent<NativeProps>('ArrayPropsNativeComponent');
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* 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 {WithDefault} from '../../../../Libraries/Types/CodegenTypes';
import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent';

type NativeProps = $ReadOnly<{|
...ViewProps,

// Props
disabled?: WithDefault<boolean, false>,
|}>;

export default codegenNativeComponent<NativeProps>(
'BooleanPropNativeComponent',
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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 {ColorValue} from '../../../../Libraries/StyleSheet/StyleSheetTypes';
import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent';

type NativeProps = $ReadOnly<{|
...ViewProps,

// Props
tintColor?: ColorValue,
|}>;

export default codegenNativeComponent<NativeProps>('ColorPropNativeComponent');
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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 {WithDefault} from '../../../../Libraries/Types/CodegenTypes';
import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent';

type NativeProps = $ReadOnly<{|
...ViewProps,

// Props
alignment?: WithDefault<'top' | 'center' | 'bottom-right', 'center'>,
|}>;

export default codegenNativeComponent<NativeProps>('EnumPropNativeComponent');
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* 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 {
Int32,
BubblingEvent,
WithDefault,
} from '../../../../Libraries/Types/CodegenTypes';
import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent';

type OnChangeEvent = $ReadOnly<{|
location: {
source: {
url: string,
},
x: Int32,
y: Int32,
},
|}>;

type NativeProps = $ReadOnly<{|
...ViewProps,

// Props
disabled?: WithDefault<boolean, false>,

// Events
onChange?: ?(event: BubblingEvent<OnChangeEvent>) => void,
|}>;

export default codegenNativeComponent<NativeProps>(
'EventNestedObjectPropsNativeComponent',
);
Loading

0 comments on commit 98b03fa

Please sign in to comment.