@ohos-ports/react-native-gradle-plugin 0.71.19-beta.0 → 0.86.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -4
- package/build.gradle.kts +33 -41
- package/gradle/libs.versions.toml +22 -0
- package/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/gradle/wrapper/gradle-wrapper.properties +3 -1
- package/gradle.properties +2 -0
- package/gradlew +32 -18
- package/gradlew.bat +22 -18
- package/package.json +21 -11
- package/react-native-gradle-plugin/README.md +17 -0
- package/react-native-gradle-plugin/build.gradle.kts +83 -0
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/ReactExtension.kt +78 -10
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +320 -0
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactRootProjectPlugin.kt +86 -0
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/TaskConfiguration.kt +36 -25
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/internal/PrivateReactExtension.kt +11 -4
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt +60 -50
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateAutolinkingNewArchitecturesFileTask.kt +252 -0
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt +8 -3
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/GenerateCodegenSchemaTask.kt +11 -18
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateEntryPointTask.kt +108 -0
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GeneratePackageListTask.kt +214 -0
- package/{src/main/kotlin/com/facebook/react/tasks → react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal}/BuildCodegenCLITask.kt +24 -17
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal/CustomExecTask.kt +46 -0
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareBoostTask.kt +10 -4
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/internal/PrepareGflagsTask.kt +119 -0
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PrepareGlogTask.kt +26 -18
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/PreparePrefabHeadersTask.kt +28 -12
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/tasks/internal/utils/PrefabPreprocessingEntry.kt +4 -3
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt +163 -0
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt +71 -0
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt +299 -0
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/JdkConfiguratorUtils.kt +64 -0
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt +59 -65
- package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/PathUtils.kt +44 -30
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/ProjectUtils.kt +119 -0
- package/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/PropertyUtils.kt +96 -0
- package/settings-plugin/build.gradle.kts +73 -0
- package/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsExtension.kt +217 -0
- package/settings-plugin/src/main/kotlin/com/facebook/react/ReactSettingsPlugin.kt +23 -0
- package/settings-plugin/src/test/kotlin/com/facebook/react/ReactSettingsExtensionTest.kt +475 -0
- package/settings.gradle.kts +10 -1
- package/shared/build.gradle.kts +52 -0
- package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingAndroidProjectJson.kt +18 -0
- package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingConfigJson.kt +14 -0
- package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingDependenciesJson.kt +18 -0
- package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingDependenciesPlatformAndroidJson.kt +23 -0
- package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingDependenciesPlatformJson.kt +12 -0
- package/shared/src/main/kotlin/com/facebook/react/model/ModelAutolinkingProjectJson.kt +10 -0
- package/{src → shared/src}/main/kotlin/com/facebook/react/model/ModelCodegenConfig.kt +2 -1
- package/{src → shared/src}/main/kotlin/com/facebook/react/model/ModelPackageJson.kt +1 -1
- package/shared/src/main/kotlin/com/facebook/react/utils/JsonUtils.kt +43 -0
- package/shared/src/main/kotlin/com/facebook/react/utils/KotlinStdlibCompatUtils.kt +32 -0
- package/{src → shared/src}/main/kotlin/com/facebook/react/utils/Os.kt +7 -6
- package/{src → shared/src}/main/kotlin/com/facebook/react/utils/TaskUtils.kt +4 -5
- package/shared/src/test/kotlin/com/facebook/react/utils/JsonUtilsTest.kt +382 -0
- package/shared/src/test/kotlin/com/facebook/react/utils/KotlinStdlibCompatUtilsTest.kt +82 -0
- package/shared/src/test/kotlin/com/facebook/react/utils/OsTest.kt +87 -0
- package/shared/src/test/kotlin/com/facebook/react/utils/TaskUtilsTest.kt +76 -0
- package/shared-testutil/build.gradle.kts +46 -0
- package/shared-testutil/src/main/kotlin/com/facebook/react/tests/OsRule.kt +52 -0
- package/shared-testutil/src/main/kotlin/com/facebook/react/tests/WithOs.kt +17 -0
- package/build/libs/react-native-gradle-plugin.jar +0 -0
- package/index.js +0 -73
- package/src/main/kotlin/com/facebook/react/ReactPlugin.kt +0 -212
- package/src/main/kotlin/com/facebook/react/tasks/internal/PrepareJSCTask.kt +0 -50
- package/src/main/kotlin/com/facebook/react/tasks/internal/PrepareLibeventTask.kt +0 -51
- package/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt +0 -54
- package/src/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt +0 -48
- package/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt +0 -109
- package/src/main/kotlin/com/facebook/react/utils/JsonUtils.kt +0 -21
- package/src/main/kotlin/com/facebook/react/utils/ProjectUtils.kt +0 -55
- /package/{src → react-native-gradle-plugin/src}/main/kotlin/com/facebook/react/utils/FileUtils.kt +0 -0
- /package/{src → shared/src}/main/kotlin/com/facebook/react/model/ModelCodegenConfigAndroid.kt +0 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
package com.facebook.react.utils
|
|
9
|
+
|
|
10
|
+
import com.facebook.react.tests.OS
|
|
11
|
+
import com.facebook.react.tests.OsRule
|
|
12
|
+
import com.facebook.react.tests.WithOs
|
|
13
|
+
import org.assertj.core.api.Assertions.assertThat
|
|
14
|
+
import org.junit.Rule
|
|
15
|
+
import org.junit.Test
|
|
16
|
+
|
|
17
|
+
class TaskUtilsTest {
|
|
18
|
+
|
|
19
|
+
@get:Rule val osRule = OsRule()
|
|
20
|
+
|
|
21
|
+
@Test
|
|
22
|
+
fun windowsAwareCommandLine_withEmptyInput_isEmpty() {
|
|
23
|
+
assertThat(windowsAwareCommandLine().isEmpty()).isTrue()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Test
|
|
27
|
+
fun windowsAwareCommandLine_withList_isEqualAsVararg() {
|
|
28
|
+
assertThat(windowsAwareCommandLine(listOf("a", "b", "c")))
|
|
29
|
+
.isEqualTo(windowsAwareCommandLine("a", "b", "c"))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Test
|
|
33
|
+
@WithOs(OS.MAC)
|
|
34
|
+
fun windowsAwareCommandLine_onMac_returnsTheList() {
|
|
35
|
+
assertThat(listOf("a", "b", "c")).isEqualTo(windowsAwareCommandLine("a", "b", "c"))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Test
|
|
39
|
+
@WithOs(OS.LINUX)
|
|
40
|
+
fun windowsAwareCommandLine_onLinux_returnsTheList() {
|
|
41
|
+
assertThat(listOf("a", "b", "c")).isEqualTo(windowsAwareCommandLine("a", "b", "c"))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Test
|
|
45
|
+
@WithOs(OS.WIN)
|
|
46
|
+
fun windowsAwareCommandLine_onWindows_prependsCmd() {
|
|
47
|
+
assertThat(listOf("cmd", "/c", "a", "b", "c")).isEqualTo(windowsAwareCommandLine("a", "b", "c"))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Test
|
|
51
|
+
@WithOs(OS.MAC)
|
|
52
|
+
fun windowsAwareBashCommandLine_onMac_returnsTheList() {
|
|
53
|
+
assertThat(listOf("a", "b", "c"))
|
|
54
|
+
.isEqualTo(windowsAwareBashCommandLine("a", "b", "c", bashWindowsHome = "abc"))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Test
|
|
58
|
+
@WithOs(OS.LINUX)
|
|
59
|
+
fun windowsAwareBashCommandLine_onLinux_returnsTheList() {
|
|
60
|
+
assertThat(listOf("a", "b", "c")).isEqualTo(windowsAwareBashCommandLine("a", "b", "c"))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Test
|
|
64
|
+
@WithOs(OS.WIN)
|
|
65
|
+
fun windowsAwareBashCommandLine_onWindows_prependsBash() {
|
|
66
|
+
assertThat(listOf("bash", "-c", "a", "b", "c"))
|
|
67
|
+
.isEqualTo(windowsAwareBashCommandLine("a", "b", "c"))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Test
|
|
71
|
+
@WithOs(OS.WIN)
|
|
72
|
+
fun windowsAwareBashCommandLine_onWindows_prependsCustomBashPath() {
|
|
73
|
+
assertThat(listOf("/custom/bash", "-c", "a", "b", "c"))
|
|
74
|
+
.isEqualTo(windowsAwareBashCommandLine("a", "b", "c", bashWindowsHome = "/custom/bash"))
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
|
9
|
+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
|
10
|
+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
|
11
|
+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
12
|
+
|
|
13
|
+
plugins {
|
|
14
|
+
alias(libs.plugins.kotlin.jvm)
|
|
15
|
+
alias(libs.plugins.ktfmt)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
repositories { mavenCentral() }
|
|
19
|
+
|
|
20
|
+
group = "com.facebook.react"
|
|
21
|
+
|
|
22
|
+
dependencies { implementation(libs.junit) }
|
|
23
|
+
|
|
24
|
+
java { targetCompatibility = JavaVersion.VERSION_11 }
|
|
25
|
+
|
|
26
|
+
kotlin { jvmToolchain(26) }
|
|
27
|
+
|
|
28
|
+
tasks.withType<KotlinCompile>().configureEach {
|
|
29
|
+
compilerOptions {
|
|
30
|
+
apiVersion.set(KotlinVersion.KOTLIN_1_8)
|
|
31
|
+
// See comment above on JDK 11 support
|
|
32
|
+
jvmTarget.set(JvmTarget.JVM_11)
|
|
33
|
+
allWarningsAsErrors.set(
|
|
34
|
+
project.properties["enableWarningsAsErrors"]?.toString()?.toBoolean() ?: false
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
tasks.withType<Test>().configureEach {
|
|
40
|
+
testLogging {
|
|
41
|
+
exceptionFormat = TestExceptionFormat.FULL
|
|
42
|
+
showExceptions = true
|
|
43
|
+
showCauses = true
|
|
44
|
+
showStackTraces = true
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
package com.facebook.react.tests
|
|
9
|
+
|
|
10
|
+
import org.junit.rules.TestRule
|
|
11
|
+
import org.junit.runner.Description
|
|
12
|
+
import org.junit.runners.model.Statement
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A JUnit [TestRule] to override values of [System.getProperties] with the support of the [WithOs]
|
|
16
|
+
* annotation.
|
|
17
|
+
*/
|
|
18
|
+
class OsRule : TestRule {
|
|
19
|
+
|
|
20
|
+
private var retainOs: String? = null
|
|
21
|
+
private var retainArch: String? = null
|
|
22
|
+
|
|
23
|
+
override fun apply(statement: Statement, description: Description): Statement {
|
|
24
|
+
return object : Statement() {
|
|
25
|
+
override fun evaluate() {
|
|
26
|
+
val annotation = description.annotations.filterIsInstance<WithOs>().firstOrNull()
|
|
27
|
+
|
|
28
|
+
annotation?.os?.propertyName?.let { osName ->
|
|
29
|
+
retainOs = System.getProperty(OS_NAME_KEY)
|
|
30
|
+
System.setProperty(OS_NAME_KEY, osName)
|
|
31
|
+
}
|
|
32
|
+
annotation?.arch?.let { arch ->
|
|
33
|
+
if (arch.isNotBlank()) {
|
|
34
|
+
retainArch = System.getProperty(OS_ARCH_KEY)
|
|
35
|
+
System.setProperty(OS_ARCH_KEY, arch)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
statement.evaluate()
|
|
40
|
+
} finally {
|
|
41
|
+
retainOs?.let { System.setProperty(OS_NAME_KEY, it) }
|
|
42
|
+
retainArch?.let { System.setProperty(OS_ARCH_KEY, it) }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
companion object {
|
|
49
|
+
const val OS_NAME_KEY = "os.name"
|
|
50
|
+
const val OS_ARCH_KEY = "os.arch"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
package com.facebook.react.tests
|
|
9
|
+
|
|
10
|
+
/** Annotation to specify an Operating System to override the "os.name" System Property. */
|
|
11
|
+
@Retention(AnnotationRetention.RUNTIME) annotation class WithOs(val os: OS, val arch: String = "")
|
|
12
|
+
|
|
13
|
+
enum class OS(val propertyName: String) {
|
|
14
|
+
WIN("Windows"),
|
|
15
|
+
MAC("MacOs"),
|
|
16
|
+
LINUX("Linux"),
|
|
17
|
+
}
|
|
Binary file
|
package/index.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* react-native-gradle-plugin Node.js entry point
|
|
3
|
-
*
|
|
4
|
-
* This package is a Gradle/Kotlin build plugin for React Native.
|
|
5
|
-
* It is compiled to a JAR file and loaded via the JVM/Gradle runtime.
|
|
6
|
-
* This JS entry point provides a bridge to invoke the Gradle plugin
|
|
7
|
-
* from Node.js using the available JVM and Gradle toolchain.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const { execSync } = require('child_process');
|
|
11
|
-
const path = require('path');
|
|
12
|
-
const fs = require('fs');
|
|
13
|
-
|
|
14
|
-
// Locate the compiled JAR
|
|
15
|
-
const jarPath = path.join(__dirname, 'build', 'libs', 'react-native-gradle-plugin.jar');
|
|
16
|
-
|
|
17
|
-
// Package metadata
|
|
18
|
-
const pkg = require('./package.json');
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Get the path to the compiled Gradle plugin JAR.
|
|
22
|
-
* @returns {string} Absolute path to the JAR file
|
|
23
|
-
*/
|
|
24
|
-
function getJarPath() {
|
|
25
|
-
return jarPath;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Check if the JAR has been compiled and is available.
|
|
30
|
-
* @returns {boolean} True if the JAR exists
|
|
31
|
-
*/
|
|
32
|
-
function isCompiled() {
|
|
33
|
-
return fs.existsSync(jarPath);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Run the Gradle plugin via the Gradle build tool.
|
|
38
|
-
* This invokes the Gradle build system with the React Native plugin applied.
|
|
39
|
-
*
|
|
40
|
-
* @param {Object} options - Options for the Gradle invocation
|
|
41
|
-
* @param {string} options.projectDir - Directory of the project to build
|
|
42
|
-
* @param {string[]} options.tasks - Gradle tasks to execute
|
|
43
|
-
* @param {Object} options.gradleProps - Additional Gradle properties
|
|
44
|
-
* @returns {string} Output of the Gradle command
|
|
45
|
-
*/
|
|
46
|
-
function runGradle(options = {}) {
|
|
47
|
-
const projectDir = options.projectDir || process.cwd();
|
|
48
|
-
const tasks = options.tasks || ['assembleRelease'];
|
|
49
|
-
const gradleCmd = process.env.GRADLE_CMD || 'gradle';
|
|
50
|
-
const args = [gradleCmd, ...tasks, '-p', projectDir];
|
|
51
|
-
|
|
52
|
-
if (options.gradleProps) {
|
|
53
|
-
for (const [key, value] of Object.entries(options.gradleProps)) {
|
|
54
|
-
args.push(`-P${key}=${value}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const cmd = args.join(' ');
|
|
59
|
-
return execSync(cmd, {
|
|
60
|
-
cwd: projectDir,
|
|
61
|
-
encoding: 'utf-8',
|
|
62
|
-
stdio: 'pipe',
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
module.exports = {
|
|
67
|
-
name: pkg.name,
|
|
68
|
-
version: pkg.version,
|
|
69
|
-
description: pkg.description,
|
|
70
|
-
getJarPath,
|
|
71
|
-
isCompiled,
|
|
72
|
-
runGradle,
|
|
73
|
-
};
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
package com.facebook.react
|
|
9
|
-
|
|
10
|
-
import com.android.build.api.variant.AndroidComponentsExtension
|
|
11
|
-
import com.android.build.gradle.AppExtension
|
|
12
|
-
import com.android.build.gradle.internal.tasks.factory.dependsOn
|
|
13
|
-
import com.facebook.react.internal.PrivateReactExtension
|
|
14
|
-
import com.facebook.react.tasks.BuildCodegenCLITask
|
|
15
|
-
import com.facebook.react.tasks.GenerateCodegenArtifactsTask
|
|
16
|
-
import com.facebook.react.tasks.GenerateCodegenSchemaTask
|
|
17
|
-
import com.facebook.react.utils.AgpConfiguratorUtils.configureBuildConfigFields
|
|
18
|
-
import com.facebook.react.utils.AgpConfiguratorUtils.configureDevPorts
|
|
19
|
-
import com.facebook.react.utils.BackwardCompatUtils.configureBackwardCompatibilityReactMap
|
|
20
|
-
import com.facebook.react.utils.DependencyUtils.configureDependencies
|
|
21
|
-
import com.facebook.react.utils.DependencyUtils.configureRepositories
|
|
22
|
-
import com.facebook.react.utils.DependencyUtils.readVersionAndGroupStrings
|
|
23
|
-
import com.facebook.react.utils.JsonUtils
|
|
24
|
-
import com.facebook.react.utils.NdkConfiguratorUtils.configureReactNativeNdk
|
|
25
|
-
import com.facebook.react.utils.ProjectUtils.needsCodegenFromPackageJson
|
|
26
|
-
import com.facebook.react.utils.findPackageJsonFile
|
|
27
|
-
import java.io.File
|
|
28
|
-
import kotlin.system.exitProcess
|
|
29
|
-
import org.gradle.api.Plugin
|
|
30
|
-
import org.gradle.api.Project
|
|
31
|
-
import org.gradle.api.Task
|
|
32
|
-
import org.gradle.internal.jvm.Jvm
|
|
33
|
-
|
|
34
|
-
class ReactPlugin : Plugin<Project> {
|
|
35
|
-
override fun apply(project: Project) {
|
|
36
|
-
checkJvmVersion(project)
|
|
37
|
-
val extension = project.extensions.create("react", ReactExtension::class.java, project)
|
|
38
|
-
|
|
39
|
-
// We register a private extension on the rootProject so that project wide configs
|
|
40
|
-
// like codegen config can be propagated from app project to libraries.
|
|
41
|
-
val rootExtension =
|
|
42
|
-
project.rootProject.extensions.findByType(PrivateReactExtension::class.java)
|
|
43
|
-
?: project.rootProject.extensions.create(
|
|
44
|
-
"privateReact", PrivateReactExtension::class.java, project)
|
|
45
|
-
|
|
46
|
-
// App Only Configuration
|
|
47
|
-
project.pluginManager.withPlugin("com.android.application") {
|
|
48
|
-
// We wire the root extension with the values coming from the app (either user populated or
|
|
49
|
-
// defaults).
|
|
50
|
-
rootExtension.root.set(extension.root)
|
|
51
|
-
rootExtension.reactNativeDir.set(extension.reactNativeDir)
|
|
52
|
-
rootExtension.codegenDir.set(extension.codegenDir)
|
|
53
|
-
rootExtension.nodeExecutableAndArgs.set(extension.nodeExecutableAndArgs)
|
|
54
|
-
|
|
55
|
-
project.afterEvaluate {
|
|
56
|
-
val reactNativeDir = extension.reactNativeDir.get().asFile
|
|
57
|
-
val propertiesFile = File(reactNativeDir, "ReactAndroid/gradle.properties")
|
|
58
|
-
val versionAndGroupStrings = readVersionAndGroupStrings(propertiesFile)
|
|
59
|
-
val versionString = versionAndGroupStrings.first
|
|
60
|
-
val groupString = versionAndGroupStrings.second
|
|
61
|
-
configureDependencies(project, versionString, groupString)
|
|
62
|
-
configureRepositories(project, reactNativeDir)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
configureReactNativeNdk(project, extension)
|
|
66
|
-
configureBuildConfigFields(project)
|
|
67
|
-
configureDevPorts(project)
|
|
68
|
-
configureBackwardCompatibilityReactMap(project)
|
|
69
|
-
|
|
70
|
-
project.extensions.getByType(AndroidComponentsExtension::class.java).apply {
|
|
71
|
-
onVariants(selector().all()) { variant ->
|
|
72
|
-
project.configureReactTasks(variant = variant, config = extension)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// This is a legacy AGP api. Needed as AGP 7.3 is not consuming generated resources correctly.
|
|
77
|
-
// Can be removed as we bump to AGP 7.4 stable.
|
|
78
|
-
// This registers the $buildDir/generated/res/react/<variant> folder as a
|
|
79
|
-
// res folder to be consumed with the old AGP Apis which are not broken.
|
|
80
|
-
project.extensions.getByType(AppExtension::class.java).apply {
|
|
81
|
-
this.applicationVariants.all { variant ->
|
|
82
|
-
val isDebuggableVariant =
|
|
83
|
-
extension.debuggableVariants.get().any { it.equals(variant.name, ignoreCase = true) }
|
|
84
|
-
val targetName = variant.name.replaceFirstChar { it.uppercase() }
|
|
85
|
-
val bundleTaskName = "createBundle${targetName}JsAndAssets"
|
|
86
|
-
if (!isDebuggableVariant) {
|
|
87
|
-
variant.registerGeneratedResFolders(
|
|
88
|
-
project.layout.buildDirectory.files("generated/res/react/${variant.name}"))
|
|
89
|
-
variant.mergeResourcesProvider.get().dependsOn(bundleTaskName)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
configureCodegen(project, extension, rootExtension, isLibrary = false)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Library Only Configuration
|
|
97
|
-
project.pluginManager.withPlugin("com.android.library") {
|
|
98
|
-
configureCodegen(project, extension, rootExtension, isLibrary = true)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private fun checkJvmVersion(project: Project) {
|
|
103
|
-
val jvmVersion = Jvm.current()?.javaVersion?.majorVersion
|
|
104
|
-
if ((jvmVersion?.toIntOrNull() ?: 0) <= 8) {
|
|
105
|
-
project.logger.error(
|
|
106
|
-
"""
|
|
107
|
-
|
|
108
|
-
********************************************************************************
|
|
109
|
-
|
|
110
|
-
ERROR: requires JDK11 or higher.
|
|
111
|
-
Incompatible major version detected: '$jvmVersion'
|
|
112
|
-
|
|
113
|
-
********************************************************************************
|
|
114
|
-
|
|
115
|
-
"""
|
|
116
|
-
.trimIndent())
|
|
117
|
-
exitProcess(1)
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** This function sets up `react-native-codegen` in our Gradle plugin. */
|
|
122
|
-
@Suppress("UnstableApiUsage")
|
|
123
|
-
private fun configureCodegen(
|
|
124
|
-
project: Project,
|
|
125
|
-
localExtension: ReactExtension,
|
|
126
|
-
rootExtension: PrivateReactExtension,
|
|
127
|
-
isLibrary: Boolean
|
|
128
|
-
) {
|
|
129
|
-
// First, we set up the output dir for the codegen.
|
|
130
|
-
val generatedSrcDir = File(project.buildDir, "generated/source/codegen")
|
|
131
|
-
|
|
132
|
-
// We specify the default value (convention) for jsRootDir.
|
|
133
|
-
// It's the root folder for apps (so ../../ from the Gradle project)
|
|
134
|
-
// and the package folder for library (so ../ from the Gradle project)
|
|
135
|
-
if (isLibrary) {
|
|
136
|
-
localExtension.jsRootDir.convention(project.layout.projectDirectory.dir("../"))
|
|
137
|
-
} else {
|
|
138
|
-
localExtension.jsRootDir.convention(localExtension.root)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
val buildCodegenTask =
|
|
142
|
-
project.tasks.register("buildCodegenCLI", BuildCodegenCLITask::class.java) {
|
|
143
|
-
it.codegenDir.set(rootExtension.codegenDir)
|
|
144
|
-
val bashWindowsHome = project.findProperty("REACT_WINDOWS_BASH") as String?
|
|
145
|
-
it.bashWindowsHome.set(bashWindowsHome)
|
|
146
|
-
|
|
147
|
-
// Please note that appNeedsCodegen is triggering a read of the package.json at
|
|
148
|
-
// configuration time as we need to feed the onlyIf condition of this task.
|
|
149
|
-
// Therefore, the appNeedsCodegen needs to be invoked inside this lambda.
|
|
150
|
-
val needsCodegenFromPackageJson = project.needsCodegenFromPackageJson(rootExtension.root)
|
|
151
|
-
it.onlyIf { isLibrary || needsCodegenFromPackageJson }
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// We create the task to produce schema from JS files.
|
|
155
|
-
val generateCodegenSchemaTask =
|
|
156
|
-
project.tasks.register(
|
|
157
|
-
"generateCodegenSchemaFromJavaScript", GenerateCodegenSchemaTask::class.java) { it ->
|
|
158
|
-
it.dependsOn(buildCodegenTask)
|
|
159
|
-
it.nodeExecutableAndArgs.set(rootExtension.nodeExecutableAndArgs)
|
|
160
|
-
it.codegenDir.set(rootExtension.codegenDir)
|
|
161
|
-
it.generatedSrcDir.set(generatedSrcDir)
|
|
162
|
-
|
|
163
|
-
// We're reading the package.json at configuration time to properly feed
|
|
164
|
-
// the `jsRootDir` @Input property of this task & the onlyIf. Therefore, the
|
|
165
|
-
// parsePackageJson should be invoked inside this lambda.
|
|
166
|
-
val packageJson = findPackageJsonFile(project, rootExtension.root)
|
|
167
|
-
val parsedPackageJson = packageJson?.let { JsonUtils.fromCodegenJson(it) }
|
|
168
|
-
|
|
169
|
-
val jsSrcsDirInPackageJson = parsedPackageJson?.codegenConfig?.jsSrcsDir
|
|
170
|
-
if (jsSrcsDirInPackageJson != null) {
|
|
171
|
-
it.jsRootDir.set(File(packageJson.parentFile, jsSrcsDirInPackageJson))
|
|
172
|
-
} else {
|
|
173
|
-
it.jsRootDir.set(localExtension.jsRootDir)
|
|
174
|
-
}
|
|
175
|
-
val needsCodegenFromPackageJson =
|
|
176
|
-
project.needsCodegenFromPackageJson(rootExtension.root)
|
|
177
|
-
it.onlyIf { isLibrary || needsCodegenFromPackageJson }
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// We create the task to generate Java code from schema.
|
|
181
|
-
val generateCodegenArtifactsTask =
|
|
182
|
-
project.tasks.register(
|
|
183
|
-
"generateCodegenArtifactsFromSchema", GenerateCodegenArtifactsTask::class.java) {
|
|
184
|
-
it.dependsOn(generateCodegenSchemaTask)
|
|
185
|
-
it.reactNativeDir.set(rootExtension.reactNativeDir)
|
|
186
|
-
it.nodeExecutableAndArgs.set(rootExtension.nodeExecutableAndArgs)
|
|
187
|
-
it.generatedSrcDir.set(generatedSrcDir)
|
|
188
|
-
it.packageJsonFile.set(findPackageJsonFile(project, rootExtension.root))
|
|
189
|
-
it.codegenJavaPackageName.set(localExtension.codegenJavaPackageName)
|
|
190
|
-
it.libraryName.set(localExtension.libraryName)
|
|
191
|
-
|
|
192
|
-
// Please note that appNeedsCodegen is triggering a read of the package.json at
|
|
193
|
-
// configuration time as we need to feed the onlyIf condition of this task.
|
|
194
|
-
// Therefore, the appNeedsCodegen needs to be invoked inside this lambda.
|
|
195
|
-
val needsCodegenFromPackageJson =
|
|
196
|
-
project.needsCodegenFromPackageJson(rootExtension.root)
|
|
197
|
-
it.onlyIf { isLibrary || needsCodegenFromPackageJson }
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// We update the android configuration to include the generated sources.
|
|
201
|
-
// This equivalent to this DSL:
|
|
202
|
-
//
|
|
203
|
-
// android { sourceSets { main { java { srcDirs += "$generatedSrcDir/java" } } } }
|
|
204
|
-
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext ->
|
|
205
|
-
ext.sourceSets.getByName("main").java.srcDir(File(generatedSrcDir, "java"))
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// `preBuild` is one of the base tasks automatically registered by AGP.
|
|
209
|
-
// This will invoke the codegen before compiling the entire project.
|
|
210
|
-
project.tasks.named("preBuild", Task::class.java).dependsOn(generateCodegenArtifactsTask)
|
|
211
|
-
}
|
|
212
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
package com.facebook.react.tasks.internal
|
|
9
|
-
|
|
10
|
-
import java.io.File
|
|
11
|
-
import org.gradle.api.DefaultTask
|
|
12
|
-
import org.gradle.api.file.DirectoryProperty
|
|
13
|
-
import org.gradle.api.provider.Property
|
|
14
|
-
import org.gradle.api.tasks.*
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A task that takes care of unbundling JSC and preparing it for be consumed by the Android NDK.
|
|
18
|
-
* Specifically it will unbundle shared libs, headers and will copy over the Makefile from
|
|
19
|
-
* `src/main/jni/third-party/jsc/`
|
|
20
|
-
*/
|
|
21
|
-
abstract class PrepareJSCTask : DefaultTask() {
|
|
22
|
-
|
|
23
|
-
@get:Input abstract val jscPackagePath: Property<String>
|
|
24
|
-
|
|
25
|
-
@get:OutputDirectory abstract val outputDir: DirectoryProperty
|
|
26
|
-
|
|
27
|
-
@TaskAction
|
|
28
|
-
fun taskAction() {
|
|
29
|
-
if (!jscPackagePath.isPresent || jscPackagePath.orNull == null) {
|
|
30
|
-
error("Could not find the jsc-android npm package")
|
|
31
|
-
}
|
|
32
|
-
val jscDist = File(jscPackagePath.get(), "dist")
|
|
33
|
-
if (!jscDist.exists()) {
|
|
34
|
-
error("The jsc-android npm package is missing its \"dist\" directory")
|
|
35
|
-
}
|
|
36
|
-
val jscAAR =
|
|
37
|
-
project.fileTree(jscDist).matching { it.include("**/android-jsc/**/*.aar") }.singleFile
|
|
38
|
-
val soFiles = project.zipTree(jscAAR).matching { it.include("**/*.so") }
|
|
39
|
-
val headerFiles = project.fileTree(jscDist).matching { it.include("**/include/*.h") }
|
|
40
|
-
|
|
41
|
-
project.copy { it ->
|
|
42
|
-
it.from(soFiles)
|
|
43
|
-
it.from(headerFiles)
|
|
44
|
-
it.from(project.file("src/main/jni/third-party/jsc/CMakeLists.txt"))
|
|
45
|
-
it.filesMatching("**/*.h") { it.path = "JavaScriptCore/${it.name}" }
|
|
46
|
-
it.includeEmptyDirs = false
|
|
47
|
-
it.into(outputDir)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
package com.facebook.react.tasks.internal
|
|
9
|
-
|
|
10
|
-
import java.io.File
|
|
11
|
-
import org.gradle.api.DefaultTask
|
|
12
|
-
import org.gradle.api.file.ConfigurableFileCollection
|
|
13
|
-
import org.gradle.api.file.DirectoryProperty
|
|
14
|
-
import org.gradle.api.provider.Property
|
|
15
|
-
import org.gradle.api.tasks.*
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A task that takes care of extracting Libevent from a source folder/zip and preparing it to be
|
|
19
|
-
* consumed by the NDK.
|
|
20
|
-
*/
|
|
21
|
-
abstract class PrepareLibeventTask : DefaultTask() {
|
|
22
|
-
|
|
23
|
-
@get:InputFiles abstract val libeventPath: ConfigurableFileCollection
|
|
24
|
-
|
|
25
|
-
@get:Input abstract val libeventVersion: Property<String>
|
|
26
|
-
|
|
27
|
-
@get:OutputDirectory abstract val outputDir: DirectoryProperty
|
|
28
|
-
|
|
29
|
-
@TaskAction
|
|
30
|
-
fun taskAction() {
|
|
31
|
-
project.copy { it ->
|
|
32
|
-
it.from(libeventPath)
|
|
33
|
-
it.from(project.file("src/main/jni/third-party/libevent/"))
|
|
34
|
-
it.include(
|
|
35
|
-
"libevent-${libeventVersion.get()}-stable/*.c",
|
|
36
|
-
"libevent-${libeventVersion.get()}-stable/*.h",
|
|
37
|
-
"libevent-${libeventVersion.get()}-stable/include/**/*",
|
|
38
|
-
"evconfig-private.h",
|
|
39
|
-
"event-config.h",
|
|
40
|
-
"CMakeLists.txt")
|
|
41
|
-
it.eachFile { it.path = it.path.removePrefix("libevent-${libeventVersion.get()}-stable/") }
|
|
42
|
-
it.includeEmptyDirs = false
|
|
43
|
-
it.into(outputDir)
|
|
44
|
-
}
|
|
45
|
-
File(outputDir.asFile.get(), "event-config.h").apply {
|
|
46
|
-
val destination =
|
|
47
|
-
File(this.parentFile, "include/event2/event-config.h").apply { parentFile.mkdirs() }
|
|
48
|
-
renameTo(destination)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
package com.facebook.react.utils
|
|
9
|
-
|
|
10
|
-
import com.android.build.api.variant.AndroidComponentsExtension
|
|
11
|
-
import com.facebook.react.utils.ProjectUtils.isHermesEnabled
|
|
12
|
-
import com.facebook.react.utils.ProjectUtils.isNewArchEnabled
|
|
13
|
-
import org.gradle.api.Action
|
|
14
|
-
import org.gradle.api.Project
|
|
15
|
-
import org.gradle.api.plugins.AppliedPlugin
|
|
16
|
-
|
|
17
|
-
@Suppress("UnstableApiUsage")
|
|
18
|
-
internal object AgpConfiguratorUtils {
|
|
19
|
-
|
|
20
|
-
fun configureBuildConfigFields(project: Project) {
|
|
21
|
-
val action =
|
|
22
|
-
Action<AppliedPlugin> {
|
|
23
|
-
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext ->
|
|
24
|
-
ext.defaultConfig.buildConfigField(
|
|
25
|
-
"boolean", "IS_NEW_ARCHITECTURE_ENABLED", project.isNewArchEnabled.toString())
|
|
26
|
-
ext.defaultConfig.buildConfigField(
|
|
27
|
-
"boolean", "IS_HERMES_ENABLED", project.isHermesEnabled.toString())
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
project.pluginManager.withPlugin("com.android.application", action)
|
|
31
|
-
project.pluginManager.withPlugin("com.android.library", action)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
fun configureDevPorts(project: Project) {
|
|
35
|
-
val devServerPort =
|
|
36
|
-
project.properties["reactNativeDevServerPort"]?.toString() ?: DEFAULT_DEV_SERVER_PORT
|
|
37
|
-
val inspectorProxyPort =
|
|
38
|
-
project.properties["reactNativeInspectorProxyPort"]?.toString() ?: devServerPort
|
|
39
|
-
|
|
40
|
-
val action =
|
|
41
|
-
Action<AppliedPlugin> {
|
|
42
|
-
project.extensions.getByType(AndroidComponentsExtension::class.java).finalizeDsl { ext ->
|
|
43
|
-
ext.defaultConfig.resValue("integer", "react_native_dev_server_port", devServerPort)
|
|
44
|
-
ext.defaultConfig.resValue(
|
|
45
|
-
"integer", "react_native_inspector_proxy_port", inspectorProxyPort)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
project.pluginManager.withPlugin("com.android.application", action)
|
|
50
|
-
project.pluginManager.withPlugin("com.android.library", action)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const val DEFAULT_DEV_SERVER_PORT = "8081"
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
package com.facebook.react.utils
|
|
9
|
-
|
|
10
|
-
import java.util.*
|
|
11
|
-
import org.gradle.api.Project
|
|
12
|
-
|
|
13
|
-
internal object BackwardCompatUtils {
|
|
14
|
-
|
|
15
|
-
fun configureBackwardCompatibilityReactMap(project: Project) {
|
|
16
|
-
if (project.extensions.extraProperties.has("react")) {
|
|
17
|
-
@Suppress("UNCHECKED_CAST")
|
|
18
|
-
val reactMap =
|
|
19
|
-
project.extensions.extraProperties.get("react") as? Map<String, Any?> ?: mapOf()
|
|
20
|
-
if (reactMap.isNotEmpty()) {
|
|
21
|
-
project.logger.error(
|
|
22
|
-
"""
|
|
23
|
-
********************************************************************************
|
|
24
|
-
|
|
25
|
-
ERROR: Using old project.ext.react configuration.
|
|
26
|
-
We identified that your project is using a old configuration block as:
|
|
27
|
-
|
|
28
|
-
project.ext.react = [
|
|
29
|
-
// ...
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
You should migrate to the new configuration:
|
|
33
|
-
|
|
34
|
-
react {
|
|
35
|
-
// ...
|
|
36
|
-
}
|
|
37
|
-
You can find documentation inside `android/app/build.gradle` on how to use it.
|
|
38
|
-
|
|
39
|
-
********************************************************************************
|
|
40
|
-
"""
|
|
41
|
-
.trimIndent())
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// We set an empty react[] map so if a library is reading it, they will find empty values.
|
|
46
|
-
project.extensions.extraProperties.set("react", mapOf<String, String>())
|
|
47
|
-
}
|
|
48
|
-
}
|