Commit Graph

36 Commits

Author SHA1 Message Date
Nicola Corti 3a41131913 Setup a package inside react-native-gradle-plugin.
Summary:
This diff adds a `package.json` inside `react-native-gradle-plugin`
so it can be distributed and used inside the `template/` project
similarly to what we do with the `react-native-codegen` package.

Changelog:
[Internal] [Added] - Setup a package inside `react-native-gradle-plugin`

Reviewed By: fkgozali

Differential Revision: D31081980

fbshipit-source-id: 9a9ad696ee6db01666bae75255616fd20aadd243
2021-09-24 09:27:59 -07:00
Nicola Corti 5b8da02296 Fix GenerateCodegenArtifactsTask calling two generators with Java enabled
Summary:
This diff fixes a bug with `GenerateCodegenArtifactsTask` that was causing
two generators to be called one after the other (first the JS and then the Java one).
Now they're mutually exclusive.

Changelog:
[Internal] [Changed] -  Fix GenerateCodegenArtifactsTask calling two generators with Java enabled

Reviewed By: ShikaSD

Differential Revision: D31169379

fbshipit-source-id: 668d8e440ad6b3f06654f29c5cbc344ef82c4b9c
2021-09-24 08:19:17 -07:00
Nicola Corti c3e294f2a8 Move PathUtilsTest.kt to the correct package
Summary:
This file was placed in the wrong package. I'm moving it.

Changelog:
[Internal] [Changed] - Move `PathUtilsTest.kt` to the correct package

Reviewed By: motiz88

Differential Revision: D31168890

fbshipit-source-id: 59d09b5fd329b776bd2800921889281a116c26ee
2021-09-24 04:09:08 -07:00
Nicola Corti 861acce530 Add unit tests for GenerateCodegenSchemaTask
Summary:
Adding tests for the `GenerateCodegenSchemaTask`.
Plus fixing a bug where `delete()` was used instead of `deleteRecursively` causing
the files inside the output folder to don't be properly cleaned up.

Changelog:
[Internal] [Changed] - Add unit tests for GenerateCodegenSchemaTask

Reviewed By: ShikaSD

Differential Revision: D31142346

fbshipit-source-id: 69bb026fa2c64d91193a153fdc99c9b5d0a9e1ff
2021-09-24 03:02:55 -07:00
Nicola Corti 0d9b32769c Add unit tests for BuildCodegenCLITask
Summary:
This Diff is adding some tests for BuildCodegenCLITask.
Plus I found a bug in how we pass the input/output relative to `codegenDir`
so I'm fixing the properties to use `by lazy{}`.

Moreover the `output` was not correctly annotated with `OutputDirectories`,
fixing it here.

Changelog:
[Internal] [Changed] - Add unit tests for BuildCodegenCLITask

Reviewed By: ShikaSD

Differential Revision: D31109599

fbshipit-source-id: bec75b216e8cef18072179c89c3223ee2bad74e3
2021-09-24 02:13:03 -07:00
Nicola Corti 929cb56f22 Merge CodegenPlugin with ReactAppPlugin
Summary:
Since we moved several classes from the older Java plugin to standalone files,
we can now remove the old `CodegenPlugin.java` class and have a single plugin class.

Changelog:
[Internal] [Changed] - Merge `CodegenPlugin` with `ReactAppPlugin`

Reviewed By: ShikaSD

Differential Revision: D31080558

fbshipit-source-id: c4b005f8648ab62a71cb5bee22c06ae5272ecc44
2021-09-24 01:40:08 -07:00
Nicola Corti d314d1f265 Export GenerateCodegenArtifactTask to its own task.
Summary:
This is the last task from the Codegen Plugin that is exported to
its own Task file and converted to Kotlin.

Changelog:
[Internal] [Changed] - Export `GenerateCodegenArtifactTask` to its own task.

Reviewed By: ShikaSD

Differential Revision: D31054781

