Commit Graph

481 Commits

Author SHA1 Message Date
Chatura Atapattu 2c2b831716 Apply new buildifier fixes
Summary: Changelog: [Internal]

Reviewed By: zertosh

Differential Revision: D30407205

fbshipit-source-id: 022a02829d59a900764b228afb9856ed1ba2cf8c
2021-08-19 20:01:02 -07:00
Nicola Corti 1f8c5607b2 Flatten the react-native-codegen included build. (#32007)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32007

This Diff simplifies the codegen Gradle build.
Previously the build used to have a 2-level nesting of included build.

Turns out that the `react-native-codegen/android/build.gradle` build
is just providing a task and including an inner build that contains the codegen
Gradle plugin. I've moved such plugin to the outer build.

This will also make sure that the Gradle plugin files are properly index by the
IDE when opening the build (as nested included build are not yet supported).

Changelog:
Internal - Flatten the `react-native-codegen` Gradle included build

Reviewed By: fkgozali, ShikaSD

Differential Revision: D30227784

fbshipit-source-id: af304afeeba1926f8b7b5b47cf69889d3f808f5f
2021-08-12 05:14:58 -07:00
Nicola Corti ae494e7ce1 Bump AGP to 4.2.2
Summary:
This is just a minor bump in the Android Gradle plugin.

Changelog:
[Android][Changed] - Bumped AGP to 4.2.2

allow-large-files

Reviewed By: ShikaSD

Differential Revision: D30220591

fbshipit-source-id: 217a21e4935bcd258ac3bcd45c7fb1ff5c0a1ead
2021-08-12 02:43:16 -07:00
David Vacca 809fd7eab2 Add TODO to fix and enable 'generated_tests-codegen_testsAndroid'
Summary:
Add TODO to fix and enable 'generated_tests-codegen_testsAndroid'

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D30046143

fbshipit-source-id: dbeba6f1d51b32c069bda8bb9ca976014d299dae
2021-08-02 15:36:33 -07:00
David Vacca cdce14f670 Implement PlatformColor in Fabric Android
Summary:
This diff implements PlatformColor in Fabric Android

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D29841461

fbshipit-source-id: 63a523626b021c634bc399e749b639b55730391a
2021-07-30 22:16:08 -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
Dustin Shahidehpour 35a4ba01e8 explicitly set autoglob=False on programatically created targets.
Summary:
I'm going to be flipping the default from autoglob on `fb_apple_library` to `True`. This prepares the target so that there are no behavior changes.

## Changelog: [Internal]

Reviewed By: natestedman

Differential Revision: D29769271

fbshipit-source-id: a20b4f99f00613c092461979b4afe61bdca9fe37
2021-07-19 13:57:43 -07:00
Tim Yung 92c13f0d1d RN: Replace master with main in Documentation
Summary:
Updates documentation in React Native to reference `main` (or `HEAD` for URLs) instead of `master`.

Part of https://github.com/facebook/react-native/issues/31788.

Changelog:
[General][Changed] - Update documentation reference from `master` to `main` or `HEAD`.

Reviewed By: JoshuaGross

Differential Revision: D29717128

fbshipit-source-id: 0b0babd8407c6fd3d0e5431f6eaf976059731d6f
2021-07-15 15:22:57 -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
Dulmandakh 70da640946 remove jcenter (#31609)
Summary:
jcenter is read-only now, and newer versions of dependencies will be published to either MavenCentral or Jitpack. This PR removes jcenter to avoid future issues, then uses MavenCentral and Jitpack as replacement. Current flipper depends on Stetho version that is not available on MavenCentral, so had to exclude and bump the version.

Both Gradle and Buck successfully download all the dependencies.

## Changelog

[Android] [Changed] - Remove jcenter

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

Test Plan: rn-tester builds and runs as expected.

Reviewed By: mdvacca

Differential Revision: D28802444

Pulled By: ShikaSD

fbshipit-source-id: 043ef079d0cda77a1f8dd732678452ed712741a4
2021-06-02 09:57:28 -07:00
Dulmandakh 547b4c92e4 Gradle 6.9, Android Gradle Plugin 4.2.1 (#31593)
Summary:
Bump Gradle to 6.9 which supports Apple Silicon, also Android Gradle Plugin 4.2.1 which defaults to Java 1.8 so no additional config required.

## Changelog

[Android] [Changed] - Bump Gradle to 6.9, Android Gradle Plugin to 4.2.1

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

Test Plan: rn-tester builds and runs as expected

Reviewed By: mdvacca

Differential Revision: D28711942

Pulled By: ShikaSD

fbshipit-source-id: 2a4616cd0f17db7616ab29dea1652717f2cd0f6d
2021-06-01 11:29:51 -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
Micha Reiser 58a0f9b4e2 Upgrade babel from 7.12.3 -> 7.14.1
Summary:
Changelog:

[General] [Changed] Upgrade Babel from 7.12.3 to 7.14.1

Reviewed By: motiz88

Differential Revision: D27851184

fbshipit-source-id: 59326332d1d188f163cdb034556eea7808824360
2021-05-13 02:48:09 -07:00
Pavlos Vinieratos 73844712b6 Fixing the git attrs for all the people and all the files and all future (#31128)
Summary:
We have had problems with `.gitattributes`, `.bat` and `.pbxproj` (Xcode) files for a while. The two main concerns were:
- Xcode project files not diffing correctly.
- Windows files having messed up line endings.
This PR fixes both issues, hopefully forever.

After seeing the diffs from v0.63 -> v0.64 and the changes in https://github.com/facebook/react-native/pull/29792, I, again, felt that this is going to cause problems, so I looked into both issues.

I started with `git check-attr -a Artsy.xcodeproj/project.pbxproj` after removing the `.gitattributes` file that contained `*.pbxproj -text` and there are no "guessed" attributes that would break things, and diffing and checking in worked well with the current git version. I agree this is not needed, so I left it out.

I looked into what it was doing before, and it was telling git (for the xcode project file) to "unset text", which means (according to https://git-scm.com/docs/gitattributes#_text) that it should not try to do any line ending changes when checking in that file. At some point git must have done this, and that's why it was needed, but no more, so it's safe and good to get rid of this, as it helps with nothing anymore.

Now for the bat files. We don't need any extra instructions for `gradle` and `*.sh` files as they are guessed correctly, so these are also safe to keep removed (https://github.com/facebook/react-native/pull/29792/files#diff-618cd5b83d62060ba3d027e314a21ceaf75d36067ff820db126642944145393eL5).

But we do need the `*.bat` instruction. I noticed that when working on macOS there were two problems that made things funky.
- One, is that the editor (usually vscode but not the important) would convert line endings to lf when editing a bat file.
- Two, is that git thought the files are lf line endings.

To fix the first one, I added a rule in `.editorconfig` (that's whats important, when any editor just supports editorconfig, but all my editors do). I can't believe how we missed that for sooooo long {emoji:1f605}!

To fix the second, I added the `.gitattributes` instruction **and** `renormalize`d the files (https://git-scm.com/docs/git-add#Documentation/git-add.txt---renormalize and https://docs.github.com/en/github/using-git/configuring-git-to-handle-line-endings#refreshing-a-repository-after-changing-line-endings). I think the problem all along was that even though the files had crlf, git still thought they were using lf.

After the editorconfig change and the renormalization, everything behaves correctly and as expected. Changing bat files on macOS and Windows is fine now, producing only the smallest change needed, no random line ending diffs. Also here is a screenshot of one of the files actually crlf. It's these tiny things at the end of each line {emoji:1f453}.
<img width="612" alt="Screenshot 2021-03-10 at 12 20 28" src="https://user-images.githubusercontent.com/100233/110630943-ef536280-819d-11eb-9212-dbd70f038a44.png">

I have tested this on macOS and Windows, doing changes in both bat and xcode files, and verified that diffing and checking in files works well.

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

[General] [Added] - Added an `.editorconfig` file to help with default line endings for Windows files.

[Internal] [Fixed] - Added a rule in `.editorconfig` and `.gitattributes` to help with default line endings for Windows files.

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

Test Plan: Feel free to go on a macOS or Windows machine (or both) and, using any editor that supports editorconfig, do any change in a `.bat` file. Then look at your git diff in terminal or gui or whatever you use, and then look at the sky and smile. It's fixed. The diff is just your change. Everything is as it should {emoji:1f49c}.

Reviewed By: nadiia

Differential Revision: D27914636

Pulled By: hramos

fbshipit-source-id: fc4e53a4fa42cb13e29686669e8de1679c2242e7
2021-04-21 11:27:32 -07:00
Samuel Susla 9ef995a14a Enable C++ 17 in React Native
Summary:
Changelog: [Internal] enable support for C++ 17.

C++ 17 in React Native targets.

Short and comprehensive list of C++ features:
https://github.com/AnthonyCalandra/modern-cpp-features#c17-language-features

Reviewed By: JoshuaGross

Differential Revision: D27431145

fbshipit-source-id: e8da6fe9d70e9b7343a8caec21cdbeb043478575
2021-04-01 04:50:59 -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
Andrei Shikov dbbc1c1624 Add react build app plugin and extension
Summary:
Changelog:
[Android][Added] - Basic definition for react gradle plugin

Adds plugin and build configuration + copies config from react.gradle to extension.
Copies internals of react.gradle to the plugin. Will be refactored in the next commits.

Reviewed By: mdvacca

Differential Revision: D25693008

fbshipit-source-id: b0feaa02cee8a1ee94d032426d19c501ff3b2534
2021-02-22 08:16:51 -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
Andrei Shikov 704dd2812f Replace jcenter with mavenCentral when possible
Summary:
Changelog:
[Android][Changed] - Initial replacement of jcenter with mavenCentral.

Replaces jcenter with Maven Central in the build files of the repository.

Some dependencies are not resolvable from maven central yet, so for now they are included from jcenter, but limited to specific modules only.

I didn't touch the template for now.

Reviewed By: mdvacca

Differential Revision: D26260977

fbshipit-source-id: 2a65e1195b6367c026089184ad6471bf3573dc37
2021-02-05 05:17:32 -08:00
Héctor Ramos edf18c74ce Bump react-native-codegen to 0.0.7
Summary:
Publish a new react-native-codegen release with latest changes in order to support the 0.64 react-native release.

Changelog:
[Internal]

Reviewed By: fkgozali

Differential Revision: D26253312

fbshipit-source-id: 766cfa3e088b3715bc9bc815523c8d04fae409bf
2021-02-04 17:35:57 -08:00
Micha Reiser 93377ff508 Remove "use strict" directive from ES Modules
Summary:
ES Modules implicitly enable strict mode. Adding the "use strict" directive is, therefore, not required.

This diff removes all "use strict" directives from ES modules.

Changelog:

[Internal]

Reviewed By: motiz88

Differential Revision: D26172715

fbshipit-source-id: 57957bcbb672c4c3e62b1db633cf425c1c9d6430
2021-02-02 11:12:56 -08:00
Igor Klemenski 5dc15222b2 Fix building RN Android from source on Windows. (#30535)
Summary:
Running `.\gradlew installArchives` is currently broken on Windows. This is because .sh scripts were added in the codegen module, which cannot be run by the Command Prompt on Windows. It can be worked around by installing eg. Git Bash., which can be then leveraged using the code modifications in this PR, which include sanitizing mixed Linux-Windows relative paths, and other minor Windows-specific adjustments.

It's required that the user adds a Windows Environment variable storing the path to their bash binary named `REACT_WINDOWS_BASH`.

Pair-programmed with davinci26
## 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] [Fix] - Fix building React Android on Windows.

Fixes https://github.com/facebook/react-native/issues/30271

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

Reviewed By: ShikaSD

Differential Revision: D25909760

Pulled By: appden

fbshipit-source-id: ea0e6e7c161a5e4a937d46e8e6972ce142fead4e
2021-01-28 11:53:56 -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 dc0b917fb5 Preserve directory structure in android zip
Summary:
The Codegen runs on all JavaScript specs, generating C++/Java/Jni, etc. Then, we copy only the Java files into a directory:

https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/js/react-native-github/packages/react-native-codegen/DEFS.bzl?commit=3945e905d6636c005af77d29b7f45ef7b1efe00e&lines=340-347

And zip that directory up, before [creating an android_library with that zip](https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/js/react-native-github/packages/react-native-codegen/DEFS.bzl?commit=3945e905d6636c005af77d29b7f45ef7b1efe00e&lines=395-414%2C442-452%2C415-442):

https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/js/react-native-github/packages/react-native-codegen/DEFS.bzl?commit=3945e905d6636c005af77d29b7f45ef7b1efe00e&lines=365-371

**Problem:** We unnecessarily flatten the directory structure of all our Java files.

This diff moves all the files under the java/ folder of the Codegen output into the zip that is used to create the android_library. This way, we avoid filename collisions between two Pojos belonging to two different components (with different packages), but that have the same name.

Changelog: [Internal]

Differential Revision: D26050260

fbshipit-source-id: f92e916cd640a688997dd75c2707d77cb15de083
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 5a2099fe7d Rename rn_codegen_modules(native_module_spec_name => name)
Summary: Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25963929

fbshipit-source-id: 4c82562404a21b5a1789d11ae2d228411329fee5
2021-01-21 19:04:54 -08:00
Ramanpreet Nara d2bbedad1a Rename intermediary module codegen targets
Summary: Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25963082

fbshipit-source-id: 54ed496a6e8bab224f6145539c63cb006e619900
2021-01-21 19:04:53 -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 86a9c0aa8f Delete react_native_module_flow_types_library(name = "RNCodegenModuleFixtures")
Summary:
This BUCK target only existed for debugging purposes. Nothing depends on it.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D25844759

fbshipit-source-id: e27fb04809a5c97adbeefd7df60b82992c6e1eda
2021-01-08 14:44:00 -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
Ramanpreet Nara d5cfad5519 Make android codegen target generate static library
Reviewed By: fkgozali

Differential Revision: D25835846

fbshipit-source-id: 214b8059d73c6e675a5006c7ca46db9ebc425e9b
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 fb34fba01c Use native_module_spec_name to name codegen targets
Summary:
## Description
Suppose this was the codegen declaration before:

```
rn_library(
  name = "FooModule",
  native_module_spec_name = "FBReactNativeSpec",
  codegen_modules = True,
  # ...
)
```

Previously, this would generate the following BUCK targets:
- generated_objcpp_modules-FooModuleApple
- generated_java_modules-FooModuleAndroid
- generated_java_modules-FooModule-jniAndroid

## Changes
We will now generate:
- FBReactNativeSpecApple
- FBReactNativeSpecAndroid
- FBReactNativeSpec-jniAndroid

This matches the naming scheme of the old codegen.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D25680224

fbshipit-source-id: 617ac18fd915f3277f6bd98072d147f20fb193e5
2020-12-24 00:50:01 -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
Ramanpreet Nara bc0c5c98bb Move react-native-codegen/e2e/__tests__/modules/BUCK
Reviewed By: PeteTheHeat

Differential Revision: D25675408

fbshipit-source-id: 97f8070611f7f7707af9bd7dd9c9a59e8ad96125
2020-12-22 09:06:31 -08:00