Files
react-native/packages/react-native-codegen/android/build.gradle
T
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

75 lines
2.3 KiB
Groovy

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import org.apache.tools.ant.taskdefs.condition.Os
plugins {
id 'java-gradle-plugin'
}
repositories {
mavenLocal()
google()
mavenCentral()
}
dependencies {
implementation 'com.android.tools.build:gradle:4.2.2'
// Use the same Gson version that `com.android.tools.build:gradle` depends on.
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.guava:guava:29.0-jre'
implementation 'com.squareup:javapoet:1.13.0'
}
gradlePlugin {
plugins {
codegen {
id = 'com.facebook.react.codegen'
implementationClass = 'com.facebook.react.codegen.plugin.CodegenPlugin'
}
}
}
// This task is required when using react-native-codegen from source, instead of npm.
task('buildCodegenCLI', type: Exec) {
def codegenRoot = "$projectDir/.."
inputs.files(
file("$codegenRoot/scripts"),
file("$codegenRoot/src"),
file("$codegenRoot/package.json"),
file("$codegenRoot/.babelrc"),
file("$codegenRoot/.prettierrc"),
)
def libDir = file("$codegenRoot/lib")
libDir.mkdirs()
def nodeModulesDir = file("$codegenRoot/node_modules")
nodeModulesDir.mkdirs();
outputs.dirs(libDir, nodeModulesDir)
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
// Convert path to Linux format: use canonical path to strip it off relative elements in the middle of the string.
// Then replace baskslashes with slashes, remove leading colon, add leading slash.
// Eg. D:\path1\sub2/.. -> /D/path1/path2
String canonicalPath = new File(codegenRoot).getCanonicalPath()
String linuxPath = canonicalPath.replace('\\', '/');
linuxPath = linuxPath.replace(':', '')
linuxPath = '/' + linuxPath
// Get the location of bash in the system; assume environment variable created to store it.
String bashHome = "$System.env.REACT_WINDOWS_BASH"
if (bashHome == null) {
throw new GradleException("REACT_WINDOWS_BASH is not defined.")
}
commandLine(bashHome, "-c", "$linuxPath/scripts/oss/build.sh")
}
else {
commandLine("$codegenRoot/scripts/oss/build.sh")
}
}