fbshipit-source-id: 6787065b497570fb312310e3d9f4120f0629f374
2021-09-24 00:47:10 -07:00
Nicola Corti 7df5f57fa7 Export GenerateCodegenSchemaTask to its own task.
Summary:
Similarly to the previous diff, this is moving another small part of the codegen
to its own Kotlin separate task. I've used the Gradle idiomatic APIs and added a couple of tests.

Changelog:
[Internal] [Changed] - Export `GenerateCodegenSchemaTask` to its own task.

Reviewed By: ShikaSD

Differential Revision: D31017274

fbshipit-source-id: f0d288a63883e92a9d725eb3bf695a3aa77f9030
2021-09-20 03:23:44 -07:00
Nicola Corti 2a0d8cccea Export BuildCodegenCLITask to its own task class
Summary:
This diff moves `BuildCodegenCLITask` from being inlined to have its own task definition
I've also cleaned up the task body and refactored a bit how we do the CLI invocation.

Changelog:
[Internal] [Changed] - Export `BuildCodegenCLITask` to its own task class

Reviewed By: ShikaSD

Differential Revision: D31016610

fbshipit-source-id: 8407fc2a62ea473daa775196925c1b9b6f4f2f4b
2021-09-17 11:26:30 -07:00
Nicola Corti 85031d0166 Rename extension to just ReactExtension
Summary:
I'm cleaning up the extension to be just ReactExtension and not ReactAppExtension.
Similarly the name of the extension will be just `react` and not `reactApp`.

Changelog:
[Internal] [Changed] - Rename extension to just ReactExtension

Reviewed By: ShikaSD

Differential Revision: D30964793

fbshipit-source-id: 8a4207825d424e133e51495c34c21284c50363ae
2021-09-16 05:38:51 -07:00
Nicola Corti 05b449baf2 Use Locale.ROOT for capitalization of variant names
Summary:
The IDE is complainign as we're using capitalization functions that
are not locale-independent. I'm changing this to use `Locale.ROOT`.
Once we move to Kotlin 1.5 we're going to replace those functions with newer ones.

Changelog:
[Internal] [Changed] - Use Locale.ROOT for capitalization of variant names

Reviewed By: ShikaSD

Differential Revision: D30958992

fbshipit-source-id: 225af4e7e323f143ab75bad106f3bca3db510b22
2021-09-15 09:32:55 -07:00
Nicola Corti 022f188750 Merge CodegenPluginExtension inside ReactAppExtension
Summary:
This Diff is merging over all the properties from `CodegenPluginExtension` to
`ReactAppExtension`. Some of the properties were duplicate and generally having two
extensions is creating a lot of confusion for the users (e.g. don't know where to place a
specific property).

Therefore I'm merging the two to have only one. I've also updated the property to use the
Gradle Lazy Configuration API.

Changelog:
[Android] [Changed] - Gradle: Merge CodegenPluginExtension inside ReactAppExtension

Reviewed By: ShikaSD

Differential Revision: D30961343

