Commit Graph

389 Commits

Author SHA1 Message Date
Charles Dudley c532fcff90 Copy Flow parser components logic to prepare TypeScript parser
Summary:
These files are directly copied from the flow parser to aid in reviewing the next Diff, D33080623

Changelog:
[Internal][Add] - Copy Flow parser component logic to aid in Diff review

Reviewed By: RSNara

Differential Revision: D33130222

fbshipit-source-id: ba7233b17d698793559da8b81bb7e1a78654e614
2021-12-20 14:20:21 -08:00
Charles Dudley 114d5a8a17 TypeScript parser foundation
Summary:
These are utility functions that the TypeScript parser uses and are copied from and follows the same logic as the flow parser with some TypeScript specific changes.  Also added dependency of `babel/parser` as the parsing engine we're using for TypeScript.

Changelog:
[General][Add] - Add foundation for WIP TypeScript parser for Codegen

Reviewed By: RSNara

Differential Revision: D33080527

fbshipit-source-id: d4bd515af549a41f07a2e3ee1a16b5ed678180b2
2021-12-20 14:20:21 -08:00
Charles Dudley 165dfbcc87 Copy Flow parser foundation for TypeScript parser
Summary:
This is a direct copy of the following files from the flow parser:

```
react-native-codegen/src/parsers/flow/errors.js
react-native-codegen/src/parsers/flow/utils.js
```

Changelog:
[Internal][Added] - Copy flow parser foundation files to aid in diff review

Reviewed By: RSNara

Differential Revision: D33137685

