diff options
| author | 2024-10-14 12:14:54 -0700 | |
|---|---|---|
| committer | 2024-10-14 13:42:54 -0700 | |
| commit | c71b175e6c3d6e7223c5c30b305659cce15b68c0 (patch) | |
| tree | eb2c12d7615ae50d4eec98ea154666f4c0b1eda4 /java | |
| parent | 8017cca9eaabc14ffda4c8fcfc04b5ef7c047ace (diff) | |
Make the "apk" property configurable
On android_app_import and android_test_import.
Unfortunately I had to add a mutator because you can't evaluate
configurable properties during defaultable hooks.
Bug: 373414956
Test: m nothing --no-skip-soong-tests
Change-Id: Ic42d558e4f2222091aac250b9513d867fb8d6984
Diffstat (limited to 'java')
| -rw-r--r-- | java/app_import.go | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/java/app_import.go b/java/app_import.go index a54cf2fc3..f5d9f3e79 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -61,6 +61,9 @@ var ( func RegisterAppImportBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("android_app_import", AndroidAppImportFactory) ctx.RegisterModuleType("android_test_import", AndroidTestImportFactory) + ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { + ctx.BottomUp("disable_prebuilts_without_apk", disablePrebuiltsWithoutApkMutator) + }) } type AndroidAppImport struct { @@ -90,7 +93,7 @@ type AndroidAppImport struct { type AndroidAppImportProperties struct { // A prebuilt apk to import - Apk *string `android:"path"` + Apk proptools.Configurable[string] `android:"path,replace_instead_of_append"` // The name of a certificate in the default certificate directory or an android_app_certificate // module name in the form ":module". Should be empty if presigned or default_dev_cert is set. @@ -193,13 +196,6 @@ func (a *AndroidAppImport) processVariants(ctx android.DefaultableHookContext) { } } } - - if String(a.properties.Apk) == "" { - // Disable this module since the apk property is still empty after processing all matching - // variants. This likely means there is no matching variant, and the default variant doesn't - // have an apk property value either. - a.Disable() - } } func MergePropertiesFromVariant(ctx android.EarlyModuleContext, @@ -219,6 +215,30 @@ func MergePropertiesFromVariant(ctx android.EarlyModuleContext, } } +// disablePrebuiltsWithoutApkMutator is a pre-arch mutator that disables AndroidAppImport or +// AndroidTestImport modules that don't have an apk set. We need this separate mutator instead +// of doing it in processVariants because processVariants is a defaultable hook, and configurable +// properties can only be evaluated after the defaults (and eventually, base configurabtion) +// mutators. +func disablePrebuiltsWithoutApkMutator(ctx android.BottomUpMutatorContext) { + switch a := ctx.Module().(type) { + case *AndroidAppImport: + if a.properties.Apk.GetOrDefault(ctx, "") == "" { + // Disable this module since the apk property is still empty after processing all + // matching variants. This likely means there is no matching variant, and the default + // variant doesn't have an apk property value either. + a.Disable() + } + case *AndroidTestImport: + if a.properties.Apk.GetOrDefault(ctx, "") == "" { + // Disable this module since the apk property is still empty after processing all + // matching variants. This likely means there is no matching variant, and the default + // variant doesn't have an apk property value either. + a.Disable() + } + } +} + func (a *AndroidAppImport) DepsMutator(ctx android.BottomUpMutatorContext) { cert := android.SrcIsModule(String(a.properties.Certificate)) if cert != "" { @@ -409,7 +429,7 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext if apexInfo.IsForPlatform() { a.installPath = ctx.InstallFile(installDir, apkFilename, a.outputFile) - artifactPath := android.PathForModuleSrc(ctx, *a.properties.Apk) + artifactPath := android.PathForModuleSrc(ctx, a.properties.Apk.GetOrDefault(ctx, "")) a.provenanceMetaDataFile = provenance.GenerateArtifactProvenanceMetaData(ctx, artifactPath, a.installPath) } @@ -633,7 +653,7 @@ func AndroidAppImportFactory() android.Module { android.InitApexModule(module) android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) - android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk") + android.InitConfigurablePrebuiltModuleString(module, &module.properties.Apk, "Apk") module.usesLibrary.enforce = true @@ -686,7 +706,7 @@ func AndroidTestImportFactory() android.Module { android.InitApexModule(module) android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) - android.InitSingleSourcePrebuiltModule(module, &module.properties, "Apk") + android.InitConfigurablePrebuiltModuleString(module, &module.properties.Apk, "Apk") return module } |