fbshipit-source-id: 66be3157efef356392c0701aaef2283d058d3161
2021-09-15 09:23:23 -07:00
Nicola Corti 578cba2338 Use Gradle Lazy API (#32214)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32214

This Diff updates part of the Gradle plugin to use the Gradle Lazy Api (mostly `Property` classes).
This will defer the time when those value are accessed from configuration to execution phase.

So far I've converted the `Extension` class that should be our primary entry point to the public API.
I haven't converted the tasks as well, therefore we have several `.get()` calls around now.
I'll take care of them once I go over the Tasks file as well.

Moreover, I added some documentation to the Extention properties, as those will show up in the `build.gradle`
autocompletion for our users.

On the API point of view, this is going to be a breaking change for users that are testing the Gradle plugin AND
are on Gradle Kotlin DSL (which I believe are really limited so I don't think is a problem at the moment). Users
relying on `react.gradle` are unaffected.

Changelog:
[Internal] [Changed] - Use Gradle Lazy API

Reviewed By: ShikaSD

Differential Revision: D30902517

fbshipit-source-id: 5af4625e901b82f4b1c65bd631aa4bb9b505b2d0
2021-09-15 05:29:38 -07:00
Nicola Corti c3ff336326 Merge the two Gradle Plugins (#32177)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32177

This diff merges the `react-native-gradle-plugin` and the `react-codegen/android` into a single plugin.
This will allow us to iterate faster on a single plugin, will create less confusion for our users (`react` vs `reactApp`)
and will help us avoid race conditions when the two plugins are applied together (as we will control the whole lifecycle of it).

Changelog:
[Internal] [Changed] - Merged the two Gradle Plugins

allow-large-files

Reviewed By: ShikaSD

Differential Revision: D30765147

fbshipit-source-id: fcb02a181c7d900daa514107c637d0ee0225976c
2021-09-15 03:21:23 -07:00
Facebook Community Bot 671068f28d Re-sync with internal repository (#32212)
Co-authored-by: Facebook Community Bot <6422482+facebook-github-bot@users.noreply.github.com>
2021-09-15 10:45:06 +01:00
Nicola Corti 16a6f9f9d0 Do not wipe extraArgs for BundleJsAndAssetsTask
Summary:
Seems like we discard the `extraArgs` for `BundleJsAndAssetsTask` and it doesn't look right.
I'm fixing it here.

Changelog:
[Internal] [Changed] - Do not wipe extraArgs for `BundleJsAndAssetsTask`

Reviewed By: ShikaSD

Differential Revision: D30902743

fbshipit-source-id: 787a7fafab1d3f62d9fdc84d4f55a0cc381bcef8
2021-09-14 06:44:59 -07:00
Nicola Corti 8d4fe826c3 Backport the cliPath fix to the Gradle Plugin (#32193)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32193

This Diff is backporting the change in https://github.com/facebook/react-native/pull/31839/
applied to `react.gradle` also to the React Gradle Plugin. Ideally we would like to two
logic to be in sync as much as possible.

Changelog:
[Internal] [Changed] - Backport the cliPath fix to the Gradle Plugin

Reviewed By: ShikaSD

Differential Revision: D30899057

fbshipit-source-id: a28628b36b3dfe565dbdc8d6416c5d25ddf1fe03
2021-09-13 10:13:10 -07:00
Nicola Corti 24bf1c5e8b Fix broken Android CI due to broken BundleJsAndAssetsTask override (#32194)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32194

This Diff fixes the `test_android` CircleCI that is currently broken due to a faulty `BundleJsAndAssetsTask`
(that's my fault sorry for this).

The CI is failing with a `execCommand == null!` error message. The message is happening as the aformentioned
task is not correctly overriding `exec()` but just declaring a `TaskAction`. I'm fixing it.

Changelog:
[Internal] [Changed] - Fix broken Android CI due to broken `BundleJsAndAssetsTask` override

Reviewed By: GijsWeterings

Differential Revision: D30899742

fbshipit-source-id: a39b01b7d429bd7e87411282e1c22a7606ea22e0
2021-09-13 07:37:51 -07:00
Nicola Corti d246946fb8 Export and test detectedHermesCommand function from ReactAppExtension
Summary:
Another diff to remove code from `ReactAppExtension` to a Util file and test it.

Changelog:
[Internal] [Changed] - Export and test `detectedHermesCommand` function from `ReactAppExtension`

Reviewed By: feedthejim

Differential Revision: D30866510

fbshipit-source-id: 0023a063793d669ee4b2190679ca7fbd01e9a3fc
2021-09-13 03:19:53 -07:00
Nicola Corti d8d9c28b48 Make the BundleJsAndAssetsTask Task more Gradle friendly
Summary:
This Diff is adapting the `BundleJsAndAssetsTask` to be a bit more idiomatic. Here the summary of changes.
- Make the task `abstract` to let Gradle properly implement it.
- Make all the annotated filed `public` instead of `internal` as they will be easier to access for Gradle + will show up
correctly in logs/scans
- Update the Task to subclass a `Exec` that is a specificed Task
- Do not reference `project.` inside the Task body as that is breaking the Configuration Caching of Gradle

Changelog:
[Internal] [Changed] - Make the `BundleJsAndAssetsTask` Task more Gradle friendly

Reviewed By: mdvacca

Differential Revision: D30865159

fbshipit-source-id: 74d4c77f6a2b3fac944e7e0b123726e6a423ba1d
2021-09-10 08:39:21 -07:00
Nicola Corti d4c347c052 Export detected* functions fron ReactAppExtension to its own file
Summary:
Ideally a Gradle `Extension` should contain only properties as it's the public facing API of our
Gradle surface. Here I'm movign a couple of functions away from it. Now they're located inside their
own Util file. Moreover I've added tests and documentation to those.

Changelog:
[Internal] [Changed] - Export `detected*` functions fron `ReactAppExtension` to its own file

Reviewed By: mdvacca

Differential Revision: D30865494

fbshipit-source-id: 59925414c0eb427161691950f5b9b6495121da00
2021-09-10 08:31:43 -07:00
Nicola Corti c40b177f61 Export file utils to a separate file and test them
Summary:
Another small diff to setup some testing for our Gradle Plugin.
Here I exported a couple of extension functions on `File` to a separate
Utils file + I've added some tests for them.

Changelog:
[Internal] [Added] - Add tests for AndroidConfiguration

Reviewed By: mdvacca

Differential Revision: D30841339

fbshipit-source-id: fcb00d7397d1f3e2b4500e9920508c71f20c76f3
2021-09-10 02:40:32 -07:00
Timothy Yung ab2bdee735 Fix encoding for gradlew.bat files (#32178) 2021-09-09 14:33:50 -07:00
Nicola Corti ebcdf511a5 Add tests for AndroidConfiguration
Summary:
Another small diff to setup some testing for our Gradle Plugin.
Specifically this one is also setting up a test environment where we would be able to exercies
AGP usages on top of `ProjectBuilder`. This will allow us to verify that an Android project
is configured correctly for a React Native build.

Changelog:
[Internal] [Added] - Add tests for AndroidConfiguration

Reviewed By: GijsWeterings

Differential Revision: D30839600

fbshipit-source-id: 10e3b3c0fcf5979c2a0eaf64320f87ae58093fbd
2021-09-09 06:42:53 -07:00
Nicola Corti 90a465f8a8 Add tests for TaskUtils
Summary:
This Diff is adding some really simple tests for TaskUtils.
It also adds a couple of utilities to run some sample tests (e.g. mocking the OS version)
that would come handy the more we keep on writing tests and adding functionalities to the Gradle plugin.

Changelog:
[Internal] [Changed] - Added tests for TaskUtils

Reviewed By: mdvacca

Differential Revision: D30809779

fbshipit-source-id: c401cb78e386964e429c6f459c699e6f18f54f11
2021-09-08 10:19:54 -07:00
Nicola Corti 805d798d30 Do not use kotlin-dsl inside react-native-gradle-plugin (#32139)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32139

Currently RN Gradle Plugin is using `kotlin-dsl` that comes will all sorts of side effects on Gradle plugins projects.
Specifically we can't specify the Kotlin version, plus it makes harder to include Java source code in a single
project.

I'm removing it in favor of Kotlin-JVM plugin. I've adapted the code to use the correct APIs.
Specifically most of the lambdas are changing the scope of the parameter (from `this` to `it`) so I had to adapt
those as well.

Changelog:
[Internal] [Changed] - Do not use `kotlin-dsl` for `react-native-gradle-plugin`

Reviewed By: yungsters

Differential Revision: D30726977

fbshipit-source-id: b10635eefdbbb496c4adddd418db6b0ab613ab59
2021-09-06 02:47:50 -07:00
Nicola Corti 040f548ba0 Setup Gradle Wrapper inside packages/react-native-gradle-plugin/ (#32140)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32140

This diff is setting up the Gradle wrapper inside packages/react-native-gradle-plugin/.
Currently the `./gradlew` file is missing so it's not possible to `cd` inside the project and build it from
there (also opening that folder inside the IDE will trigger the creation of the files I added here).

This diff is fixing. The files have been generated with the command:

```
gw -p packages/react-native-gradle-plugin wrapper --gradle-version 7.0.2 --distribution-type=all
```

Changelog:
[Internal] [Added] - Setup Gradle Wrapper inside packages/react-native-gradle-plugin/

Reviewed By: yungsters

Differential Revision: D30730145

fbshipit-source-id: a0bd6be0ac062e089b2b90a55b47987c0f4b6644
2021-09-06 02:42:30 -07:00
Nicola Corti 85249cafe8 Update project to build on Gradle 7.0.2 (#32073)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32073

This Diff bumps the version of Gradle used to build the project to
7.0.2. Ideally we could bump to 7.2.x directly, but I'll do one minor version
at a time to exclude potential build problems.

This diff is addressing all the extra build warnings that got raised by the new version.

Changelog:
[Android][Changed] - Bumped Gradle project version to 7.0.2

Reviewed By: ShikaSD

Differential Revision: D30486612

fbshipit-source-id: 70e0f7d18e547013ca7b1d12f8dd64a633df5870
2021-08-31 13:27:27 -07:00
Carmi Grushko ec3a3df94f Enable ktfmt
Summary: Changelog: [internal]

Reviewed By: zertosh

Differential Revision: D30423755

fbshipit-source-id: 8ae27b3666214f5144ef8b5ef7fe868afc19b4b9
2021-08-19 06:16:37 -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
Dulmandakh 9a5e22650a RN project wide Kotlin version (#31645)
Summary:
This PR sets project wide Kotlin version to 1.4.21, supported in Buck https://github.com/facebook/buck/tree/dev/third-party/java/kotlin.

We had to specify version for both kotlin-dsl and kotlin('jvm') plugins to remove version mismatch warnings in **react-native-gradle-plugin**. Also I expect more Kotlin code in RN, so instead of specifying version for each sub-project it's better to have project wide setting.

We don't need to load Kotlin in react-native-gradle-plugin because Kotlin is available RN project wide.

## Changelog

[Internal] [Changed] - Project wide Kotlin version set to 1.4.21

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

Test Plan: Everything works as expected, no visible change for developers.

Reviewed By: yungsters

Differential Revision: D28991440

Pulled By: ShikaSD

fbshipit-source-id: 971fa6f50c12d916a56d0dcde7c65299496fb68a
2021-06-10 00:46:15 -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
Andrei Shikov c6d7af60fa Use lazy configuration APIs in the react app plugin
Summary:
Changelog:
[Internal] - Use lazy task APIs in the Gradle new plugin

Gradle now migrates to [lazy task APIs](https://docs.gradle.org/current/userguide/lazy_configuration.html) to help with project configuration time. It helps even in the rn-tester case, e.g. `./gradlew help` executes in 2-3s instead of 20s.

The migration is quite simple - use `Provider` and `tasks.register` instead of `task.create` everywhere.

Reviewed By: mdvacca

Differential Revision: D25946748

fbshipit-source-id: 2ccd2f881afe7601e506dc7adcc8a658c7267328
2021-02-22 08:16:52 -08:00
Andrei Shikov 959e135d80 Extract bundle task
Summary:
Changelog: [Internal]

Extracts task definition for bundling and hermes binary into separate tasks in the new plugin.

Reviewed By: mdvacca

Differential Revision: D25915057

fbshipit-source-id: b1d8a4b5e8789c3b7832efea13274435c9391ccb
2021-02-22 08:16:51 -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