Skip to content

Commit

Permalink
feat: derive if a dependency is pure cxx from other properties
Browse files Browse the repository at this point in the history
  • Loading branch information
atlj committed May 11, 2024
1 parent 660b282 commit f8b3075
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
10 changes: 5 additions & 5 deletions packages/cli-platform-android/native_modules.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ class ReactNativeModules {
reactNativeModules.forEach { reactNativeModule ->
def nameCleansed = reactNativeModule["nameCleansed"]
def dependencyConfiguration = reactNativeModule["dependencyConfiguration"]
def cxxOnly = reactNativeModule["cxxOnly"]

if (cxxOnly) {
def isPureCxxDependency = reactNativeModule["isPureCxxDependency"]
if (isPureCxxDependency) {
return
}

Expand Down Expand Up @@ -254,12 +253,12 @@ class ReactNativeModules {
})
}
packageImports = packages
.findAll { !it.cxxOnly }
.findAll { !it.isPureCxxDependency }
.collect {
"// ${it.name}\n${interpolateDynamicValues(it.packageImportPath)}"
}.join('\n')
packageClassInstances = ",\n " + packages
.findAll { !it.cxxOnly }
.findAll { !it.isPureCxxDependency }
.collect {
interpolateDynamicValues(it.packageInstance)
}.join(",\n ")
Expand Down Expand Up @@ -481,6 +480,7 @@ class ReactNativeModules {
reactNativeModuleConfig.put("cxxModuleCMakeListsModuleName", androidConfig["cxxModuleCMakeListsModuleName"])
reactNativeModuleConfig.put("cxxModuleCMakeListsPath", androidConfig["cxxModuleCMakeListsPath"])
reactNativeModuleConfig.put("cxxModuleHeaderName", androidConfig["cxxModuleHeaderName"])
reactNativeModuleConfig.put("isPureCxxDependency", androidConfig["isPureCxxDependency"])

if (androidConfig["buildTypes"] && !androidConfig["buildTypes"].isEmpty()) {
reactNativeModulesBuildVariants.put(nameCleansed, androidConfig["buildTypes"])
Expand Down
45 changes: 27 additions & 18 deletions packages/cli-platform-android/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,29 +135,38 @@ export function dependencyConfig(
? path.join(sourceDir, userConfig.manifestPath)
: findManifest(sourceDir);
const buildGradlePath = findBuildGradle(sourceDir, true);
const cxxOnly = userConfig.cxxOnly || false;

if (!cxxOnly && !manifestPath && !buildGradlePath) {
const isPureCxxDependency =
userConfig.cxxModuleCMakeListsModuleName != null &&
userConfig.cxxModuleCMakeListsPath != null &&
userConfig.cxxModuleHeaderName != null &&
!manifestPath &&
!buildGradlePath;

if (!manifestPath && !buildGradlePath && !isPureCxxDependency) {
return null;
}

const packageName =
userConfig.packageName || getPackageName(manifestPath, buildGradlePath);
const packageClassName = findPackageClassName(sourceDir);
let packageImportPath = null,
packageInstance = null;

/**
* This module has no package to export
*/
if (!cxxOnly && !packageClassName) {
return null;
}
if (!isPureCxxDependency) {
const packageName =
userConfig.packageName || getPackageName(manifestPath, buildGradlePath);
const packageClassName = findPackageClassName(sourceDir);

/**
* This module has no package to export
*/
if (!packageClassName) {
return null;
}

const packageImportPath =
userConfig.packageImportPath ||
`import ${packageName}.${packageClassName};`;
packageImportPath =
userConfig.packageImportPath ||
`import ${packageName}.${packageClassName};`;

const packageInstance =
userConfig.packageInstance || `new ${packageClassName}()`;
packageInstance = userConfig.packageInstance || `new ${packageClassName}()`;
}

const buildTypes = userConfig.buildTypes || [];
const dependencyConfiguration = userConfig.dependencyConfiguration;
Expand Down Expand Up @@ -194,6 +203,6 @@ export function dependencyConfig(
cxxModuleCMakeListsModuleName,
cxxModuleCMakeListsPath,
cxxModuleHeaderName,
cxxOnly,
isPureCxxDependency,
};
}
5 changes: 3 additions & 2 deletions packages/cli-types/src/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export type AndroidProjectParams = {

export type AndroidDependencyConfig = {
sourceDir: string;
packageImportPath: string;
packageInstance: string;
packageImportPath: string | null;
packageInstance: string | null;
dependencyConfiguration?: string;
buildTypes: string[];
libraryName?: string | null;
Expand All @@ -35,6 +35,7 @@ export type AndroidDependencyConfig = {
cxxModuleCMakeListsModuleName?: string | null;
cxxModuleCMakeListsPath?: string | null;
cxxModuleHeaderName?: string | null;
isPureCxxDependency?: boolean;
};

export type AndroidDependencyParams = {
Expand Down

0 comments on commit f8b3075

Please sign in to comment.