Commit Graph

328 Commits

Author SHA1 Message Date
Ramanpreet Nara aba4e87873 Add unit tests to validate module parser
Summary:
## Test Structure
- Parameter Parsing
  - For type in [optional, nullable, optional and nullable, required]:
    - Can parse Primitives
    - Can parse Object
    - Can parse Arrays
      - Can parse primitive element types
      - Can parse Object element types
      - Can parse Array element types
      - Can parse Reserved Type element types
      - Can parse Type alias element types
      - Can parse Object Literals
    - Can parse Function
    - Can parse Reserved Types (e.g: RootTag)
    - Can parse Type alias
    - Can parse Object Literals
      - For prop type in [optional, nullable, optional and nullable, required]:
        - Can parse primitive prop types
        - Can parse Object prop types
        - Can parse Array prop types
        - Can parse Reserved Type prop types
        - Can parse Type alias prop types
        - Can parse Object Literal prop types
- Return Parsing
  - For type in [nullable, required]:
    - Can parse Promises
    - Can parse Primitives
    - Can parse Object
    - Can parse Arrays
      - Can parse primitive element types
      - Can parse Object element types
      - Can parse Array element types
      - Can parse Reserved Type element types
      - Can parse Type alias element types
      - Can parse Object Literals
    - Can parse Function
    - Can parse Reserved Types (e.g: RootTag)
    - Can parse Type aliases
    - Can parse Object Literals
      - For prop type in [optional, nullable, optional and nullable, required]:
        - Can parse primitive prop types
        - Can parse Object prop types
        - Can parse Array prop types
        - Can parse Reserved Type prop types
        - Can parse Type alias prop types
        - Can parse Object Literal prop types

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D23089925

fbshipit-source-id: 73c3b1ef33b402265c14f0ac9e364414a5d54dca
2020-09-29 14:39:38 -07:00
Ramanpreet Nara 2d19037041 Rewrite Flow module parser
Summary:
This diff:
1. Simplifies the NativeModule schema Flow types.
2. Simplifies the NativeModule Flow parser, to accomodate the modified schema, and to reduce code duplication.

**Notes:**
- If the parser detects an unrecognized type within the context of parsing an Array's element type, it'll omit the `elementType` property of the `ArrayTypeAnnotation`. Details: T72031674. **Rationale:** Basically, when an array element type is supported, we use it in our generators. When it's unsupported, we ignore it. In the unsupported case, there's no point in trying to parse the Array element type, which is why I decided to omit the `elementType` property. Ideally, our NativeModule specs would never use unsupported types, in any context. This would allow us to always parse and use the elementType. However, that seems like a it could be a hefty migration: we have > 400 specs. Since, this isn't a battle we need to fight right now, I left a TODO at the relevant lines instead.
- The legacy codegen would generate structs for each object literal type in the file. In this re-implementation of the parser, I only insert into the aliases array when we detect a usage of a type-alias to an ObjectLiteral type annotation. With this decision, we won't be able to generate these unnecessary structs. This is good because we get rid of dead code. It's bad because it might make our migration to this codegen bit more difficult.

[WARNING] This diff produces flow failures that will be addressed in subsequent diffs.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D23201387

fbshipit-source-id: 55ce0df925a8bae0e7d5bb2a9b63167607eba461
2020-09-29 14:39:38 -07:00
Ramanpreet Nara f9ea52574e Cleanup buildMethodSchema and introduce nullable methods
Summary:
## Changes
- Started doing cleanup under `/parsers/flow/modules/methods.js`
- Rename `NativeModuleMethodTypeShape` -> `NativeModulePropertyShape`
- Moved optional property from `FunctionTypeAnnotation` to the `NativeModulePropertyShape`
- Introduced a nullable property inside what was once `FunctionTypeAnnotation`.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D23146050

