Граф коммитов

60 Коммитов

Автор SHA1 Сообщение Дата
Nicola Corti cfacfe8b6c Bump gradle-plugin to 0.0.3
Summary:
For the sake of the playbook, I'm bumping the Gradle Plugin to the latest stable.
Specifically a change in how CLI args are parsed (D31908041 (70785e3d5a)) was not backward compatible,
therefore we need to migrate users to the new version.

Changelog:
[Internal] [Changed] - Bump gradle-plugin to 0.0.3

Reviewed By: hramos

Differential Revision: D32101577

fbshipit-source-id: 9a29b988a4b520a8ece10a90a9a4bedc02ec16ad
2021-11-02 10:39:25 -07:00
Héctor Ramos 70785e3d5a generate-specs-cli: Parse arguments using yargs
Summary:
Make `generate-specs-cli.js` use named arguments.

Updated all `generate-specs-cli.js` callsites to make use of named arguments.

Changelog: [Internal]

Reviewed By: sota000

Differential Revision: D31908041

fbshipit-source-id: f2cb5967db3c3b847e1095e35e8d5d21585be27b
2021-10-29 11:07:38 -07:00
Nicola Corti 25605fb6c5 Bump version to 0.0.2
Summary:
Publishing a new version of the Gradle plugin as we need to distribute some
changes before releasing the playbook to the public.

Changelog:
[Internal] [Changed] - Bump react-native-gradle-plugin to 0.0.2

Reviewed By: ShikaSD

Differential Revision: D31957686

fbshipit-source-id: ef6742a205f2b568714c349dcb6481af33254b9b
2021-10-27 10:20:14 -07:00
Nicola Corti 3dff1fabdd Do not publish tests inside the npm package
Summary:
I'm removing the `src/test` folder from the npm bundle as it's not really
needed for the sake of distributing the gradle plugin.

Changelog:
[Internal] [Changed] - Do not publish tests inside the react-native-gradle-plugin npm package

Reviewed By: ShikaSD

Differential Revision: D31956449

