Skip to content

Commit

Permalink
Back out "Update RNGP to handle cxxModule in codegenConfig" (#43050)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #43050

Original commit changeset: 702f09ccf793

Original Phabricator Diff: D53669912

Changelog:
[Internal] [Changed] - Back out "[RN][Android][TmCxxAutolinking] Update RNGP to handle cxxModule in codegenConfig"

Reviewed By: cipolleschi

Differential Revision: D53812110

fbshipit-source-id: a7583c0cb8354bf31723794fbbb4ca5de8f1790a
  • Loading branch information
cortinico authored and facebook-github-bot committed Feb 16, 2024
1 parent 2697b9a commit 906985b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ data class ModelCodegenConfig(
val jsSrcsDir: String?,
val android: ModelCodegenConfigAndroid?,
val includesGeneratedCode: Boolean?,
val cxxModules: List<ModelCodegenConfigCxxModules>?,
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ abstract class GenerateCodegenArtifactsTask : Exec() {
@get:OutputDirectory val generatedJniFiles: Provider<Directory> = generatedSrcDir.dir("jni")

override fun exec() {
val (resolvedLibraryName, resolvedCodegenJavaPackageName, cxxModules) = resolveTaskParameters()
setupCommandLine(resolvedLibraryName, resolvedCodegenJavaPackageName, cxxModules)
val (resolvedLibraryName, resolvedCodegenJavaPackageName) = resolveTaskParameters()
setupCommandLine(resolvedLibraryName, resolvedCodegenJavaPackageName)
super.exec()
}

internal fun resolveTaskParameters(): List<String> {
internal fun resolveTaskParameters(): Pair<String, String> {
val parsedPackageJson =
if (packageJsonFile.isPresent && packageJsonFile.get().asFile.exists()) {
JsonUtils.fromPackageJson(packageJsonFile.get().asFile)
Expand All @@ -60,40 +60,24 @@ abstract class GenerateCodegenArtifactsTask : Exec() {
val resolvedLibraryName = parsedPackageJson?.codegenConfig?.name ?: libraryName.get()
val resolvedCodegenJavaPackageName =
parsedPackageJson?.codegenConfig?.android?.javaPackageName ?: codegenJavaPackageName.get()
val cxxModules = parsedPackageJson?.codegenConfig?.cxxModules ?: emptyList()
val separatedCxxModules = cxxModules.joinToString(":") { "${it.name}:${it.headerPath}" }
return listOf(resolvedLibraryName, resolvedCodegenJavaPackageName, separatedCxxModules)
return resolvedLibraryName to resolvedCodegenJavaPackageName
}

internal fun setupCommandLine(
libraryName: String,
codegenJavaPackageName: String,
cxxModules: String
) {
internal fun setupCommandLine(libraryName: String, codegenJavaPackageName: String) {
val workingDir = project.projectDir
val generateSpecsCli =
commandLine(
windowsAwareCommandLine(
*nodeExecutableAndArgs.get().toTypedArray(),
reactNativeDir
.file("scripts/generate-specs-cli.js")
.get()
.asFile
.cliPath(workingDir),
"--platform",
"android",
"--schemaPath",
generatedSchemaFile.get().asFile.cliPath(workingDir),
"--outputDir",
generatedSrcDir.get().asFile.cliPath(workingDir),
"--libraryName",
libraryName,
"--javaPackageName",
codegenJavaPackageName)
.toMutableList()
if (cxxModules.isNotBlank()) {
generateSpecsCli.add("--cxxModules")
generateSpecsCli.add(cxxModules)
}
commandLine(generateSpecsCli)
*nodeExecutableAndArgs.get().toTypedArray(),
reactNativeDir.file("scripts/generate-specs-cli.js").get().asFile.cliPath(workingDir),
"--platform",
"android",
"--schemaPath",
generatedSchemaFile.get().asFile.cliPath(workingDir),
"--outputDir",
generatedSrcDir.get().asFile.cliPath(workingDir),
"--libraryName",
libraryName,
"--javaPackageName",
codegenJavaPackageName))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class GenerateCodegenArtifactsTaskTest {
it.nodeExecutableAndArgs.set(listOf("--verbose"))
}

task.setupCommandLine("example-test", "com.example.test", "Module:Module.h")
task.setupCommandLine("example-test", "com.example.test")

assertEquals(
listOf(
Expand All @@ -91,8 +91,6 @@ class GenerateCodegenArtifactsTaskTest {
"example-test",
"--javaPackageName",
"com.example.test",
"--cxxModules",
"Module:Module.h",
),
task.commandLine.toMutableList())
}
Expand All @@ -111,7 +109,7 @@ class GenerateCodegenArtifactsTaskTest {
it.nodeExecutableAndArgs.set(listOf("--verbose"))
}

task.setupCommandLine("example-test", "com.example.test", "Module:Module.h")
task.setupCommandLine("example-test", "com.example.test")

assertEquals(
listOf(
Expand All @@ -131,8 +129,6 @@ class GenerateCodegenArtifactsTaskTest {
"example-test",
"--javaPackageName",
"com.example.test",
"--cxxModules",
"Module:Module.h",
),
task.commandLine.toMutableList())
}
Expand All @@ -145,7 +141,7 @@ class GenerateCodegenArtifactsTaskTest {
writeText(
"""
{
"name": "@a/library",
"name": "@a/libray",
"codegenConfig": {
"name": "an-awesome-library",
"android": {
Expand All @@ -170,44 +166,6 @@ class GenerateCodegenArtifactsTaskTest {
assertEquals("com.awesome.package", javaPackageName)
}

@Test
fun resolveTaskParameters_withCxxModules_parsesIt() {
val packageJsonFile =
tempFolder.newFile("package.json").apply {
// language=JSON
writeText(
"""
{
"name": "@a/library",
"codegenConfig": {
"name": "an-awesome-library",
"android": {
"javaPackageName": "com.awesome.package"
},
"cxxModules": [
{
"name": "Module1",
"headerPath": "Module1.h"
},
{
"name": "Module2",
"headerPath": "another/header/path/Module2.h"
}
]
}
}
"""
.trimIndent())
}

val task =
createTestTask<GenerateCodegenArtifactsTask> { it.packageJsonFile.set(packageJsonFile) }

val (_, _, cxxModules) = task.resolveTaskParameters()

assertEquals("Module1:Module1.h:Module2:another/header/path/Module2.h", cxxModules)
}

@Test
fun resolveTaskParameters_withConfigMissingInPackageJson_usesGradleOne() {
val packageJsonFile =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ class ProjectUtilsTest {
@Test
fun needsCodegenFromPackageJson_withCodegenConfigInModel_returnsTrue() {
val project = createProject()
val model =
ModelPackageJson("1000.0.0", ModelCodegenConfig(null, null, null, null, false, null))
val model = ModelPackageJson("1000.0.0", ModelCodegenConfig(null, null, null, null, false))

assertTrue(project.needsCodegenFromPackageJson(model))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ function generateSpecFromInMemorySchema(
packageName,
libraryType,
useLocalIncludePaths,
cxxModules,
) {
validateLibraryType(libraryType);
createOutputDirectoryIfNeeded(outputDirectory, libraryName);
Expand Down Expand Up @@ -112,7 +111,6 @@ function generateSpec(
libraryName,
packageName,
libraryType,
cxxModules,
) {
generateSpecFromInMemorySchema(
platform,
Expand Down
7 changes: 0 additions & 7 deletions packages/react-native/scripts/generate-specs-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ const argv = yargs
describe: 'all, components, or modules.',
default: 'all',
})
.option('c', {
alias: 'cxxModules',
describe:
'A colon separated list of modules name & modules header path, used to support CXX TurboModule linking.',
default: 'all',
})
.usage('Usage: $0 <args>')
.demandOption(
['platform', 'schemaPath', 'outputDir'],
Expand All @@ -61,7 +55,6 @@ function main() {
argv.libraryName,
argv.javaPackageName,
argv.libraryType,
argv.cxxModules,
);
}

Expand Down

0 comments on commit 906985b

Please sign in to comment.