fbshipit-source-id: 2fe97bb9c0736242682133e4923131a54bbea54b
2020-09-29 14:39:38 -07:00
Ramanpreet Nara 747f493feb Colocate alias/method generation logic
Summary:
## Changes
- Generating the aliases was split over `parsers/flow/modules/index.js`, and `parsers/flow/modules/aliases.js`. I moved everything to the latter file.
- Generating methods was split over `parsers/flow/modules/index.js` and `parsers/flow/modules/methods.js`. I moved everything to the latter file.
- More type-safety

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D23143382

fbshipit-source-id: e11b76bee7917a7db37ae7f1af64da5f046c5d1e
2020-09-29 14:39:38 -07:00
Ramanpreet Nara 78057729ce Clean up parsers/flow/modules/index.js
Summary:
Changes:
- Adding type annotations, where possible
- Delete unnecessary functions

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23138227

fbshipit-source-id: b4b47492ddef49f496ed9fcb61ef1c000e3e8f18
2020-09-29 14:39:38 -07:00
Ramanpreet Nara 8c138baf4e Fix parser's buildSchema's return type
Summary:
`buildSchema` delegates to two other functions: `buildComponentSchema`, or `buildComponentSchema`. Both return have a return type of *required* `SchemaType`. Therefore, `buildSchema` can have a return type of `SchemaType`.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23135499

fbshipit-source-id: f13db17549c93b965f372d9b68d06efc2a40c6cc
2020-09-29 14:39:37 -07:00
Ramanpreet Nara 22d6e04da1 Clean up Module/Component detection logic in Flow parser
Summary:
Just broke down getConfigType into two separate functions: `isModule` and `isComponent`.
- Cleaned up `isComponent`, to check for the the AST node types.
- Re-implemented `isModule`
- Improved error messages.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23121896

fbshipit-source-id: 3df2b2e334c4cea8eabe2e73ecb9f1f1217e7be4
2020-09-29 14:39:37 -07:00
Ramanpreet Nara 1435d654d7 Restructure getTypes function
Summary:
There are two types of types we care about:
- Type aliases
- Interface Declarations

These types can be exported.

I think we should build the types dictionary from only those types. Everything else should be ignored.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D23120241

fbshipit-source-id: 9f023081d0f9c85b45407b180ae7c3e7391eb725
2020-09-29 14:39:37 -07:00
Ramanpreet Nara 5142e99437 Delete NativeModuleSchemaBuilderConfig type
Summary:
Unecessary, since `NativeModuleShape` is the exact same thing.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23119784

fbshipit-source-id: 8c4aded88a97a80aa977c13cc27e32fbe68150aa
2020-09-29 14:39:37 -07:00
Ramanpreet Nara 341e05ff62 Allow NativeModule method return types to use type aliases
Summary:
We already support type-aliases in our NativeModule method params. This diff extends the support to NativeModule method returns.

**Note:** I need to see if I need to update the generators to handle this case. Will do that in this diff, after working through other higher priority stuff.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D22828839

