Skip to content

Commit f8b3075

Browse files
committed
feat: derive if a dependency is pure cxx from other properties
1 parent 660b282 commit f8b3075

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

packages/cli-platform-android/native_modules.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,8 @@ class ReactNativeModules {
185185
reactNativeModules.forEach { reactNativeModule ->
186186
def nameCleansed = reactNativeModule["nameCleansed"]
187187
def dependencyConfiguration = reactNativeModule["dependencyConfiguration"]
188-
def cxxOnly = reactNativeModule["cxxOnly"]
189-
190-
if (cxxOnly) {
188+
def isPureCxxDependency = reactNativeModule["isPureCxxDependency"]
189+
if (isPureCxxDependency) {
191190
return
192191
}
193192

@@ -254,12 +253,12 @@ class ReactNativeModules {
254253
})
255254
}
256255
packageImports = packages
257-
.findAll { !it.cxxOnly }
256+
.findAll { !it.isPureCxxDependency }
258257
.collect {
259258
"// ${it.name}\n${interpolateDynamicValues(it.packageImportPath)}"
260259
}.join('\n')
261260
packageClassInstances = ",\n " + packages
262-
.findAll { !it.cxxOnly }
261+
.findAll { !it.isPureCxxDependency }
263262
.collect {
264263
interpolateDynamicValues(it.packageInstance)
265264
}.join(",\n ")
@@ -481,6 +480,7 @@ class ReactNativeModules {
481480
reactNativeModuleConfig.put("cxxModuleCMakeListsModuleName", androidConfig["cxxModuleCMakeListsModuleName"])
482481
reactNativeModuleConfig.put("cxxModuleCMakeListsPath", androidConfig["cxxModuleCMakeListsPath"])
483482
reactNativeModuleConfig.put("cxxModuleHeaderName", androidConfig["cxxModuleHeaderName"])
483+
reactNativeModuleConfig.put("isPureCxxDependency", androidConfig["isPureCxxDependency"])
484484

485485
if (androidConfig["buildTypes"] && !androidConfig["buildTypes"].isEmpty()) {
486486
reactNativeModulesBuildVariants.put(nameCleansed, androidConfig["buildTypes"])

packages/cli-platform-android/src/config/index.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,29 +135,38 @@ export function dependencyConfig(
135135
? path.join(sourceDir, userConfig.manifestPath)
136136
: findManifest(sourceDir);
137137
const buildGradlePath = findBuildGradle(sourceDir, true);
138-
const cxxOnly = userConfig.cxxOnly || false;
139-
140-
if (!cxxOnly && !manifestPath && !buildGradlePath) {
138+
const isPureCxxDependency =
139+
userConfig.cxxModuleCMakeListsModuleName != null &&
140+
userConfig.cxxModuleCMakeListsPath != null &&
141+
userConfig.cxxModuleHeaderName != null &&
142+
!manifestPath &&
143+
!buildGradlePath;
144+
145+
if (!manifestPath && !buildGradlePath && !isPureCxxDependency) {
141146
return null;
142147
}
143148

144-
const packageName =
145-
userConfig.packageName || getPackageName(manifestPath, buildGradlePath);
146-
const packageClassName = findPackageClassName(sourceDir);
149+
let packageImportPath = null,
150+
packageInstance = null;
147151

148-
/**
149-
* This module has no package to export
150-
*/
151-
if (!cxxOnly && !packageClassName) {
152-
return null;
153-
}
152+
if (!isPureCxxDependency) {
153+
const packageName =
154+
userConfig.packageName || getPackageName(manifestPath, buildGradlePath);
155+
const packageClassName = findPackageClassName(sourceDir);
156+
157+
/**
158+
* This module has no package to export
159+
*/
160+
if (!packageClassName) {
161+
return null;
162+
}
154163

155-
const packageImportPath =
156-
userConfig.packageImportPath ||
157-
`import ${packageName}.${packageClassName};`;
164+
packageImportPath =
165+
userConfig.packageImportPath ||
166+
`import ${packageName}.${packageClassName};`;
158167

159-
const packageInstance =
160-
userConfig.packageInstance || `new ${packageClassName}()`;
168+
packageInstance = userConfig.packageInstance || `new ${packageClassName}()`;
169+
}
161170

162171
const buildTypes = userConfig.buildTypes || [];
163172
const dependencyConfiguration = userConfig.dependencyConfiguration;
@@ -194,6 +203,6 @@ export function dependencyConfig(
194203
cxxModuleCMakeListsModuleName,
195204
cxxModuleCMakeListsPath,
196205
cxxModuleHeaderName,
197-
cxxOnly,
206+
isPureCxxDependency,
198207
};
199208
}

packages/cli-types/src/android.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export type AndroidProjectParams = {
2525

2626
export type AndroidDependencyConfig = {
2727
sourceDir: string;
28-
packageImportPath: string;
29-
packageInstance: string;
28+
packageImportPath: string | null;
29+
packageInstance: string | null;
3030
dependencyConfiguration?: string;
3131
buildTypes: string[];
3232
libraryName?: string | null;
@@ -35,6 +35,7 @@ export type AndroidDependencyConfig = {
3535
cxxModuleCMakeListsModuleName?: string | null;
3636
cxxModuleCMakeListsPath?: string | null;
3737
cxxModuleHeaderName?: string | null;
38+
isPureCxxDependency?: boolean;
3839
};
3940

4041
export type AndroidDependencyParams = {

0 commit comments

Comments
 (0)