@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,217 @@
|
|
|
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.facebook.react.model.ModelAutolinkingConfigJson
|
|
11
|
+
import com.facebook.react.utils.JsonUtils
|
|
12
|
+
import com.facebook.react.utils.windowsAwareCommandLine
|
|
13
|
+
import java.io.File
|
|
14
|
+
import java.math.BigInteger
|
|
15
|
+
import java.security.MessageDigest
|
|
16
|
+
import javax.inject.Inject
|
|
17
|
+
import kotlin.math.min
|
|
18
|
+
import org.gradle.api.GradleException
|
|
19
|
+
import org.gradle.api.file.FileCollection
|
|
20
|
+
import org.gradle.api.initialization.Settings
|
|
21
|
+
import org.gradle.api.logging.Logging
|
|
22
|
+
|
|
23
|
+
abstract class ReactSettingsExtension @Inject constructor(val settings: Settings) {
|
|
24
|
+
|
|
25
|
+
private val outputFile =
|
|
26
|
+
settings.layout.rootDirectory.file("build/generated/autolinking/autolinking.json").asFile
|
|
27
|
+
private val outputFolder =
|
|
28
|
+
settings.layout.rootDirectory.file("build/generated/autolinking/").asFile
|
|
29
|
+
|
|
30
|
+
private val defaultConfigCommand: List<String> =
|
|
31
|
+
windowsAwareCommandLine(listOf("npx", "@react-native-community/cli", "config")).map {
|
|
32
|
+
it.toString()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Utility function to autolink libraries using an external command as source of truth.
|
|
37
|
+
*
|
|
38
|
+
* This should be invoked inside the `settings.gradle` file, and will make sure the Gradle project
|
|
39
|
+
* is loading all the discovered libraries.
|
|
40
|
+
*
|
|
41
|
+
* @param command The command to execute to get the autolinking configuration. Default is
|
|
42
|
+
* `npx @react-native-community/cli config`.
|
|
43
|
+
* @param workingDirectory The directory where the command should be executed.
|
|
44
|
+
* @param lockFiles The list of lock files to check for changes (if lockfiles are not changed, the
|
|
45
|
+
* command will not be executed).
|
|
46
|
+
*/
|
|
47
|
+
@JvmOverloads
|
|
48
|
+
public fun autolinkLibrariesFromCommand(
|
|
49
|
+
command: List<String> = defaultConfigCommand,
|
|
50
|
+
workingDirectory: File? = settings.layout.rootDirectory.dir("../").asFile,
|
|
51
|
+
lockFiles: FileCollection =
|
|
52
|
+
settings.layout.rootDirectory
|
|
53
|
+
.dir("../")
|
|
54
|
+
.files("yarn.lock", "package-lock.json", "package.json", "react-native.config.js"),
|
|
55
|
+
) {
|
|
56
|
+
outputFile.parentFile.mkdirs()
|
|
57
|
+
|
|
58
|
+
val updateConfig =
|
|
59
|
+
object : GenerateConfig {
|
|
60
|
+
override fun command(): List<String> = command
|
|
61
|
+
|
|
62
|
+
override fun execute(): Int {
|
|
63
|
+
val execResult =
|
|
64
|
+
settings.providers.exec { exec ->
|
|
65
|
+
exec.commandLine(command)
|
|
66
|
+
exec.workingDir = workingDirectory
|
|
67
|
+
}
|
|
68
|
+
outputFile.writeText(execResult.standardOutput.asText.get())
|
|
69
|
+
return execResult.result.get().exitValue
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
checkAndUpdateCache(updateConfig, outputFile, outputFolder, lockFiles)
|
|
74
|
+
|
|
75
|
+
linkLibraries(getLibrariesToAutolink(outputFile))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Utility function to autolink libraries using an external file as source of truth.
|
|
80
|
+
*
|
|
81
|
+
* The file should be a JSON file with the same structure as the one generated by the
|
|
82
|
+
* `npx @react-native-community/cli config` command.
|
|
83
|
+
*
|
|
84
|
+
* @param autolinkConfigFile The file to read the autolinking configuration from.
|
|
85
|
+
*/
|
|
86
|
+
public fun autolinkLibrariesFromConfigFile(
|
|
87
|
+
autolinkConfigFile: File,
|
|
88
|
+
) {
|
|
89
|
+
// We copy the file to the build directory so that the various Gradle tasks can access it.
|
|
90
|
+
autolinkConfigFile.copyTo(outputFile, overwrite = true)
|
|
91
|
+
linkLibraries(getLibrariesToAutolink(autolinkConfigFile))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Utility function so that for each tuple :project-name -> project-dir, it instructs Gradle to
|
|
96
|
+
* lad this extra module.
|
|
97
|
+
*/
|
|
98
|
+
private fun linkLibraries(input: Map<String, File>) {
|
|
99
|
+
input.forEach { (path, projectDir) ->
|
|
100
|
+
settings.include(path)
|
|
101
|
+
settings.project(path).projectDir = projectDir
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
internal interface GenerateConfig {
|
|
106
|
+
fun command(): List<String>
|
|
107
|
+
|
|
108
|
+
fun execute(): Int
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
companion object {
|
|
112
|
+
private val md = MessageDigest.getInstance("SHA-256")
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Determine if our cache is out-of-date
|
|
116
|
+
*
|
|
117
|
+
* @param cacheJsonConfig Our current cached autolinking.json config, which may exist
|
|
118
|
+
* @param cacheFolder The folder we store our cached SHAs and config
|
|
119
|
+
* @param lockFiles The [FileCollection] of the lockfiles to check.
|
|
120
|
+
* @return `true` if the cache needs to be rebuilt, `false` otherwise
|
|
121
|
+
*/
|
|
122
|
+
internal fun isCacheDirty(
|
|
123
|
+
cacheJsonConfig: File,
|
|
124
|
+
cacheFolder: File,
|
|
125
|
+
lockFiles: FileCollection,
|
|
126
|
+
): Boolean {
|
|
127
|
+
if (cacheJsonConfig.exists().not() || cacheJsonConfig.length() == 0L) {
|
|
128
|
+
return true
|
|
129
|
+
}
|
|
130
|
+
val lockFilesChanged = checkAndUpdateLockfiles(lockFiles, cacheFolder)
|
|
131
|
+
if (lockFilesChanged) {
|
|
132
|
+
return true
|
|
133
|
+
}
|
|
134
|
+
return isConfigModelInvalid(JsonUtils.fromAutolinkingConfigJson(cacheJsonConfig))
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Utility function to update the settings cache only if it's entries are dirty
|
|
139
|
+
*
|
|
140
|
+
* @param updateJsonConfig A [GenerateConfig] to update the project's autolinking config
|
|
141
|
+
* @param cacheJsonConfig Our current cached autolinking.json config, which may exist
|
|
142
|
+
* @param cacheFolder The folder we store our cached SHAs and config
|
|
143
|
+
* @param lockFiles The [FileCollection] of the lockfiles to check.
|
|
144
|
+
*/
|
|
145
|
+
internal fun checkAndUpdateCache(
|
|
146
|
+
updateJsonConfig: GenerateConfig,
|
|
147
|
+
cacheJsonConfig: File,
|
|
148
|
+
cacheFolder: File,
|
|
149
|
+
lockFiles: FileCollection,
|
|
150
|
+
) {
|
|
151
|
+
if (isCacheDirty(cacheJsonConfig, cacheFolder, lockFiles)) {
|
|
152
|
+
val exitValue = updateJsonConfig.execute()
|
|
153
|
+
if (exitValue != 0) {
|
|
154
|
+
val prefixCommand =
|
|
155
|
+
"ERROR: autolinkLibrariesFromCommand: process ${updateJsonConfig.command().joinToString(" ")}"
|
|
156
|
+
val message = "$prefixCommand exited with error code: $exitValue"
|
|
157
|
+
val logger = Logging.getLogger("ReactSettingsExtension")
|
|
158
|
+
logger.error(message)
|
|
159
|
+
if (cacheJsonConfig.length() != 0L) {
|
|
160
|
+
logger.error(
|
|
161
|
+
cacheJsonConfig.readText().substring(0, min(1024, cacheJsonConfig.length().toInt()))
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
cacheJsonConfig.delete()
|
|
165
|
+
throw GradleException(message)
|
|
166
|
+
} else {
|
|
167
|
+
// If cache was dirty, we executed the command and we need to update the lockfiles sha.
|
|
168
|
+
checkAndUpdateLockfiles(lockFiles, cacheFolder)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Utility function to check if the provided lockfiles have been updated or not. This function
|
|
175
|
+
* will both check and update the lockfiles hashes if necessary.
|
|
176
|
+
*
|
|
177
|
+
* @param lockFiles The [FileCollection] of the lockfiles to check.
|
|
178
|
+
* @param outputFolder The folder where the hashes will be stored.
|
|
179
|
+
* @return `true` if the lockfiles have been updated, `false` otherwise.
|
|
180
|
+
*/
|
|
181
|
+
internal fun checkAndUpdateLockfiles(lockFiles: FileCollection, outputFolder: File): Boolean {
|
|
182
|
+
var changed = false
|
|
183
|
+
lockFiles.forEach { lockFile ->
|
|
184
|
+
if (lockFile.exists()) {
|
|
185
|
+
val sha = computeSha256(lockFile)
|
|
186
|
+
val shaFile = File(outputFolder, "${lockFile.name}.sha")
|
|
187
|
+
if (shaFile.exists().not() || shaFile.readText() != sha) {
|
|
188
|
+
shaFile.writeText(sha)
|
|
189
|
+
changed = true
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return changed
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
internal fun getLibrariesToAutolink(buildFile: File): Map<String, File> {
|
|
197
|
+
val model = JsonUtils.fromAutolinkingConfigJson(buildFile)
|
|
198
|
+
return model
|
|
199
|
+
?.dependencies
|
|
200
|
+
?.values
|
|
201
|
+
// We handle scenarios where there are deps that are
|
|
202
|
+
// iOS-only or missing the Android configs.
|
|
203
|
+
?.filter { it.platforms?.android?.sourceDir != null }
|
|
204
|
+
// We want to skip dependencies that are pure C++ as they won't contain a .gradle file.
|
|
205
|
+
?.filterNot { it.platforms?.android?.isPureCxxDependency == true }
|
|
206
|
+
?.associate { deps ->
|
|
207
|
+
":${deps.nameCleansed}" to File(deps.platforms?.android?.sourceDir)
|
|
208
|
+
} ?: emptyMap()
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
internal fun computeSha256(lockFile: File) =
|
|
212
|
+
String.format("%032x", BigInteger(1, md.digest(lockFile.readBytes())))
|
|
213
|
+
|
|
214
|
+
internal fun isConfigModelInvalid(model: ModelAutolinkingConfigJson?) =
|
|
215
|
+
model?.project?.android?.packageName == null
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 org.gradle.api.Plugin
|
|
11
|
+
import org.gradle.api.initialization.Settings
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This is the settings.gradle plugin for React Native.
|
|
15
|
+
*
|
|
16
|
+
* It just registers the [ReactSettingsExtension] extension, so that utility functions over there
|
|
17
|
+
* can be called to support autolinking.
|
|
18
|
+
*/
|
|
19
|
+
class ReactSettingsPlugin : Plugin<Settings> {
|
|
20
|
+
override fun apply(settings: Settings) {
|
|
21
|
+
settings.extensions.create("reactSettings", ReactSettingsExtension::class.java, settings)
|
|
22
|
+
}
|
|
23
|
+
}
|