fbshipit-source-id: cf5c756d3cacf067df217cdb6212946320a2d4be
2020-09-29 14:39:37 -07:00
simek 29f5dc2ae0 chore: deduplicate lock, update packages repository fields (#30044)
Summary:
This small PR includes the following changes:
* deduplicate yarn lock file using [`yarn-deduplicate`](https://github.com/atlassian/yarn-deduplicate) package
  * deduplicate script has been added as `update-lock`, let me know if you would like also to see this in [`postinstall`](https://docs.npmjs.com/misc/scripts) (to automatically optimize lock on every dependency change)
* according to the [npm docs](https://docs.npmjs.com/files/package.json#repository):
  * main `package.json` repository field has been replaced with shorthand
  * monorepo packages repository field has been extended by `directory`

The main goal of introducing deduplication script was to optimize the dependencies footprint while developing and speed up the initial installation process. Running `yarn-deduplicate` also increase the security in some way, because it enforces usage only of the latest version of the package. You can read more about the benefits in the deduplicate script [repository](https://github.com/atlassian/yarn-deduplicate#duplicated-packages).

## 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
-->

[Internal] [Added] - add yarn lock deduplication script

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

Test Plan: `yarn install` was successful, this also should not affect yarn workspaces in any way.

Reviewed By: GijsWeterings

Differential Revision: D23959812

Pulled By: cpojer

fbshipit-source-id: e2455e3718378e1ce6206e79463d4083f8fe5d47
2020-09-28 22:41:50 -07:00
Kevin Gozali c3ab2a2541 RNTester Android: Add stub C++ for TurboModule provider (#30014)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/30014

This is the base setup to compile C++ as part of RNTester app. There is no dependencies on ReactAndroidNdk lib yet, just a bunch of ndkBuild setup in Gradle. Note: this is using Gradle's `nkdBuild` support instead of calling `ndk-build` manually like in ReactAndroid/build.gradle.

Reference: https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.ExternalNativeNdkBuildOptions.html

Note that `ANDROID_NDK` env var is honored to pick the right NDK version.

For now, this is gated behind `USE_CODEGEN` env variable.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D23887058

fbshipit-source-id: 7a962649461d15af46999a15b900464543e5b05c
2020-09-23 16:52:48 -07:00
Kevin Gozali 2b46fd065f Codegen Android: Compile ReactAndroid codegen C++ output
Summary:
Now that the react-native-codegen produces the Android.mk for the JNI C++ output, let's compile them into its own shared library, to be included in the ReactAndroid final deliverable: libreact_codegen_reactandroidspec.so. This is gated behind `USE_CODEGEN` env var.

Note: RNTester specific C++ spec files are not compiled here.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D23809081

fbshipit-source-id: 7a90f420a923d5d02654facac01ffe025c321e44
2020-09-21 11:09:12 -07:00
Kevin Gozali 8cca54a7a7 Codegen Android: adjust JNI output to compile from Gradle
Summary:
This adjusted the C++ output for Android codegen (NativeModule specs) so we can compile it with ndk-build in Gradle:
* Use `#include` instead of `#import` for header files
* Added `#pragma once`
* Removed direct include of `<fb/fbjni.h>` -- this is not necessary
* Added generated Android.mk file based on library name

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D23809082

fbshipit-source-id: 11ddfea7b48c8b2eb6efe885641ace4fc327d50d
2020-09-21 11:09:12 -07:00
Kevin Gozali 7c93f5b001 Move TurboModule Core from ReactCommon/turbomodule to ReactCommon/react/nativemodule
Summary:
This diff moves the code of TurboModule Core from ReactCommon/turbomodule to ReactCommon/react/nativemodule

For iOS: Pod spec name stays as "ReactCommon/turbomodule/..." for now, only the source/header location is affected. The target will be renamed/restructured closer to TurboModule rollout.

changelog: [internal] Internal

Reviewed By: RSNara

Differential Revision: D23362253

fbshipit-source-id: c2c8207578e50821c7573255d4319b9051b58a37
2020-09-19 00:42:30 -07:00
Kevin Gozali 22e3f020fd Codegen: create java dirs based on javaPackageName for .java spec files
Summary:
Move the directory creation logic to the CLI. This needs to be processed by RNCodegen.js eventually.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23618550

fbshipit-source-id: e7dc4f5fc37e5ad12b5c6ae8ea31fc9ef16d74b9
2020-09-11 01:14:17 -07:00
Kevin Gozali 0351c57e6a Codegen: Generate module C++ lookup function for JNI next to the spec classes
Summary:
The TurboModule system requires a lookup function to map the spec name (name used in JS) to the C++ TurboModule subclass. This is a pure C function. For now, generate one lookup function per set of modules found in the codegen schema.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23618281

fbshipit-source-id: 889e07bdd4f2e5e93c4d14e60225f5b0c6683917
2020-09-11 01:14:17 -07:00
Frieder Bluemle fb354cba05 Remove .gitattributes and normalize line endings (#29792)
Summary:
The nested `.gitattributes` file in `packages/react-native-codegen/android/` caused some confusion on Linux and macOS, causing Git to show `packages/react-native-codegen/android/gradlew.bat` as modified (CRLF removed, LF added).

Instead of relying on repo-local `.gitattributes` files to convert endings in the working directory, the files should be committed to source control with the correct line endings in the first place. There is no reason to convert LF endings in .sh and many other file to CRLF on Windows (maybe this was an issue a long time ago, but unless Notepad is used this won't be a problem for practically all modern editors).

Also fixed the line endings of `scripts/launchPackager.bat` which was incorrectly committed as LF.

## Changelog

[Internal] [Fixed] - Line endings and .gitattributes

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

Test Plan: Clone repo on Linux, macOS, and Windows, and make sure no modified files show up.

Reviewed By: fkgozali

Differential Revision: D23546135

Pulled By: mdvacca

fbshipit-source-id: 1572fcb959212f212b137066f1aa66f0bb6e86c3
2020-09-04 13:44:40 -07:00
Kevin Gozali 02fed06340 Codegen: Add JNI C++ generator for TurboModule subclasses
Summary:
This adds the C++ classes for Android, just like checked in here: https://github.com/facebook/react-native/tree/master/ReactAndroid/src/main/java/com/facebook/fbreact/specs/jni

The whitespace/formatting is slightly different but the functionality should be preserved.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23489368

fbshipit-source-id: 60c112a48b6de2d2eb19f7d1bcc894048334610f
2020-09-03 16:11:08 -07:00
Nat Mote fc2b1cac82 Deploy Flow v0.133.0
Summary: Changelog: [Internal]

Reviewed By: samwgoldman

Differential Revision: D23491703

fbshipit-source-id: 46b9b0db821e7acacb355a9e3e03fa716052ef85
2020-09-03 16:02:37 -07:00
Frieder Bluemle 3a8559b86c Use Gradle Wrapper 6.6 (-all variant) (#29793)
Summary:
`-all` is the **default** for projects generated by Android Studio, and it provides **additional sources** helpful for debugging. It's also much more likely to already exist on a developer's machine (which has built other Android projects), avoiding additional downloads and saving disk space.

`-all` has also been the variant used in `react-native` for all versions prior to 5bc67b658e.

Follow-up to https://github.com/facebook/react-native/issues/29613

## Changelog

[Android] [Changed] - Use Gradle Wrapper 6.6 (-all variant)

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

Test Plan: No test needed since versions are the same.

Reviewed By: fkgozali

Differential Revision: D23406546

Pulled By: mdvacca

fbshipit-source-id: b74dbbfc0317bccf1940b1e5062d866e50aed28a
2020-09-01 17:09:27 -07:00
Frieder Bluemle cf8368f204 Update Android Gradle plugin to 3.6.4 (#28170)
Summary:
Android Studio 3.6.3 is now available in the stable channel

https://androidstudio.googleblog.com/2020/04/android-studio-363-available.html

EDIT: Another patch update to `3.6.4` was released in July 2020:

> This minor update supports compatibility with new default settings and features for package visibility in Android 11.

Details: https://developer.android.com/studio/releases/gradle-plugin#3-6-0

## Changelog

[Android] [Changed] - Update Android Gradle plugin to 3.6.4

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

Test Plan: Build project

Reviewed By: mdvacca

Differential Revision: D23357163

Pulled By: fkgozali

fbshipit-source-id: 45f1bfc8a1b21e60c6da03e60e4fa3b1e30c221c
2020-08-27 16:28:28 -07:00
Frieder Bluemle 5bc67b658e Update Gradle Wrapper to 6.6 (#29613)
Summary:
Gradle Wrapper to 6.6

https://docs.gradle.org/6.6/release-notes.html

## Changelog

[Android] [Changed] - Update Gradle Wrapper to 6.6

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

Test Plan: Build project

Reviewed By: mdvacca

Differential Revision: D23197319

Pulled By: mdvacca

fbshipit-source-id: 97ac5a9799435e5d117fe72d924698a169a64efb
2020-08-26 16:37:20 -07:00
Kevin Gozali 8ce57ec1b5 Codegen: JavaGenerator [7] - produce complete NativeModule spec .java files
Summary:
This implements the full NativeModuleResolvedType for each NativeModule spec, producing .java spec files in the output directory. The output files are now compiled during build time for :ReactAndroid and :packages:rn-tester:android:app.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23312858

fbshipit-source-id: c521b9d6602677fd275891cf44329740c6bd7387
2020-08-25 10:38:14 -07:00
Kevin Gozali 92a3dff58a Codegen: ignore NativeUIManager.js when producing schema given a JavaScript directory
Summary:
When crawling a provided JS directory to find all .js files for NativeModules and native components, ignore `NativeUIManager.js` for now, because it will be replaced with the Fabric UIManager in the future. The existing NativeUIManagerSpec.java won't be produced by the codegen, but stays manually checked in just in case: https://github.com/facebook/react-native/blob/0199a0392c65fa72d9599262ba1b4f8e14c0fc04/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeUIManagerSpec.java

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23312859

fbshipit-source-id: 7d554fefa651732c13e478b8ec94566348ed3142
2020-08-25 10:38:14 -07:00
Kevin Gozali 8fc1646c75 Codegen: JavaGenerator [6] - resolve individual types into their generated code
Summary:
For each resolved type, define how to process its own type and whether it should produce generated code/file, minus the NativeModuleResolvedType (will be in the next commit).

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23307961

fbshipit-source-id: 87af09867aace7a5ff060a33a00b141048630eda
2020-08-25 10:38:14 -07:00
Kevin Gozali eda1f8da7b Codegen: JavaGenerator [5] - Introduced ResolvedType structure that knows how to generate code for itself
Summary:
This is the base setup for ResolvedType. Each Type needs to be resolved to its final representation, which knows what Java type it needs, and what standalone Java code (e.g. class) it needs to produce. Individual resolved types are not yet implemented, this commit provides the flow to pass the parsed structure (from schema) to the resolution logic.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23288208

fbshipit-source-id: 18535d5fae8ca15f6d9374bdba38f57dfd4300e8
2020-08-25 10:38:14 -07:00
Kevin Gozali 301e149f97 Codegen: JavaGenerator [4] - collect all parsed types in a flat list of "TypeData"
Summary:
Instead of recreating the schema structure, the generator only needs to collect the list of types that it needs to generate for. So instead, let's just add each parsed type into a map using TypeId as the key. This means every inner types in the schema needs its own unique TypeId. This was a change from the previous commit where we didn't assign unique names to the types. Here's the reasoning:
* In Java, any generated class needs to be in its own file.
* If a NativeModule spec defines a few aliases, and or inner types (function args, return type shape, etc) that needs representation with a dedicated class, we need to track them as well for code generation.
* This means, the schema format is no longer relevant for the code generation step, so let's produce a structure that's more efficient for code generation

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23287818

fbshipit-source-id: 7caf4e95aeafe5c8ba336af290179b85bf87ad6d
2020-08-25 10:38:14 -07:00
Kevin Gozali b0fbbe5442 Codegen: execute JavaGenerator only after tasks are evaluated
Summary:
Instead of invoking JavaGenerator when the task is registered, do it when the task actually executes. This way, it will wait until the other task it depends on to finish executing.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23276359

fbshipit-source-id: 6aea98d97121f2dcfd83b299e38debc767f08240
2020-08-22 11:34:57 -07:00
Christoph Nakazawa 3967635632 Add a proper "monorepo" setup for React Native
Summary:
This adds all the packages we use to the workspace in open source, which means we can change our publish scripts to also publish the packages from the repo every time we publish the main repo. I'll work with somebody from the community on that part.

Note: We do not use `eslint-config-react-native-community` internally and it pulls in a lot of packages we don't need. It is part of the React Native repo because it is used in the RN app template but we may want to choose to move it out into a separate repo at some point.

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D23208695

fbshipit-source-id: 02d401721dfdc8bbb2305f8ac3381f1e98c18f1d
2020-08-21 02:54:24 -07:00
David Vacca 29513ac989 Fix output files generated by oss-android-codegen script
Summary:
This diff filters the iOS C++ friles that are generated by the oss-android-codegen script
Also, as part of this diff I'm inlcuding .cpp files into the output.

These files are only used and compiled in Android

changelog: [internal] internal

Reviewed By: fkgozali

Differential Revision: D23169268

fbshipit-source-id: 404607f3cd6e59197291ea67701774c9c492a282
2020-08-18 17:00:01 -07:00
Christoph Nakazawa f3930a93d5 Split React Native repo into product/infra packages
Summary: Changelog: [Internal]

Reviewed By: TheSavior

Differential Revision: D23165627

fbshipit-source-id: f371c070f8b297c218d2989ff3b553a8b83c18ea
2020-08-18 12:10:09 -07:00
Kevin Gozali eecb930222 Codegen: JavaGenerator [3] - parse aliases and reserved value types
Summary:
This parses the JSON schema's aliases and reserved function valye types. It also assigns TypeId correctly now:
* TypeId is an identifier for a specific type, that can be referred by others
* This means only aliases should have TypeId.typeName. Properties' names are not typeNames
* NativeModule spec's typeName is hardcoded to `Spec`, see T71955395

This way, whenever we encounter an `AliasType`, we can just lookup the actual Type by a quick Map lookup with TypeId as the key.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23181432

fbshipit-source-id: 9d0ea17dbf601589d8f3fc1955e0c9406a80e244
2020-08-17 19:41:53 -07:00
Kevin Gozali e26dd1c35d Codegen: JavaGenerator [2] - parse JSON schema into Java typed representation
Summary:
This parses the output JSON schema into Java Type's, without any alias resolution. Some parts of the schema have incomplete information, hence a bunch of TODOs in the code expressing the issues.

Notes:
* The type structure here could be implemented in other codegen generators as well (including the RNCodegen.js' generators) for better type safety and correctness. With this exercise, I was able to catch a few issues mentioned above.
* This commit does not produce any Java code with JavaPoet yet, just parsing the schema.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23152891

fbshipit-source-id: 9f774dd98975f7202d3faf11c3fbfb83d4c97f5a
2020-08-17 14:10:04 -07:00
David Vacca dc7defacef Add @generated tag int Fabric codegen files
Summary:
This diff adds the generated tog to codegen files

changelog: [internal] internal

Reviewed By: fkgozali

Differential Revision: D23117527

fbshipit-source-id: 600013425deeb08321761622e13e7cf9a0f0db38
2020-08-14 12:14:00 -07:00
David Vacca 29bcb5094d Create buck target to copy C++ files into OSS
Summary:
This new buck target will execute the code gen and copy C++ files to the output directory. This will be used to integrate these files into RN Tester

changelog: [internal] internal

Reviewed By: fkgozali

Differential Revision: D23115538

fbshipit-source-id: de4135be697c36cd559edf416986299511c31744
2020-08-13 17:45:03 -07:00
Kevin Gozali 59a4d6f52b Codegen: JavaGenerator [1] - introduce type model to represent the parsed JSON schema
Summary:
These Java types are to represent the schema structure based on the definition here: https://github.com/facebook/react-native/blob/master/packages/react-native-codegen/src/CodegenSchema.js#L260
This commit only deals with NativeModules related types, not Fabric yet.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23100170

fbshipit-source-id: f3d837c04b35bef099cb0132bccaca117c22f211
2020-08-13 14:52:09 -07:00
Kevin Gozali 3f1a4535d9 Codegen Gradle: add toggle to activate JavaGenerator implementation
Summary:
JavaGenerator is a Java-based implementation for generating codegen output from the parsed schema file. Right now the output is a hardcoded Java file. In the next commits, proper JavaGenerator impl will be added.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23100171

fbshipit-source-id: 1bef23e3dba4d8c222ebdece0edeb4435d388cd4
2020-08-13 14:52:09 -07:00
Kevin Gozali e8c1eeeb06 codegen Gradle: introduce com.facebook.react.codegen plugin to replace architecture.gradle script
Summary:
Instead of applying configs from gradle scripts, this introduces a proper Gradle plugin to enable Codegen in an application or library project. In the build.gradle, one enables it by:

```
plugins {
    id("com.android.application")
    id("com.facebook.react.codegen") // <---
}

// ...

react { // <--- the new plugin extension
    enableCodegen = System.getenv("USE_CODEGEN")
    jsRootDir = file("$rootDir/RNTester")
    reactNativeRootDir = file("$rootDir")
}
```

The plugin supports `react` plugin extension as demonstrated above. Adding this:
* automatically generates all TurboModule Java files via react-native-codegen **before the `preBuild` Gradle task**
* automatically adds the files to the `android {}` project configuration
* is done per project (build.gradle)

This will be the foundation for future React Native gradle plugin beyond just for react-native-codegen.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23065685

fbshipit-source-id: 4ea67e48fab33b238c0973463cdb00de8cdadfcc
2020-08-12 11:12:43 -07:00
Kevin Gozali 75033fcb00 codegen: copy gradlew files from root dir
Summary:
Using the same copies from react-native root dir.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D22936067

fbshipit-source-id: 8484991f26d51085c6c45405a940e94624b35e06
2020-08-05 06:35:41 -07:00
Ramanpreet Nara b5097c8dcd Back out "Back out "[TM][JS] Forward NativeModule schema to __turboModuleProxy""
Summary:
**Note:** This is a carbon copy of D22832730 (https://github.com/facebook/react-native/commit/3df6f5fb2c6176a809cdfef69a91792d3dce7d86). The fixes are stacked on top of this diff, in D22888030.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D22888032

fbshipit-source-id: 2f1b7ecd39437a3c5ee9c3214419716fde2bbdff
2020-08-04 15:49:52 -07:00
Kevin Gozali 83edd0c5fe codegen: set up Gradle plugin for more maintable codegen build steps
Summary:
Instead of sourcing-in a .gradle file to setup codegen tasks in Gradle, let's define a proper `com.facebook.react.codegen` Gradle plugin, so that any Gradle project (lib/app) can include it via:

```
plugins {
    id 'com.facebook.react.codegen'
}
```

The idea (not yet implemented in this commit) is to then allow those projects to add this section in the projects:

```
codegen {
    enableCodegen = ...
    jsRootDir = ...
}
```

This is more scalable and less hacky.

Important notes:
* The Gradle plugin should be prepared during the build, we're not going to publish it to Maven or other repo at this point.
* This setup is inspired by composite build setup explained here: https://ncorti.com/blog/gradle-plugins-and-composite-builds
* All android specific setup is added under `packages/react-native-codegen/android/` dir, but long term, we may want to move it up to `packages/react-native-codegen/` along side setup for other platforms.
* As part of this setup, the plugin will have an option (to be validated) to produce Java specs using https://github.com/square/javapoet
  * This is the same library already used for React Native Android annotation processors
  * This generator will not deal with parsing Flow types into schema, it will just takes in the schema and produce Java code
  * We're evaluating whether JavaPoet is a better choice for Java code generation long term, vs building it in JS via string concatenation: https://github.com/facebook/react-native/blob/master/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js
  * This commit produces a sample Java code, not the actual codegen output

Changelog: [Internal]

To try this out, run this Gradle task:

```
USE_CODEGEN=1 ./gradlew :ReactAndroid:generateJava
```

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D22917315

fbshipit-source-id: 0b79dba939b73ff1305b4b4fd86ab897c7a48d53
2020-08-04 00:55:23 -07:00
Gijs Weterings f8f53e595c Back out "Forward NativeModule schema to __turboModuleProxy"
Summary:
Original commit changeset: aecaf9943f9b

Changelog: [Internal]

Reviewed By: jimmy623

Differential Revision: D22885708

fbshipit-source-id: 6839266653ad33ea8fb53c9f4664ed773c57443d
2020-08-01 06:25:26 -07:00
Kevin Gozali e3c0f6b026 codegen: complete Android Java spec support in the JS generator
Summary:
This builds on the previous commit and complete all current NativeModule spec support for React Native Android:
* method param (nullable) typing
* promise return support
* sync method
* getConstants() special Android runtime validation

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D22862422

fbshipit-source-id: abc6d46fb8ce5863677910de1acc8bb6a927e7da
2020-07-31 19:04:54 -07:00
Kevin Gozali 77e0ba2fb0 codegen: add Android NativeModule generator base structure
Summary:
* Allow generate-native-modules-specs-cli.js to generate Android specific files
* Add stub impl for Java spec generation (the output are still incomplete, see the next diffs for missing impl + tests)
* Adjust the CLI to only produce modules stuffs, there's no need to produce components code

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D22860936

fbshipit-source-id: 38aae390189f143f6c6216995437ac1ff15a1788
2020-07-31 19:04:54 -07:00
Kevin Gozali 4a5b074c79 codegen: support directories as inputs to schema CLI
Summary:
Sometimes mobile build systems just needs to provide the JS root dir to scan for NativeModules + NativeComponents, so let's support that directly in the CLI. This way, each build system doesn't have to do its own grep/crawling/filtering of files.

This will be needed for CocoaPods/Gradle integration.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D22850011

fbshipit-source-id: fe202fa5e5a490af6d76fd10e761c9c3805fc11f
2020-07-31 19:04:54 -07:00
Ramanpreet Nara 3df6f5fb2c Forward NativeModule schema to __turboModuleProxy
Summary:
`babel-plugin-codegen` will run the NativeModules codegen on each NativeModule spec, and inline the generated schema into the spec's `TurboModuleRegistry.get(Enforcing)?` call. This diff will forward that schema to `__turboModuleProxy` function (i.e: the TurboModule C++ infra).

**Note:** Both this and D2280384 can't be landed until D22743294 (https://github.com/facebook/react-native/commit/650c0f64f1262d26a31b61d2a7576c485f3efa13) hits production (1-2 weeks).

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D22832730

fbshipit-source-id: aecaf9943f9b01be805ff6b90249a6cbc6abdd20
2020-07-31 18:29:53 -07:00
Ramanpreet Nara 91205d2ba4 Re-organize NativeModule types
Summary:
This diff:
- Moves the NativeModule flow types to the bottom of `CodegenSchema.js`.
- Re-organizes the NativeModuel flow type declarations based on when they're first used. Essentially, we start off by declaring a giant 'NativeModuleShape' type, which uses smaller undeclared types. Then we declare all the undeclared children of `NativeModuleShape`, and on and on. This way, you know where to start reading the types, and you can easily tell how every type relates to every other type.

Changelog: [Internal]

Differential Revision: D22828840

fbshipit-source-id: 5b4b9466a41b9bcb92a1de159bcbc12e4dc01df3
2020-07-31 15:13:21 -07:00
David Vacca 3093010ea5 move fabric to ReactCommon/react/renderer
Summary:
This diff moves fabric C++ code from ReactCommon/fabric to ReactCommon/react/renderer
As part of this diff I also refactored components, codegen and callsites on CatalystApp, FB4A and venice

Script: P137350694

changelog: [internal] internal refactor

Reviewed By: fkgozali

Differential Revision: D22852139

fbshipit-source-id: f85310ba858b6afd81abfd9cbe6d70b28eca7415
2020-07-31 13:34:29 -07:00
Jiawei Lv a1ed73dd64 Make some RN rules no-op for arc focus (#29510)
Summary:
## Changelog: [Internal]

## Test Plan: run buck project

Reviewed By: cute-jumper

Differential Revision: D22495239

fbshipit-source-id: b77c65632ee5fb0efd0d5980f11c48d76a4fdbb6
2020-07-29 15:11:19 -07:00