fbshipit-source-id: b84138d24a7c51c44b92ebfc84f35afb3668dee5
2021-10-27 09:48:08 -07:00
Geraint White d2c10da5d5 Add bundleForVariant option (#32472)
Summary:
Ref https://github.com/facebook/react-native/pull/30606#issuecomment-948458552

## Changelog

[Android] [Added] - Add bundleForVariant option

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

Test Plan:
I added the following log into react.gradle and ran the Android build for my app:

```
println("bundleEnabled: ${targetName}, ${bundleForVariant(variant)}")
```

```
# build.gradle

project.ext.react = [
    entryFile: "index.android.js",
    enableHermes: true,  // clean and rebuild if changing
    bundleForVariant: {
         def variant -> variant.name.toLowerCase().contains('release') || variant.name.toLowerCase().contains('live')
    },
]

...

flavorDimensions 'branding'
productFlavors {
    cve {
        dimension 'branding'
    }
    whce {
        dimension 'branding'
    }
}
```

Console output:

```
Reading env from: env/cve/live
bundleEnabled: CveDebug, false
bundleEnabled: CveRelease, true
bundleEnabled: CveLive, true
bundleEnabled: WhceDebug, false
bundleEnabled: WhceRelease, true
bundleEnabled: WhceLive, true
```

Reviewed By: cortinico, ryancat

Differential Revision: D31910406

Pulled By: ShikaSD

fbshipit-source-id: baca5efaddedddad15d974cc7bb8f3c2a4c4f35b
2021-10-26 04:59:16 -07:00
Geraint White 055ea9c7b7 Fix devDisabledInStaging not working with multiple productFlavors (#30606)
Summary:
Fixes https://github.com/facebook/react-native/issues/27052

Since react-native 0.62, the `devDisabledIn${buildType}` syntax has stopped working for apps with multiple `productFlavors`. This PR adds the `disableDevForVariant` lambda to allow dev mode to be disabled for different variants.

## 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 devDisabledIn not working with multiple productFlavors

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

Test Plan:
I added the following log into `react.gradle` and ran the Android build for my app:

```
println("devEnabled: ${targetName}, ${devEnabled}")
```

```
# build.gradle

project.ext.react = [
    entryFile: "index.android.js",
    enableHermes: true,  // clean and rebuild if changing
    bundleInLive: true,
    disableDevForVariant: {
         def variant -> variant.name.toLowerCase().contains('release') || variant.name.toLowerCase().contains('live')
    },
]

...

flavorDimensions 'branding'
productFlavors {
    cve {
        dimension 'branding'
    }
    whce {
        dimension 'branding'
    }
}
```

Console output:

```
Reading env from: env/cve/live
devEnabled: CveDebug, true
devEnabled: CveRelease, false
devEnabled: CveLive, false
devEnabled: WhceDebug, true
devEnabled: WhceRelease, false
devEnabled: WhceLive, false
```

Reviewed By: cortinico

Differential Revision: D31649977

Pulled By: ShikaSD

fbshipit-source-id: 520734314f4bca7608b8dca67c7c5ce0be6d31a5
2021-10-25 08:11:40 -07:00
Nicola Corti 30df66c648 Use explicit codegen path in ReactAndroid
Summary:
This Diff is adapting the codegen configuration for ReactAndroid
to specify a path for the codegen package. I've used the `findNodeModulePath`
so this will work for both:
* The top level OSS project as `node_modules` will be at the top level
* The scenario where ReactAndroid will be included and built from source (as `node_modules` is in the `..` folder).

Changelog:
[Internal] [Changed] - Use explicit codegen path in ReactAndroid

Reviewed By: mdvacca

Differential Revision: D31730920

fbshipit-source-id: 6637da5d0098114f4379bcaeb8a40e976c46f194
2021-10-20 09:34:06 -07:00
Nicola Corti e5ad0b403e useJavaGenerator output should override the react-native-codegen one
Summary:
Turns out that the Java generator is (as expected) outputting only Java code.
Therefore the C++ and the Markdown files are still generated by `react-native-codegen`.
I'm updating the logic to make sure the Java generator is not mutually exclusive and
overrides the output of `react-native-codegen`

Changelog:
[Internal] [Changed] - useJavaGenerator output should override the react-native-codegen one

Reviewed By: sshic

Differential Revision: D31754428

fbshipit-source-id: 3e6dae8212fbfebd28247ec17e88243871265808
2021-10-20 06:11:20 -07:00
Nicola Corti bc93fefe13 Refactor Extract Headers and JNI from AARs to an internal task (#32426)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32426

This diff refactors the extractHeader and extractJni tasks to a single Gradle task in the `.internal` package.
The reason for this change is that those two tasks were always running, therefore invalidating the
whole native build cache.

Changelog:
[Internal] [Changed] - Refactor Extract Headers and JNI from AARs to an internal task

Reviewed By: mdvacca, ShikaSD

Differential Revision: D31682942

fbshipit-source-id: 191cc77902e82c0425949cee743d240ded790137
2021-10-18 04:34:43 -07:00
Nicola Corti 75b2e5cc97 Export prepareJSC to an internal task (#32427)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32427

This diff refactors the `prepareJSC` task to a separate Gradle task in the `.internal` package.

The reason for this change is that `prepareJSC` was just a plain `Task` and not a `Copy` task.
It was defining a top level `doLast` action and would result in being
invalidated whenever the `build.gradle` file would change. This means that the JSC headers/source files
would have been extracted again, effectively invalidating the timestamps for the native build.

Changelog:
[Internal] [Changed] - Export prepareJSC to an internal task

Reviewed By: ShikaSD

Differential Revision: D31682293

fbshipit-source-id: 3d4cd9d9ce2fcd45e61f3c8c6685b69a622a1912
2021-10-18 04:34:43 -07:00
Nicola Corti 52b0cc0355 Export prepareBoost to an internal task (#32424)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32424

This diff refactors the `prepareBoost` task to a separate Gradle task in the `.internal` package.
The reason for this change is that `prepareBoost` was defining a `doLast` action and would result in being
invalidated whenever the `build.gradle` file would change. This means that the Boost headers/source files
would have been extracted again, effectively invalidating the timestamps for the native build.

Changelog:
[Internal] [Changed] - Export prepareBoost to an internal task

Reviewed By: ShikaSD

Differential Revision: D31662120

fbshipit-source-id: 87ba82c634da832ee54c3d13561df45d3fd71381
2021-10-18 04:34:43 -07:00
Nicola Corti bb981b2055 Export prepareLibevent to an internal task (#32425)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32425

This diff refactors the `prepareLibevent` task to a separate Gradle task in the `.internal` package.
The reason for this change is that `prepareLibevent` was defining a `doLast` action and would result in being
invalidated whenever the `build.gradle` file would change. This means that the Libevent headers/source files
would have been extracted again, effectively invalidating the timestamps for the native build.

Changelog:
[Internal] [Changed] - Export prepareLibevent to an internal task

Reviewed By: ShikaSD

Differential Revision: D31661988

fbshipit-source-id: e55c2179a187fa156f701c25bae3b48a796e2660
2021-10-18 04:34:43 -07:00
Nicola Corti c3e7ea0b5b Export prepareGlog to an internal task (#32421)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32421

This diff refactors the `prepareGlog` task to a separate Gradle task in the `.internal` package.
The reason for this change is that `prepareGlog` was defining a `doLast` action and would result in being
invalidated whenever the `build.gradle` file would change. This means that the Glog headers/source files
would have been extracted again, effectively invalidating the timestamps for the native build.

Changelog:
[Internal] [Changed] - Export prepareGlog to an internal task

Reviewed By: ShikaSD

Differential Revision: D31661668

fbshipit-source-id: efcd5505a67d6c9f02fcab7a5c3255a160215661
2021-10-18 04:34:43 -07:00
Nicola Corti a2b5e4cd82 Fix enableVmCleanup not working for apps with product flavors. (#32422)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32422

While working on the NDK AGP Api I realized that the `enableVmCleanup` function,
that is supposed to cleanup the extra `.so` files from the final artifacts, is broken
for apps with variants. Specifically say for a `liteDebug` app it tries to search for `.so` files inside:

```
intermediates/stripped_native_libs/lite/debug/out/lib
```

while the `.so` files are located inside:

```
intermediates/stripped_native_libs/liteDebug/out/lib
```

I've fixed changing the token of the path from `targetPath` to `variant.name`

Changelog:
[Android] [Fixed] - Fix enableVmCleanup not working for apps with product flavors

Reviewed By: ShikaSD

Differential Revision: D31654704

fbshipit-source-id: 4af3478a3079ebcde4bd8e0c62bf4df7b6c75c0f
2021-10-18 04:34:43 -07:00
Nicola Corti 79e72e05ce Fix applyAppPlugin being accessed too early in the React App Gradle Plugin (#32420)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32420

While working on the NDK AGP Apis, I realized the the `applyAppPlugin` is accessed
too early inside the Gradle plugin. Specifically is accessed once the plugin is applied,
and the extension is not configured afterwards. This means that the extension is always set
the default values.

I'm fixing it moving it inside the `project.afterEvaluate` that was already need to access
the variant informations.

Changelog:
[Internal] [Changed] - Fix applyAppPlugin being accessed too early in the React App Gradle Plugin

Reviewed By: ShikaSD

Differential Revision: D31652984

fbshipit-source-id: e7ead3f8acb24372bf953fd90ad2a5dfbbeeeec0
2021-10-18 04:34:43 -07:00
CodemodService FBSourceKtfmtLinterBot 689bfed9f1 Daily `arc lint --take KTFMT`
Reviewed By: zertosh

Differential Revision: D31647300

fbshipit-source-id: b0374baa40ff01d3ef6174d348e1c7793cb7bcaf
2021-10-14 04:47:38 -07:00
Desmond Ng 943f86272d Revert D31636434: Daily `arc lint --take KTFMT`
Differential Revision:
D31636434 (2bced60851)

Original commit changeset: 4632cdc1bfd3

fbshipit-source-id: 7810fcba547d091e5014d6a3f70af7779e9a2aa1
2021-10-13 20:37:57 -07:00
CodemodService FBSourceKtfmtLinterBot 2bced60851 Daily `arc lint --take KTFMT`
Reviewed By: zertosh

Differential Revision: D31636434

fbshipit-source-id: 4632cdc1bfd3eb398079fa3c7c3791783f30515f
2021-10-13 19:55:30 -07:00
Geraint White 91adb761cf Add hermesFlagsForVariant and deleteDebugFilesForVariant (#32281)
Summary:
Ref https://github.com/facebook/react-native/issues/25601#issuecomment-510856047.

From https://github.com/facebook/react-native/pull/31040.

The `hermesFlagsRelease` option only works with the release build type, but not with other build types.

This PR allows hermes flags on a per variant basis to be specified using the `hermesFlagsForVariant` lambda.

It also allows the hermes debugger cleanup to be run on a per variant basis using the `deleteDebugFilesForVariant` lambda.

## 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 hermesFlags not working with multiple variants

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

Test Plan:
Set the following options in `android/app/build.gradle` and ensure warnings are hidden when running `./gradlew assembleRelease` and `./gradlew assembleLive`.

```
    hermesFlagsForVariant: {
        def v -> v.name.toLowerCase().contains('release') || v.name.toLowerCase().contains('live') ? ['-w'] : []
    },
    deleteDebugFilesForVariant: {
        def v -> v.name.toLowerCase().contains('release') || v.name.toLowerCase().contains('live')
    },
```

Reviewed By: cortinico

Differential Revision: D31234241

Pulled By: ShikaSD

fbshipit-source-id: 2cb3dd63adbcd023061076b5a3b262a87b470518
2021-10-13 12:50:25 -07:00
svbutko 9ae3367431 Bump Kotlin and Gradle versions (#32319)
Summary:
Bump Kotlin version to 1.5.31 to include following changes:

https://kotlinlang.org/docs/whatsnew15.html
https://kotlinlang.org/docs/whatsnew1520.html
https://kotlinlang.org/docs/whatsnew1530.html

Primarily:
- Native support for Apple silicon
- Kotlin/JS IR backend reaches Beta
- Improved Gradle plugin experience
- Performance improvements

## 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] [Changed] - Bump Kotlin version to 1.5.31
[Android] [Changed] - Bump Gradle version to 7.2

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

Reviewed By: yungsters

Differential Revision: D31365479

Pulled By: cortinico

fbshipit-source-id: 1ffaef1222a6ada8ebc746267b2a22561c3c770f
2021-10-13 06:02:18 -07:00
CodemodService FBSourceKtfmtLinterBot 3516090174 Daily `arc lint --take KTFMT`
Reviewed By: zertosh

Differential Revision: D31225996

fbshipit-source-id: bf4c27edf42c86d3e71b3ae734307025a5203ce9
2021-09-27 20:20:27 -07:00
Nicola Corti 9db0fbb697 Add a README before publishing this package
Summary:
Before we can publish `0.0.1` of `react-native-gradle-plugin`, we
need to write a README file for it.

Changelog:
[Internal] [Changed] - Add a README before publishing the react-native-gradle-plugin

Reviewed By: ShikaSD

Differential Revision: D31206204

fbshipit-source-id: 0168298d04d4619dde931eb75d9555982f50fffe
2021-09-27 09:23:33 -07:00
Nicola Corti 25573db4b9 Renamed Gradle Plugint to `React`
Summary:
Removing the App postfix from the plugin as that is
a result of the merging. This aligns the plugin ID to the plugin
class name.

Changelog:
[Internal] [Changed] - Renamed Gradle Plugint to `React`

Reviewed By: ShikaSD

Differential Revision: D31205318

fbshipit-source-id: 23cd24c91fa8526137045e8537f03f560be939cb
2021-09-27 08:22:44 -07:00
enniel 6f126740fa gradle vm cleanup fix (#32257)
Summary:
This patch remove unused .so files for reduce android .apk and .aab

## Changelog

- [Android] [Fixed] - Exclude unused .so files for reduce android .apk and .aab

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

Test Plan:
I have created a repository for testing:
https://github.com/enniel/react-native-invalid-build-example

That lines includes patch for fix bug:
f195ecdbea/android/app/react.gradle (L331-L385)

```sh
git clone https://github.com/enniel/react-native-invalid-build-example
cd react-native-invalid-build-example
npm i
```

debug, hermes disabled, without patch
```sh
git switch hermes-disabled-without-patch
npm run build:android:debug:apk
```
open android/app/build/outputs/apk/debug/app-debug.apk in android studio

![debug-hermes-disabled-without-patch](https://user-images.githubusercontent.com/19760944/134640636-1505cfa4-0be9-4bb8-8130-74af01ebfd94.png)

debug, hermes enabled, without patch
```sh
git switch hermes-enabled-without-patch
npm run build:android:debug:apk
```
open android/app/build/outputs/apk/debug/app-debug.apk in android studio

![debug-hermes-enabled-without-patch](https://user-images.githubusercontent.com/19760944/134640743-f5730fbe-433f-45eb-a87c-e0e2eadb056b.png)

debug, hermes disabled, with patch
```sh
git switch hermes-disabled-with-patch
npm run build:android:debug:apk
```
open android/app/build/outputs/apk/debug/app-debug.apk in android studio

![debug-hermes-disabled-with-patch](https://user-images.githubusercontent.com/19760944/134640895-36f294ae-36fb-40b7-a767-f6b421fdbabd.png)

debug, hermes enabled, with patch
```sh
git switch hermes-enabled-with-patch
npm run build:android:debug:apk
```
open android/app/build/outputs/apk/debug/app-debug.apk in android studio

![debug-hermes-enabled-with-patch](https://user-images.githubusercontent.com/19760944/134641040-f4f08755-5234-4567-849d-0b815d58bc15.png)

release, hermes disabled, without patch
```sh
git switch hermes-disabled-without-patch
npm run build:android:release:apk
```
open android/app/build/outputs/apk/release/app-release.apk in android studio

![release-hermes-disabled-without-patch](https://user-images.githubusercontent.com/19760944/134641255-da3ccc5f-91e2-4b12-b0b2-1590fa13e5ce.png)

release, hermes enabled, without patch
```sh
git switch hermes-enabled-without-patch
npm run build:android:release:apk
```
open android/app/build/outputs/apk/release/app-release.apk in android studio

![release-hermes-enabled-without-patch](https://user-images.githubusercontent.com/19760944/134641396-f2ca3178-4225-4de7-b1f7-b741edba1877.png)

release, hermes disabled, with patch
```sh
git switch hermes-disabled-with-patch
npm run build:android:release:apk
```
open android/app/build/outputs/apk/release/app-release.apk in android studio

![release-hermes-disabled-with-patch](https://user-images.githubusercontent.com/19760944/134641675-b967df44-af1b-4070-9f84-a2f029381a39.png)

release, hermes enabled, with patch
```sh
git switch hermes-enabled-with-patch
npm run build:android:release:apk
```
open android/app/build/outputs/apk/release/app-release.apk in android studio

![release-hermes-enabled-with-patch](https://user-images.githubusercontent.com/19760944/134641737-aa4a435a-1fe2-4107-8bbd-8dadda24aebd.png)

Reviewed By: cortinico

Differential Revision: D31167423

Pulled By: ShikaSD

fbshipit-source-id: 4026df818c57fa699526ca1c31c1d1a68d58baef
2021-09-27 06:54:32 -07:00
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