Skip to content

Commit 98b03fa

Browse files
rickhanloniifacebook-github-bot
authored andcommitted
Switch native codegen over to flow parser
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
1 parent ea817fd commit 98b03fa

24 files changed

+472
-240
lines changed

packages/react-native-codegen/BUCK

+15-98
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,7 @@ load("@fbsource//tools/build_defs:fb_native_wrapper.bzl", "fb_native")
33
load("@fbsource//tools/build_defs:fb_xplat_cxx_binary.bzl", "fb_xplat_cxx_binary")
44
load("@fbsource//tools/build_defs/oss:rn_defs.bzl", "rn_xplat_cxx_library")
55
load("@fbsource//tools/build_defs/third_party:yarn_defs.bzl", "yarn_workspace")
6-
load("@fbsource//xplat/js/react-native-github/packages/react-native-codegen:DEFS.bzl", "rn_codegen_test")
7-
8-
fb_native.sh_binary(
9-
name = "copy_fixture_schema",
10-
main = "buck_tests/copy_fixture.sh",
11-
resources = [
12-
"buck_tests/copy-fixture.js",
13-
"buck_tests/copy_fixture.sh",
14-
"fbsource//xplat/js:setup_env",
15-
"src/generators/__test_fixtures__/fixtures.js",
16-
],
17-
)
6+
load("@fbsource//xplat/js/react-native-github/packages/react-native-codegen:DEFS.bzl", "rn_codegen")
187

