Commit Graph

310 Commits

Author SHA1 Message Date
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
Jiawei Lv a7818dd754 Format react-native-codegen/DEFS.bzl (#29372)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/29372

Changelog: [Internal]

Reviewed By: rickhanlonii

Differential Revision: D22496009

fbshipit-source-id: 4b5dc6edd924a21eb4d619b58ab094b9ea4f914b
2020-07-15 13:22:42 -07:00
Héctor Ramos 7e7706cb7d Codegen: Generate ObjC structs for type aliases
Summary:
**Motivation:**

Match the old codegen's behavior when generating structs for type alias derived objects.

**Problem description:**

Take, for example, the following spec:

```
export type MyTypeAlias = { /* ... */ }
export interface Spec extends TurboModule {
  // ...
  +myMethod: (paramName: MyTypeAlias) => void;
  // ...
}
```

The codegen needs to generate a struct to expose the properties of the type alias object. The codegen was producing the following output:

```
- (void)myMethod:(JS::MyModule::SpecMyMethodParamName &)paramName;
```

...which does not match the output from the original codegen:

```
- (void)myMethod:(JS::MyModule::MyTypeAlias &)paramName;
```

The original codegen generates a struct using the type alias name, while the new codegen was generating a struct that uses a combination of the property and parameter names.

Now that type alias names are exposed in the schema, the new codegen can match the original codegen's behavior.

**De-duplication of structs:**

Prior to these changes, type aliases were expanded into regular object types. This meant that any spec that used a type alias more than once would lead to redundant structs getting created. With these changes, we only generate the one struct per type alias, matching the old codegen.

**Expansion of type aliases:**

A new type was introduced in D22200700 (https://github.com/facebook/react-native/commit/e261f022fe6a7653b79330f878fed143725f5324), TypeAliasTypeAnnotation:

```
export type TypeAliasTypeAnnotation = $ReadOnly<{|
  type: 'TypeAliasTypeAnnotation',
  name: string,
|}>;
```

This type may now appear in several locations where a `{| type: 'ObjectTypeAnnotation', properties: [] |}` otherwise would have been used. A `getTypeAliasTypeAnnotation` function is introduced which, given an alias name and an array of aliases provided by the module, will produce the actual object type annotation for the given property parameter.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D22244323

fbshipit-source-id: 125fbf0d6d887bd05a99bf8b81b30bdda4f1682b
2020-07-01 23:39:44 -07:00
Héctor Ramos e261f022fe Codegen: List type aliases in modules schema
Summary:
The current parser behavior flattens out any object type aliases into ObjectTypeAnnotations. Generators can treat these as regular objects and generate the applicable native code. This, however, can lead to repetition whenever an object type alias is re-used in the same native module.

I propose we treat these as a special case, using a TypeAliasTypeAnnotation to denote them as type aliases. Generators can look up the actual signature for a given object alias by referring to the "aliases" array that is provided in the schema.

**Proposed schema change:**

Adds an "aliases" key to each module in the schema:

```
export type NativeModuleShape = $ReadOnly<{|
  properties: $ReadOnlyArray<NativeModuleMethodTypeShape>,
  aliases: $ReadOnlyArray<{|
    name: string,
    typeAnnotation:
      | $ReadOnly<{|
          type: 'ObjectTypeAnnotation',
          properties: $ReadOnlyArray<ObjectParamTypeAnnotation>,
        |}>
      | $ReadOnly<TypeAliasTypeAnnotation>,
  |}>,
|}>;
```

Example:
```
{
  modules: {
    SampleTurboModule: {
      nativeModules: {
        SampleTurboModule: {
          aliases: [],
          properties: [],
        },
      },
    },
  },
}
```

Method parameters will now support the new 'TypeAliasTypeAnnotation' wherever a param might have used a 'ObjectTypeAnnotation':

```
export type TypeAliasTypeAnnotation = $ReadOnly<{|
  type: 'TypeAliasTypeAnnotation',
  name: string,
|}>;
```

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D22200700

fbshipit-source-id: 15684620783c752f2fb482ba4b88d1fd1cc07540
2020-06-30 23:57:16 -07:00
Héctor Ramos 09f360b13d Codegen: Move properties functions out of methods file
Summary:
Moving property handling functions to their own properties.js file. No changes other than adding types to params.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D22208243

fbshipit-source-id: 4a7d2c6e19c151954da793d399af9a256a4a40b7
2020-06-30 16:32:18 -07:00
Eli White 6d44794447 Bump react-native-codegen: 0.0.3
Summary:
Need to publish a new version now that we want to not publish Flow code

Changelog: [Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: kacieb

Differential Revision: D22265050

fbshipit-source-id: a9a0d03b1e2c1ec72e642b0af070ba48426825f8
2020-06-29 13:13:22 -07:00
Héctor Ramos b1e12fb0d5 codegen: Move getSafePropertyName to utils
Summary:
Move to Utils for reuse, and change parameter to take a property object.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D22146669

fbshipit-source-id: e028821cdb11361a45226de0247aa4551b5ade1d
2020-06-24 12:38:38 -07:00
Lulu Wu e6fc20ee68 Keyframes is not implemented in Fabric Android
Summary:
Implement Keyframes in Fabric Android

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D21952500

fbshipit-source-id: 6ba3af1afea227d58b6b12c1be629698d309a04d
2020-06-17 15:25:18 -07:00
Tim Yung 76fe94e8b0 RN: Support $ReadOnly Properties in Codegen
Summary:
Currently, the codegen supports `$ReadOnly` values, but not `$ReadOnly` properties on objects. This adds support for those (by pretty much ignoring them).

Changelog:
[General][Added] - Support `$ReadOnly` in object properties when defining native event types

Reviewed By: TheSavior

Differential Revision: D22023142

fbshipit-source-id: 7167852050925bf31392607923576f023e729f5f
2020-06-16 15:01:05 -07:00
Héctor Ramos 1c92b1cff6 Handle mixed union types and arrays of objects
Summary:
Restore legacy support for mixed union types.
These are not type safe and modules should use a different type, but we have a precedent for supporting these in the existing Linking native module. The new codegen will generate native code for these, and show a warning to encourage use of a better type.

Generate native code for elements in arrays of objects.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D21848260

fbshipit-source-id: 0b8cbf25e7a02791b4d77e349227a2b0744854f4
2020-06-09 17:48:19 -07:00
Héctor Ramos 97d3abf982 Do not use variable types for array elements
Summary:
When a property returns an array type, use the actual element type when generating structs and inlines.

Changelog: [Internal]

Reviewed By: TheSavior

Differential Revision: D21651351

fbshipit-source-id: 14cadf209c38a301c9c65fcaadd8a292c1936349
2020-05-27 14:34:14 -07:00
Kevin Gozali f24b815fe6 use xplat BUCK attribution
Summary:
Internal code attribution update.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D21603406

fbshipit-source-id: c3da1823e26beb0092d97e66d731618c0433a2f7
2020-05-15 21:55:52 -07:00
Lulu Wu 63099c40e6 Migrate Android view managers to type-safe commands generated by JS codegen
Summary:
## Changelog:

[General] [Changed] - Migrate Android view managers to type-safe commands generated by JS codegen.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D21406461

fbshipit-source-id: 93584b240314254675a36a58c4d0c0880d6889fb
2020-05-12 04:37:44 -07:00
empyrical c67e1fe42f Codegen: Add prepublish script to build Flow files (#28827)
Summary:
*This is a follow-up to https://github.com/facebook/react-native/issues/28645, redone using a build script based off of Metro's build script instead of using `flow-remove-types` and `flow-copy-source`.*

This pull request adds a build step to `react-native-codegen` that builds the Flow-annotated JS files so that users of the NPM module `react-native-codegen` do not need to use require hooks to be able to import it.

A new build script, `scripts/build.js` is added that builds every JS file in `src/` into a `lib/` folder, and also copies over the original Flow annotated files to `lib/` with a `.js.flow` extension, so users of `react-native-codegen` can still typecheck against it using Flow. The shell scripts in `src` are also copied over. It is based off of the [build script from Metro](https://github.com/facebook/metro/blob/00867816eb9b2f69c8af9cebb523e9e4d280671a/scripts/build.js)

## Changelog

[General] [Added] - Codegen: Add prepublish script to build Flow files
Pull Request resolved: https://github.com/facebook/react-native/pull/28827

Test Plan:
I am able to make use of the Codegen scripts without needing to use the `flow-node` CLI or the `flow-remove-types/register`
require hook.

Reviewed By: cpojer

Differential Revision: D21412173

Pulled By: hramos

fbshipit-source-id: 26ae67cdd04652ca4700a069a234a25558773cb1
2020-05-08 15:41:35 -07:00
Héctor Ramos 6e88ab6bb2 Avoid redefining id when a property is named 'id'
Summary:
Handle properties named 'id' as a special case.

An example of a native module that ran afoul of this is `ExceptionsManager`.

Observe how the ExceptionsManager spec at `Libraries/Core/NativeExceptionsManager.js` defines the ExceptionData type as containing an `id` property:

```
export type ExceptionData = {
  message: string,
  originalMessage: ?string,
  name: ?string,
  componentStack: ?string,
  stack: Array<StackFrame>,
  id: number,
  isFatal: boolean,
  // flowlint-next-line unclear-type:off
  extraData?: Object,
  ...
};
```

Prior to this change, the generated code would redefine id in the SpecReportExceptionData struct...

```
 namespace JS {
   namespace NativeExceptionsManager {
     struct SpecReportExceptionData {
       // ...redacted...
       double id() const; <---
       // ...redacted...

       SpecReportExceptionData(NSDictionary *const v) : _v(v) {}
     private:
       NSDictionary *_v;
     };
   }
 }
```

...which would result in a build time error:

```
 inline double JS::NativeExceptionsManager::SpecReportExceptionData::id() const
 {
   id const p = _v[@"id"];
   ^--- build time error here
   return RCTBridgingToDouble(p);
 }
```

Comparing the above example  with the currently checked in `FBReactNativeSpec.h`, I see the expected output should be:

```
 namespace JS {
   namespace NativeExceptionsManager {
     struct SpecReportExceptionData {
       // ...redacted...
       double id_() const;
       // ...redacted...

       SpecReportExceptionData(NSDictionary *const v) : _v(v) {}
     private:
       NSDictionary *_v;
     };
   }
 }
```

...and...

```
inline double JS::NativeExceptionsManager::SpecReportExceptionData::id_() const
 {
   id const p = _v[@"id"];
   return RCTBridgingToDouble(p);
 }
```

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D21395463

fbshipit-source-id: e412648013ff9f70ebd294b6f5f81f1faccb4604
2020-05-07 17:58:00 -07:00
Héctor Ramos 853dc04d23 Handle optional return types/values
Summary:
Use folly to wrap optional return types and values as needed.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D21395439

fbshipit-source-id: a0e84e20717887e79a8565332a11fef42ebd3487
2020-05-07 17:57:59 -07:00
João Vieira 16ea9ba813 Support excluding multiple platforms.
Summary:
Currently the schema only allows to exclude a single platform (iOS OR Android). There are cases where we need to exclude multiple. This change converts the previous `excludePlatform` string property into an `excludePlatforms` array.

Changelog:
[Internal][Changed] - Added support to exclude multiple platforms in Codegen.

Reviewed By: sammy-SC

Differential Revision: D21426950

fbshipit-source-id: eff36ffa207109274794b4b300bf6313f8286161
2020-05-07 09:43:52 -07:00
Nikita Lutsenko f4815fbad3 third-party | Move glog from xplat/third-party to third-party and create temporary redirect.
Summary:
Move and create an empty rule that redirects as well, to handle //arvr rules
Need to do this way, since ovrsource sync rules are in different repo.

allow_many_files
allow-large-files

Steps:
- [X] Move glog from xplat/third-party to /third-party
- [ ] Update references in ovrsource to translate to //third-party instead of //xplat/third-party
- [ ] Get rid of temporary rule
- [ ] Update fbsource/third-party/glog to 0.3.5 (what we have in ovrsource)

Changelog: [Internal] Update reference for glog from xplat/third-party to /third-party.

Reviewed By: yfeldblum

Differential Revision: D21363584

fbshipit-source-id: c1ffe2dd615077170b03d98dcfb77121537793c9
2020-05-06 19:04:33 -07:00
Héctor Ramos e8060ae103 Import folly and adjust whitespace to match old codegen
Summary:
Import folly to handle optionals (`folly::Optional<__type__>`)

Sort modules and indent generated code to match output from the old codegen. While not strictly necessary as these are generated files that should not be edited by hand, I found that matching the old codegen in this regard made it less of a chore when it came to comparing the output of both codebases.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D21395231

fbshipit-source-id: 289d617d7a2d93724456c80afea57a49c108cb9b
2020-05-05 16:01:55 -07:00