fbshipit-source-id: 1345c8bb0785c90b2bd64d4e6e2447f3fdb0ae6b
2021-12-20 14:20:21 -08:00
Ubax 3e6902244a fix: Removes interface only check from third party components GenerateThirdPartyFabricComponentsProvider (#32779)
Summary:
Currently the codegen does not include component with field `interfaceOnly` set to `true` in the `ThirdPartyFabricComponentsProvider`.

These components need to be added to this file, so that non-core components can be used in fabric.

## Changelog

[General [Fixed] - Fixes GenerateThirdPartyFabricComponentsProvider

Pull Request resolved: https://github.com/facebook/react-native/pull/32779

Test Plan:
Run codegen with component outside of core on iOS.

Check if components with and without `interfaceOnly` are added to `RCTThirdPartyFabricComponentsProvider`

Reviewed By: cortinico

Differential Revision: D33235363

Pulled By: ShikaSD

fbshipit-source-id: e7224d2123e4da0da912fe677dae32d3aaea2ec8
2021-12-20 11:45:44 -08:00
Charles Dudley 3a01dc41e6 Flow parser cleanup
Summary:
This diff stack enables codegen to parse TypeScript spec files and generate an identical schema to our current Flow parser.

This first diff is a small cleanup of our current flow parser.

Changelog:
[General][Fixed] - Fix typo in error string and improve consistency in Codegen's flow parser tests

Reviewed By: sota000

Differential Revision: D33080423

fbshipit-source-id: 7bf817761a7704d807a0b809c9f2270354b5c6fa
2021-12-15 15:59:38 -08:00
Alex Koller 2e3bcdfda5 Update prop generator to allow value prop name
Summary:
So I was adding a new HTTPCookie prop to our WebView native component and found that my build was [failing](https://www.internalfb.com/diff/D32602297?dst_version_fbid=338931330931416) due to "redefinition of `value`". Looks like we use the name of the prop as a variable name during codegen, and this can conflict with some other hardcoded variable names. Rather than try and come up with a better prop name, I figured we can just append some string to our codegen name to reduce the chance for conflicts.

Changelog:
[Internal][Changed] - Change codegen variable naming to prevent conflicts to prop names

Reviewed By: JoshuaGross

Differential Revision: D32967807

fbshipit-source-id: 1b3631ec783b229eddfd3c801ffbb397910fc882
2021-12-09 12:02:29 -08:00
Nicola Corti 28aeb7b865 Do not .lowerCase the library name when codegenerating TurboModule Specs
Summary:
The Codegen is generating a broken output if using the default library name: `Packages<GradleModuleName>Spec`.
This diff is fixing the codegenerator to don't call the `.lowerCase` on the library name when generating the Makefile.

Changelog:
[Android] [Fixed] - Do not .lowerCase the library name when codegenerating TurboModule Specs

Reviewed By: ShikaSD

Differential Revision: D32597578

fbshipit-source-id: dee729a44134d7b3878074507191bb2a1c200608
2021-11-24 11:57:52 -08:00
Ramanpreet Nara 6b1ccef71f Update FabricComponentsProvider to use template functions
Summary:
## Rationale
- Consistency with our other generators.
- Past effort, with rationale: D32021441 (https://github.com/facebook/react-native/commit/3848f48943d0530c3712394b9e405ebddf21cf3b)

Changelog: [Internal]

Reviewed By: sota000

Differential Revision: D32546918

fbshipit-source-id: 5167ca5d7154c0e2fa0867521feaf6a6a382900e
2021-11-18 18:15:34 -08:00
Evan Yeung 037e346197 Add LTI annotations to xplat/js
Summary:
This diff runs the codemod to add type annotations to function parameters in preparation for Flow's local type inference (LTI) project. I ran the codemod over xplat/js and reverted any files that had flow errors in them. See the list of commands run to see the regeneration of various files.

Changelog:
[Internal][Changed] - Added type annotations

Reviewed By: yungsters

Differential Revision: D32075270

fbshipit-source-id: 6a9cd85aab120b4d9e690bac142a415525dbf298
2021-11-10 15:40:15 -08:00
Sota Ogo d065b06da1 Generate ThirdpartyFabricComponentsProvider to extend RCTFabricComponentsPlugins
Summary:
Currently, we don't have a way to extend RCTFabricComponentsPlugins in OSS. This diff  adds a codegen to generate ThirdpartyFabricComponentsProviderwhich will be used to extend RCTFabricComponentsPlugins.

It works almost exactly the same as RCTFabricComponentsPlugins, and in the future we might want to consider merging them together.

Changelog: [internal]

Reviewed By: hramos

Differential Revision: D32128760

fbshipit-source-id: b4f3a082f94c3053251cc6a0323c488f649deaa9
2021-11-10 10:09:59 -08:00
Tim Yung 10f9ab4d69 RN: Follow-up Format w/ Prettier v2.x
Summary:
When I upgraded React Native to Prettier v2.x, I removed `format` from a few files to reduce the number of changes.

This is a follow-up to bring back `format` and fix any remaining issues.

Changelog:
[Internal]

Reviewed By: zertosh

Differential Revision: D32287259

fbshipit-source-id: 37ea6d2c973b1db5d37c46d73675bdf436fb9a9d
2021-11-09 13:16:43 -08:00
Tim Yung fba1ae1643 RN: Temporarily Disable Prettier for Some Files
Summary:
We are in the middle of a Prettier upgrade and some of the files which disagree between Prettier v1.x and v2.x are now being flagged by `eslint-plugin-prettier` as lint errors.

The correct fix here is probably to update `eslint-config-prettier` and `eslint-plugin-prettier`, but I am landing this first to unbreak CI.

Reviewed By: mendoncakeegan

Differential Revision: D32129458

fbshipit-source-id: a5206a5ef58f1d7614f9459c99b9e39109be6de9
2021-11-02 23:09:38 -07:00
Tim Yung 77ecc7ede1 JS: Format with Prettier v2.4.1 [3/n]
Summary:
Changelog:
[General][Internal]

Reviewed By: zertosh

Differential Revision: D31883447

fbshipit-source-id: cbbf85e4bf935096d242336f41bf0cc5d6f92359
2021-11-02 22:14:16 -07:00
Ramanpreet Nara 27ddbd8137 Refactor: Simplify deprecated component code-gen logic in View Config generator
Summary:
**Motivation:** Readability. It was hard to tell how componentName, paperComponentName, and paperComponentNameDepreacted produced the NativeComponentRegistry.get call.

Changelog: [Internal]

Reviewed By: philIip

Differential Revision: D32108276

fbshipit-source-id: ea7c9fe4dc50cdd6fec94b5cd25f7bbcfb451ef6
2021-11-02 21:27:36 -07:00
Ramanpreet Nara 3848f48943 Use JavaScript functions for Component templates
Summary:
## Rationale
**Disclaimer**: This is an incremental step towards more maintainable/readable react-native-codegen generators. In the future, we may want to replace these templates/string concat logic with *something better*. But until we decide what that *something better* is, let's at least get rid of all this gross string find/replace.

Benefits of using Function templates over String.prototype.replace.
- **Self-documenting**: Template Functions enumerate/describe their exact data dependencies in their signature. You no longer have to read the template implementation to see what data you need to pass into the template.
- **Improved Readability**: JavaScript syntax highlighting makes it really easy to see where/how the data is inserted into the templates. Also template variables used be prefixed/suffixed with ::, which made things really confusing in C++ code (e.g: wtf is `::_CLASSNAME_::EventEmitter::::_EVENT_NAME_::`?).
- **Simpler Interpolation**: Don't have to worry about .replaceAll vs .replace, or calling these replace functions with regexes or strings.
- **Template Type-safety**: Ensure that the correct data types are passed to the component templates (e.g: flow will complain if you accidentally pass null/undefined when a template expects a string).
- **Template Type-safety**: Ensure that we don't pass in extra data to templates (this diff catches/fixes instances of this error). Ensure that we don't forget to pass in data to the template.
- etc.

After this diff, both our Component and NativeModule generators will be using template functions. This string find/replace exists no more in react-native-codegen.

This is also a very surface-level change. I made no efforts to simplify these templates. Let's take a look at that later, as necessary.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D32021441

fbshipit-source-id: f8f27069bcbf9d66dcafb7d1411da1f938eb6dcd
2021-11-01 09:00:24 -07:00
Ramanpreet Nara 58c9d8eda7 Fix "Duplicate license header lint error" in Component generators
Summary:
See title.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D32019151

fbshipit-source-id: aea69a6c032cef1c99cd7641bdc10e730076e781
2021-10-29 10:43:39 -07:00
Nicola Corti a9fc0c5a9c Re-add libreact_debug to codegen makefile and add prebuilts for them
Summary:
While working updating the codeden Makefile template for Android, I've removed
the `libreact_debug` and `libreact_render_debug` dependencies as they were unused in a
simple turbomodule. Turns out that `:ReactAndroid` is depending on having those dependencies.

Moving the build file to use AGP APIs, triggers this scenario and is making `ReactAndroid`
failing to build (see the build status for https://github.com/facebook/react-native/pull/32443).

I'm updating the codegen Makefile template to reintrodce the two libraries + I've update the prebuilt
makefile (used in the playbook) to include `react_debug` prebuilts as they were missing.

Changelog:
[Internal] [Changed] - Re-add libreact_debug to codegen makefile and add prebuilts for them

Reviewed By: ShikaSD

Differential Revision: D31900675

fbshipit-source-id: ff188c0498a0dca4a951a548a580ca8dd0674782
2021-10-27 09:20:35 -07:00
Tim Yung 9ac03361e6 RN: Add glob Flow Definition
Summary:
Adds the `glob` type definition via `flow-typed` so that the `combine-js-to-schema-cli.js` script does not need a Flow suppression.

Changelog:
[Internal]

Reviewed By: kacieb

Differential Revision: D31800809

fbshipit-source-id: 3e01a096d2153639a619a7152bd06332df57f06b
2021-10-20 19:25:45 -07:00
Nicola Corti c7d0c94bf9 Update codegen template to include correct native modules and C++17
Summary:
This diff updates the Makefile generated by `react-native-codegen`
to include the correct list of modules. Specifically I've removed some modules that are unused
like `libreact_debug` and added others that are necessary for the build to compile correctly
such as `libfbjni`.

Plus I've bumped the C++ version to 17 as we had a mixture of 14 and 17 across the codebase.

Changelog:
[Internal] [Changed] - Update codegen template to include correct native modules and C++17

Reviewed By: mdvacca

Differential Revision: D31754427

fbshipit-source-id: 8490fa5c5ad298689b564f760c3fc65550c94547
2021-10-20 10:19:10 -07:00
Sota Ogo 8fcc2fa31a Update the path to use the full path so that they can be found in the OSS environment.
Summary:
I had to make this change when enabling Fabric in OSS. Without the full path, it can't find the modules like processColor within node_modules.

Changelog: Internal

Reviewed By: motiz88

Differential Revision: D31300424

fbshipit-source-id: 59b82470ec1ce63b63704931786e22b98f4bf046
2021-10-19 18:35:13 -07:00
Moti Zilberman 268efb1022 Use deep require instead of Haste for NativeComponentRegistry
Summary:
Changelog: [Internal]

Some environments that use codegen don't have Haste enabled, breaking the `require('NativeComponentRegistry')` call in generated view configs. Here we change it to reference an explicit path relative to `react-native`.

Reviewed By: JoshuaGross

Differential Revision: D31166063

fbshipit-source-id: cebc23d0d95b5cde76d0f8473eabc03ca82a862e
2021-09-27 13:47:28 -07:00
Sota Ogo 286df9000e Throw when extendsProps is empty
Summary:
If I understand the code correctly, component.extendsProps is expected to have more than 1 entry. I encounter a bug where it was an empty and produced an broken Props.h file while testing out in OSS.

```
// Example of the broken file.
class RNTMyNativeViewProps final :  {
 public:
```
In this diff, it makes it clear that the function has failed so that the codegen fails when the input is wrong.

There is probably an upstream problem that we should warn about, but this diff is just to make sure this method fails loudly.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D30847173

fbshipit-source-id: 34c894f0a7bb81e132b6ed44f51d0f92ed9a5a20
2021-09-14 11:47:38 -07:00
Sota Ogo 2a0293906f Add an error message when there is no modules to process in codegen
Summary:
Adding an error message when codegen doesn't recognize any modules to help users understand what's going on.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D30624535

fbshipit-source-id: 781f1f874a5b0c16a05191186b81c2d3892da95b
2021-09-09 17:26:19 -07:00
Neil Dhar 1bc885b8b8 Make JSI a dynamic library
Summary:
Ship libjsi as a standalone dynamic library. This prevents problems
with exception handling caused by duplicate typeinfo across multiple
shared libs, and reduces bundle size by removing duplicate copies of
JSI.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D30599215

fbshipit-source-id: abad1398342a5328daa825f3f684e0067cad7a96
2021-08-27 17:16:49 -07:00
Joshua Gross 175b1ea636 Pass PropsParserContext to prop parsing layer
Summary: Changelog: [internal]

Reviewed By: mdvacca

Differential Revision: D29921232

fbshipit-source-id: ba045f545b564aedf1b287045a0e75428de30a0f
2021-07-28 20:18:20 -07:00
Joshua Gross 5d33e65694 Pass context through to all prop parser (props structs changes)
Summary:
See previous diffs for context. This updates all of the relevant props structs.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D29855426

fbshipit-source-id: 30177c3380ef82ecf8f2a4321f128cfbe8a576e0
2021-07-28 20:18:20 -07:00
Andrei Shikov 01c3bcdab0 Support string type for commands
Summary:
String type seems to be already supported by codegen, but it was not included in the list for command methods.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D29306740

fbshipit-source-id: 44b267c09f471dc601759ed2f7211a9e0fc1bb90
2021-06-22 15:31:47 -07:00
Daniel Sainati 974f0a3281 pre-suppress this typing errors ahead of 154
Summary:
This pre-suppresses the 154 error diff ahead of its release, since it is large.

Changelog: [Internal]

Reviewed By: samwgoldman

Differential Revision: D29065246

fbshipit-source-id: f418041305a46df410dcbe3d9a4db81a61ac7014
2021-06-11 14:31:41 -07:00
Daniel Sainati 74d5d03dbd pre-suppress Flow errors in xplat ahead of 153 release
Summary:
This pre-suppresses the 153 error diff ahead of its release, since it is large.

Changelog: [Internal]

Reviewed By: mroch

Differential Revision: D28754374

fbshipit-source-id: 1806f53bc7d804644d434583a2dcd6da63d00328
2021-06-01 09:01:26 -07:00
Erich Graham fa4045e4dd Add ios_assume_nonnull flag to react native codegen library (#31543)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/31543

Changelog:
[iOS][Added] - Description

When compiling iOS apps with flag `-Wnullability-completeness` (like Lightspeed app and soon Instagram), Objective-C headers are required to either have full *explicit* nullability annotations on all members of its public API, or none at all; partially annotated headers will fail to build that module.

RN native modules are currently generated with *partial* annotations.  This works today because most apps are not compiled with `-Wnullability-completeness` turned on. But when we flip the switch for Instagram, the app doesn't build due to importing these RN partially annotated modules.

JavsScript Flow types are implied nonnull, and the current RN codegen translates Flow's [maybe/optional](https://flow.org/en/docs/types/maybe/) type to Obj-C `_Nullable` annotation, and everything else without an explicit Obj-C annotation. However this creates a mismatch with the Obj-C type system, where the implied default is *unannotated*, which is handled differently from nonnull when built with the nullability compiler flags.

There is a simple Obj-C macro that automatically adds *explicit nonnull* annotations to all members in a header: `NS_ASSUME_NONNULL_BEGIN` / `NS_ASSUME_NONNULL_END`. If we add this to *all* RN-generated headers, however, we run into issues:
1) We may erroneously assume any previously-unannotated header was meant to be nonnull and cause future bugs
2) Another compiler flag (`-Wnullable-to-nonnull-conversion`) statically analyzes Obj-C implementation code to prevent us from ever passing null to one of these headers. Much existing Obj-C code will break here, and it's ambiguous if these are true or false positives because of the first point.

Instead, in this diff we add a new BUCK flag `ios_assume_nonnull` to let module authors opt into automatic nonnull for unannotated members so that Obj-C headers are generated correctly in alignment with Flow's type system. We can migrate all libraries individually as needed and eventually make this the RN native codegen default.

Reviewed By: RSNara

Differential Revision: D28396446

fbshipit-source-id: ad3a3a97ab19183df4ef504b1c3140596c8f69ca
2021-05-20 10:07:37 -07:00
Luna Wei bac2c2c801 Update FlowFixMes to use error codes in react-native-github
Summary:
Changelog:
[Internal] - Add error codes to existing FlowFixMe's

Reviewed By: kacieb

Differential Revision: D27445689

fbshipit-source-id: 2b19692e1cb822ab6785efcc5f93ee33e7dce1e5
2021-03-31 18:21:47 -07:00
Ramanpreet Nara 74682c54f9 Add @DoNotStrip to every Pojo and every Pojo method
Summary:
This should ensure that nothing is stripped at compile-time.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26094738

fbshipit-source-id: 8dd62c289deafdcceb3de4b09c12132aaceafa94
2021-03-22 18:23:28 -07:00
Andrei Shikov ac704690dc Update Android.mk to ensure the rn-tester compiles in debug mode
Summary:
Changelog: [Internal]

Adds react_debug dependency in Android.mk where it was missing

Reviewed By: mdvacca

Differential Revision: D26617400

fbshipit-source-id: 5ac799269b106eadd881d30490ac34bd2134a9b7
2021-02-24 12:29:00 -08:00
Igor Klemenski c37d49492b Work around max path length during source build of RN Android (#30776)
Summary:
Building ReactAndroid from source on Windows has recently hit the limitation of maximum path lengths.
At build time, during the `:ReactAndroid:buildReactNdkLib` task, the linker tries to access several of the intermediate binaries located deep in the tmp folder hierarchy, eg.
```
D:\r\ReactAndroid\build\tmp\buildReactNdkLib/local/armeabi-v7a/objs/react_render_components_progressbar/D_/r/ReactAndroid/__/ReactCommon/react/renderer/components/progressbar/android/react/renderer/components/progressbar/AndroidProgressBarMeasurementsManager.o
```
**Suggested fix:** for modules such as `react_render_components_progressbar` and `react_render_components_picker`, rename them to `rrc_progressbar` etc.

**NOTE**: this assumes that the fix from https://github.com/facebook/react-native/issues/30535 is in place. This regression happened while https://github.com/facebook/react-native/issues/30535 has been pending checkin.

**Other mitigations I've tried:**
- setting [`LOCAL_SHORT_COMMANDS`](https://developer.android.com/ndk/guides/android_mk#local_short_commands) for the problematic modules or `APP_SHORT_COMMANDS` for the root project. Turns out those commands don't work on the NDK version RN requires, but even after manually applying a [patch ](https://android-review.googlesource.com/c/platform/ndk/+/1126440) to my local copy of the NDK, these flags had no effect.
- moving the repo directory higher in the file system tree, and using short directory names `D:\r\...` was not enough
- creating virtual drive letters for specific long paths with the [`sust`](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/subst#examples) command is not workable, since they depend on the source folder structure, and get partly generated by the build system, which I can't plug into
- just enabling long path support on Windows is not enough, since the compiler toolchain doesn't support them.
## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Fixed] - Fix source build on Windows machines vol. 2

Pull Request resolved: https://github.com/facebook/react-native/pull/30776

Test Plan:
Run `.\gradlew installArchives`

Before:
![image](https://user-images.githubusercontent.com/12816515/105435667-a1e15d00-5c12-11eb-9fcd-d0c278aaf477.png)
Now:
![image](https://user-images.githubusercontent.com/12816515/105435741-c2a9b280-5c12-11eb-88d5-a69ae56bbf50.png)

Differential Revision: D26194286

Pulled By: mdvacca

fbshipit-source-id: 778b5a0515148e2ace19e7902f74301831ebed94
2021-02-11 12:32:33 -08:00
Ramanpreet Nara cba6aba2e6 Add @DoNotStrip annotation to getConstants()
Summary:
NativeModule getConstants() methods on Java might not be used within Java. So, they can be stripped by proguard. This diff adds the DoNotStrip annotation to the getConstants() method.

Changelog: [Internal]

Reviewed By: keoskate

Differential Revision: D26265874

fbshipit-source-id: b405ee32406e829212e5c9641750a6b5795899c3
2021-02-05 11:48:30 -08:00
Ramanpreet Nara e08681cf79 Add @DoNotStrip annotations to root Pojos
Summary:
To ensure these Pojos don't get dead code eliminated, this diff adds a DoNotStrip annotation to each Props pojo object.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26041103

fbshipit-source-id: 02031f39f5fc5ef1bb9f11b729e68437bfe95452
2021-01-26 17:07:01 -08:00
Ramanpreet Nara 19ef415895 Distinguish root Pojos from non-root Pojos
Summary:
The Pojo data structure now keeps a flag `isRoot`, so that we can customize code-generation for the Props pojo vs its helper pojos.

In the following diff (i.e: D26041103), we'll add a DoNotStrip annotation to the props pojo. That doesn't need to exist on the helper pojos, because they'll all be referenced in the root props pojo.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26041102

fbshipit-source-id: ae2e1ba346d038853b5ff30cd5524a809ef97053
2021-01-26 17:07:00 -08:00
Ramanpreet Nara 6506f7a680 Remove @Nullable annotation from ArrayList element types
Summary: Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26051159

fbshipit-source-id: 54315dc505a4fb4e595847902caf501b4ecd77e2
2021-01-26 17:07:00 -08:00
Ramanpreet Nara 8461409e88 Generate pojo for Component Props
Summary:
## What This Does
- **Phase 1:** Given a component, convert its props (and all its ObjectTypeAnnotations) into this Pojo data structure under some namespace. This is a recursive operation.
- **Phase 2:** Loop over each Pojo data structure, and serialize it to Java class.

So...
- Each Component has its own namespace (i.e: its hasteModuleName) for Java Pojo objects.
- Each Component generates 1 Pojo object, for its props.
- Each Component generates 1 Pojo object for every ObjectTypeAnnotation in its props.

## Decisions
By design, [JNI can read/write to private properties on Java objects](https://stackoverflow.com/a/12208643). So, each Pojo, which represents an ObjectTypeAnnotation, contains only a private member variable for each of its properties, and a getter to retrieve the data from each of its private members.

## Todos
- Improved type-safety:
   - ReservedTypeAnnotation (e.g: PointPrimitive). These currently map to ReadableMap.
   - String enums, and Int enums don't actually generate Java enums.
- Verify if there are any compilation issues by wiring this up to the Codegen buck infra.
- To actually use the Pojos, we'll need C++/Jni codegen to transform C++ props into these Pojos. Building this out will give a more accurate assessment of the app-size cost of Pojos. However, we can do that if we deem that the app-size increase from adding just the Pojo classes is negligible enough to **not** rule out this entire approach.
- ~~Add some annotations to prevent these Pojo classes from being stripped at compile-time.~~ D26041103

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26038189

fbshipit-source-id: c137c4ca6b043ee76adb354105aff6e0f270df86
2021-01-26 17:07:00 -08:00
Ramanpreet Nara 8053385a12 Fix Boolean to JNI type
Summary:
We were missing a semicolon.

Changelog: [Internal]

Reviewed By: JoshuaGross, shergin

Differential Revision: D26087583

fbshipit-source-id: 8ec74cf1cba40899fba063e6c93a8d6002c3422d
2021-01-26 16:50:39 -08:00
Andrei Shikov 9f7bd62f6c Back out "Add codegen debug logging to check CI issues"
Summary: Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D25995374

fbshipit-source-id: 2b08c7023e19db74f741401b3aed8ad5eb0e23e7
2021-01-25 15:22:02 -08:00
Ramanpreet Nara 3dab9a0d01 Make parser return empty schema when parsing non-spec files
Summary:
Right now, running the codegen parser on regular JavaScript files causes it to throw an error:

https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/js/react-native-github/packages/react-native-codegen/src/parsers/flow/index.js?commit=1e93f27aac8890f1731650fdcc38b702ae8874e2&lines=59-63%2C106-107

This makes the parser less usable, because you can't simply loop over a list of JavaScript files, and run codegen on them. You need to do some filtering beforehand, or surround each invocation of the parser with a try/catch.

Our codegen schema supports the idea of an empty schema:

```
{
  modules: {}
}
```

To improve the parser's ergonomics, this diff migrates the codegen parser over to returning the empty schema when it cannot detect a Component or NativeModule spec inside a JavaScript file.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D26034052

fbshipit-source-id: c2f15aba9c0e052012396eaed2034537f5918e33
2021-01-23 02:02:57 -08:00
Ramanpreet Nara fc0b3faf96 Fix ObjC structs with id properties
Summary:
## Problem
Suppose we have this NativeModule spec, that uses Object literals that contain a property called "id":

```
export interface Spec extends TurboModule {
  // Exported methods.
  +getConstants: () => {|
    id: string,
  |};

  +getObject: (arg: {id: Object}) => Object;
}
```

For both object literals, we'll generate C++ structs, backed by NSDictionaries. The method in each struct will be named "id_" to avoid a name clash with ObjC's `id` identifier. However, calling that id_ method should still access the "id" property in the corresponding NSDictionary.

## Expected Output
```
inline id<NSObject> JS::NativeSampleTurboModule::SpecGetObjectArg::id_() const
{
  id const p = _v[@"id"];
  return p;
}
inline JS::NativeSampleTurboModule::Constants::Builder::Builder(const Input i) : _factory(^{
  NSMutableDictionary *d = [NSMutableDictionary new];
  auto id_ = i.id_.get();
  d[@"id"] = id_;
  return d;
}) {}
```

## Actual Output
```
inline id<NSObject> JS::NativeSampleTurboModule::SpecGetObjectArg::id_() const
{
  id const p = _v[@"id_"]; // <-- HERE!
  return p;
}
inline JS::NativeSampleTurboModule::Constants::Builder::Builder(const Input i) : _factory(^{
  NSMutableDictionary *d = [NSMutableDictionary new];
  auto id_ = i.id_.get();
  d[@"id_"] = id_; // <-- HERE!
  return d;
}) {}
```

NOTE: This code was generated by running `jf get --version 119805822 && buck build //xplat/js:FBReactNativeSpec_Sample-flow-types-ios --show-output`

This diff fixes this mistake.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D25907493

fbshipit-source-id: cb37cbf49db4f871b3f4046f7397a7b1b7df0357
2021-01-13 19:19:30 -08:00
Andrei Shikov b1474f56cb Add codegen debug logging to check CI issues
Summary: Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D25874281

fbshipit-source-id: 9cb70c98849ab3eaa0318c88d51210fe9de8bdf5
2021-01-11 16:05:29 -08:00
Samuel Susla 0c5d59cffa Fix codegen boolean return value
Summary:
Changelog: [internal]

Codegen was generating code with return value number instead of boolean.

Reviewed By: RSNara

Differential Revision: D25863062

fbshipit-source-id: 780f88dd2d83e303b03d1ed9cc837ac6733f1702
2021-01-10 09:54:25 -08:00
Ramanpreet Nara 9215980471 Remove moduleSpecName
Summary:
All our codegen JavaScript now simply uses libraryName instead of moduleSpecName. In our buck infra, we assign native_module_spec_name to libraryName.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D25842696

fbshipit-source-id: efd3af402585f9ad4ff3b593179147eea91cc331
2021-01-07 19:39:56 -08:00
Rubén Norte e088a4fe9c Add support for UnsafeObject to allow using Flow strict in native modules
Summary:
This new type will be valid in Flow strict mode and can be used by native modules and components to replace `Object`, with the same semantics.

This unblocks the migration of the most modules in the React Native package to Flow strict.

Changelog: [Internal] Add UnsafeObject type compatible with Flow strict mode to use in native modules and components

Reviewed By: RSNara

Differential Revision: D25540631

fbshipit-source-id: 60b80bbc84a53aecc747e3a1799cdf551e1859cd
2021-01-04 03:56:57 -08:00
Ramanpreet Nara 4c734d1e8d Support custom android_package_name in module codegen
Summary:
## Changes
All `rn_library(codegen_modules = True)` must now also specify native_module_android_package_name, like so:

```
rn_library(
  name = "FBAuth"
  codegen_modules = True,
  native_module_spec_name = "Foo",
  native_module_android_package_name = "com.facebook.fbreact.specs",
)
```

This will generate the FBAuth Java spec files under the appropriate directory: "com/facebook/fbreact/specs". It will also make the code-generated specs have the appropriate package name: "com.facebook.fbreact.specs".

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D25723176

fbshipit-source-id: 6efec1cbee43d70110c0ef23e2422e08609b61d4
2020-12-29 13:04:36 -08:00
Ramanpreet Nara 6740b22ab0 Add @DoNotStrip to exported methods in NativeModule specs
Summary:
NativeModule methods are meant to be called from JavaScript. As such, they may not necessarily have call-sites in Java. This means that they're succeptible to being stripped by proguard.

This diff annotates all exported NativeModule methods with DoNotStrip, so that proguard doesn't strip them. We already do this in the legacy codegen.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D25723801

fbshipit-source-id: a7c8701e0a5d03a970f5f19cc6ae6b320a2e99a1
2020-12-29 13:04:36 -08:00
Ramanpreet Nara a68415270c Delete codegen_rn_modules_tests
Summary:
This test was used to compare the old codegen output with the new codegen output. It was written predominately to test the ObjC++ generator. A few reasons why we should delete this:
1. We do not want the old and the new codegen targets co-existing because it will slow down buck query.
2. The new ObjC++ codegen output is different from the old. In the new ObjC++ generator, we aren't generating dead structs. Therefore, this test simply won't work on the most sophisticated generator (i.e: the generator it was designed to run on). The other generators are really simple. We've also been running the ObjC++ and the Java generators in production for over a month for react-native-github specs. These are arguably the most complicated specs we maintain, so generator correctness isn't too much of a concern.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D25683069

fbshipit-source-id: b2175f34f50a078d80ef738e59024f546628219a
2020-12-24 00:50:01 -08:00