198
fb_native.sh_binary(
209
name = "write_to_json",
@@ -44,64 +33,20 @@ fb_native.sh_binary(
4433
visibility = ["PUBLIC"],
4534
)
4635

47-
rn_codegen_test(
48-
fixture_name = "INTERFACE_ONLY",
49-
)
50-
51-
rn_codegen_test(
52-
fixture_name = "BOOLEAN_PROP",
53-
)
54-
55-
rn_codegen_test(
56-
fixture_name = "STRING_PROP",
57-
)
58-
59-
rn_codegen_test(
60-
fixture_name = "INTEGER_PROPS",
61-
)
62-
63-
rn_codegen_test(
64-
fixture_name = "FLOAT_PROPS",
65-
)
66-
67-
rn_codegen_test(
68-
fixture_name = "COLOR_PROP",
69-
)
70-
71-
rn_codegen_test(
72-
fixture_name = "IMAGE_PROP",
73-
)
74-
75-
rn_codegen_test(
76-
fixture_name = "POINT_PROP",
77-
)
78-
79-
rn_codegen_test(
80-
fixture_name = "ARRAY_PROPS",
81-
)
82-
83-
rn_codegen_test(
84-
fixture_name = "MULTI_NATIVE_PROP",
85-
)
86-
87-
rn_codegen_test(
88-
fixture_name = "ENUM_PROP",
89-
)
90-
91-
rn_codegen_test(
92-
fixture_name = "EVENT_PROPS",
93-
)
94-
95-
rn_codegen_test(
96-
fixture_name = "EVENT_NESTED_OBJECT_PROPS",
97-
)
98-
99-
rn_codegen_test(
100-
fixture_name = "TWO_COMPONENTS_SAME_FILE",
36+
fb_native.genrule(
37+
name = "codegen_tests_schema",
38+
srcs = glob(
39+
[
40+
"**/e2e/__test_fixtures__/*NativeComponent.js",
41+
],
42+
),
43+
cmd = "$(exe fbsource//xplat/js/react-native-github/packages/react-native-codegen:write_to_json) $OUT $SRCS",
44+
out = "schema-codegen_tests.json",
10145
)
10246

103-
rn_codegen_test(
104-
fixture_name = "TWO_COMPONENTS_DIFFERENT_FILES",
47+
rn_codegen(
48+
name = "codegen_tests",
49+
schema_target = ":codegen_tests_schema",
10550
)
10651

10752
fb_xplat_cxx_binary(
@@ -120,21 +65,7 @@ fb_xplat_cxx_binary(
12065
],
12166
visibility = ["PUBLIC"],
12267
deps = [
123-
":generated_components-ARRAY_PROPS",
124-
":generated_components-BOOLEAN_PROP",
125-
":generated_components-COLOR_PROP",
126-
":generated_components-ENUM_PROP",
127-
":generated_components-EVENT_NESTED_OBJECT_PROPS",
128-
":generated_components-EVENT_PROPS",
129-
":generated_components-FLOAT_PROPS",
130-
":generated_components-IMAGE_PROP",
131-
":generated_components-INTEGER_PROPS",
132-
":generated_components-INTERFACE_ONLY",
133-
":generated_components-MULTI_NATIVE_PROP",
134-
":generated_components-POINT_PROP",
135-
":generated_components-STRING_PROP",
136-
":generated_components-TWO_COMPONENTS_DIFFERENT_FILES",
137-
":generated_components-TWO_COMPONENTS_SAME_FILE",
68+
":generated_components-codegen_tests",
13869
],
13970
)
14071

@@ -157,21 +88,7 @@ rn_xplat_cxx_library(
15788
"PUBLIC",
15889
],
15990
deps = [
160-
":generated_components-ARRAY_PROPS",
161-
":generated_components-BOOLEAN_PROP",
162-
":generated_components-COLOR_PROP",
163-
":generated_components-ENUM_PROP",
164-
":generated_components-EVENT_NESTED_OBJECT_PROPS",
165-
":generated_components-EVENT_PROPS",
166-
":generated_components-FLOAT_PROPS",
167-
":generated_components-IMAGE_PROP",
168-
":generated_components-INTEGER_PROPS",
169-
":generated_components-INTERFACE_ONLY",
170-
":generated_components-MULTI_NATIVE_PROP",
171-
":generated_components-POINT_PROP",
172-
":generated_components-STRING_PROP",
173-
":generated_components-TWO_COMPONENTS_DIFFERENT_FILES",
174-
":generated_components-TWO_COMPONENTS_SAME_FILE",
91+
":generated_components-codegen_tests",
17592
],
17693
)
17794

packages/react-native-codegen/DEFS.bzl

-13
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,6 @@ load(
1414
"rn_xplat_cxx_library",
1515
)
1616

17-
def rn_codegen_test(
18-
fixture_name = ""):
19-
copy_schema_name = "copy_schema-{}".format(fixture_name)
20-
21-
fb_native.genrule(
22-
name = copy_schema_name,
23-
srcs = [],
24-
cmd = "$(exe fbsource//xplat/js/react-native-github/packages/react-native-codegen:copy_fixture_schema) {} $OUT".format(fixture_name),
25-
out = "schema-{}.json".format(fixture_name),
26-
)
27-
28-
rn_codegen(fixture_name, ":{}".format(copy_schema_name))
29-
3017
def rn_codegen(
3118
name = "",
3219
schema_target = ""):

packages/react-native-codegen/buck_tests/copy-fixture.js

-33
This file was deleted.

packages/react-native-codegen/buck_tests/copy_fixture.sh

-11
This file was deleted.

packages/react-native-codegen/buck_tests/emptyFile.cpp

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
#import <react/components/ARRAY_PROPS/ComponentDescriptors.h>
2-
#import <react/components/INTERFACE_ONLY/ComponentDescriptors.h>
3-
#import <react/components/BOOLEAN_PROP/ComponentDescriptors.h>
4-
#import <react/components/STRING_PROP/ComponentDescriptors.h>
5-
#import <react/components/INTEGER_PROPS/ComponentDescriptors.h>
6-
#import <react/components/FLOAT_PROPS/ComponentDescriptors.h>
7-
#import <react/components/COLOR_PROP/ComponentDescriptors.h>
8-
#import <react/components/IMAGE_PROP/ComponentDescriptors.h>
9-
#import <react/components/POINT_PROP/ComponentDescriptors.h>
10-
#import <react/components/MULTI_NATIVE_PROP/ComponentDescriptors.h>
11-
#import <react/components/ENUM_PROP/ComponentDescriptors.h>
12-
#import <react/components/EVENT_NESTED_OBJECT_PROPS/ComponentDescriptors.h>
13-
#import <react/components/EVENT_PROPS/ComponentDescriptors.h>
14-
#import <react/components/TWO_COMPONENTS_SAME_FILE/ComponentDescriptors.h>
15-
#import <react/components/TWO_COMPONENTS_DIFFERENT_FILES/ComponentDescriptors.h>
1+
#import <react/components/codegen_tests/ComponentDescriptors.h>
2+
3+
// TODO: Import every prop and event to asset they're generated
164

175
int main(){
186
return 0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
'use strict';
12+
13+
import type {
14+
PointValue,
15+
ColorValue,
16+
} from '../../../../Libraries/StyleSheet/StyleSheetTypes';
17+
import type {ImageSource} from '../../../../Libraries/Image/ImageSource';
18+
import type {
19+
Int32,
20+
Float,
21+
WithDefault,
22+
} from '../../../../Libraries/Types/CodegenTypes';
23+
import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
24+
import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent';
25+
26+
type NativeProps = $ReadOnly<{|
27+
...ViewProps,
28+
29+
// Props
30+
names?: $ReadOnlyArray<string>,
31+
disableds?: $ReadOnlyArray<boolean>,
32+
progress?: $ReadOnlyArray<Int32>,
33+
radii?: $ReadOnlyArray<Float>,
34+
colors?: $ReadOnlyArray<ColorValue>,
35+
srcs?: $ReadOnlyArray<ImageSource>,
36+
points?: $ReadOnlyArray<PointValue>,
37+
sizes?: WithDefault<$ReadOnlyArray<'small' | 'large'>, 'small'>,
38+
|}>;
39+
40+
export default codegenNativeComponent<NativeProps>('ArrayPropsNativeComponent');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
'use strict';
12+
13+
import type {WithDefault} from '../../../../Libraries/Types/CodegenTypes';
14+
import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
15+
import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent';
16+
17+
type NativeProps = $ReadOnly<{|
18+
...ViewProps,
19+
20+
// Props
21+
disabled?: WithDefault<boolean, false>,
22+
|}>;
23+
24+
export default codegenNativeComponent<NativeProps>(
25+
'BooleanPropNativeComponent',
26+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
'use strict';
12+
13+
import type {ColorValue} from '../../../../Libraries/StyleSheet/StyleSheetTypes';
14+
import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
15+
import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent';
16+
17+
type NativeProps = $ReadOnly<{|
18+
...ViewProps,
19+
20+
// Props
21+
tintColor?: ColorValue,
22+
|}>;
23+
24+
export default codegenNativeComponent<NativeProps>('ColorPropNativeComponent');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
'use strict';
12+
13+
import type {WithDefault} from '../../../../Libraries/Types/CodegenTypes';
14+
import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
15+
import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent';
16+
17+
type NativeProps = $ReadOnly<{|
18+
...ViewProps,
19+
20+
// Props
21+
alignment?: WithDefault<'top' | 'center' | 'bottom-right', 'center'>,
22+
|}>;
23+
24+
export default codegenNativeComponent<NativeProps>('EnumPropNativeComponent');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
'use strict';
12+
13+
import type {
14+
Int32,
15+
BubblingEvent,
16+
WithDefault,
17+
} from '../../../../Libraries/Types/CodegenTypes';
18+
import type {ViewProps} from '../../../../Libraries/Components/View/ViewPropTypes';
19+
import codegenNativeComponent from '../../../../Libraries/Utilities/codegenNativeComponent';
20+
21+
type OnChangeEvent = $ReadOnly<{|
22+
location: {
23+
source: {
24+
url: string,
25+
},
26+
x: Int32,
27+
y: Int32,
28+
},
29+
|}>;
30+
31+
type NativeProps = $ReadOnly<{|
32+
...ViewProps,
33+
34+
// Props
35+
disabled?: WithDefault<boolean, false>,
36+
37+
// Events
38+
onChange?: ?(event: BubblingEvent<OnChangeEvent>) => void,
39+
|}>;
40+
41+
export default codegenNativeComponent<NativeProps>(
42+
'EventNestedObjectPropsNativeComponent',
43+
);

0 commit comments

Comments
 (0)