diff options
-rw-r--r-- | android/androidmk.go | 15 | ||||
-rw-r--r-- | android/module.go | 6 | ||||
-rw-r--r-- | apex/prebuilt.go | 75 | ||||
-rw-r--r-- | ci_tests/ci_test_package_zip.go | 8 |
4 files changed, 92 insertions, 12 deletions
diff --git a/android/androidmk.go b/android/androidmk.go index 7cc6aef00..e32835946 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -435,13 +435,18 @@ func getDistContributions(ctx ConfigAndOtherModuleProviderContext, mod Module) * suffix = *dist.Suffix } - productString := "" - if dist.Append_artifact_with_product != nil && *dist.Append_artifact_with_product { - productString = fmt.Sprintf("_%s", ctx.Config().DeviceProduct()) + prependProductString := "" + if proptools.Bool(dist.Prepend_artifact_with_product) { + prependProductString = fmt.Sprintf("%s-", ctx.Config().DeviceProduct()) } - if suffix != "" || productString != "" { - dest = strings.TrimSuffix(dest, ext) + suffix + productString + ext + appendProductString := "" + if proptools.Bool(dist.Append_artifact_with_product) { + appendProductString = fmt.Sprintf("_%s", ctx.Config().DeviceProduct()) + } + + if suffix != "" || appendProductString != "" || prependProductString != "" { + dest = prependProductString + strings.TrimSuffix(dest, ext) + suffix + appendProductString + ext } if dist.Dir != nil { diff --git a/android/module.go b/android/module.go index c0abfd0a3..1538861d3 100644 --- a/android/module.go +++ b/android/module.go @@ -208,6 +208,12 @@ type Dist struct { // no change to the artifact file name. Append_artifact_with_product *bool `android:"arch_variant"` + // If true, then the artifact file will be prepended with <product name>-. For + // example, if the product is coral and the module is an android_app module + // of name foo, then the artifact would be coral-foo.apk. If false, there is + // no change to the artifact file name. + Prepend_artifact_with_product *bool `android:"arch_variant"` + // A string tag to select the OutputFiles associated with the tag. // // If no tag is specified then it will select the default dist paths provided diff --git a/apex/prebuilt.go b/apex/prebuilt.go index 89b0091be..fdd9a75d7 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -15,7 +15,9 @@ package apex import ( + "fmt" "slices" + "sort" "strconv" "strings" @@ -80,6 +82,10 @@ type prebuiltCommon struct { // systemServerDexJars stores the list of dexjars for system server jars in the prebuilt for use when // dexpreopting system server jars that are later in the system server classpath. systemServerDexJars android.Paths + + // Certificate information of any apk packaged inside the prebuilt apex. + // This will be nil if the prebuilt apex does not contain any apk. + apkCertsFile android.WritablePath } type sanitizedPrebuilt interface { @@ -273,6 +279,10 @@ func (p *prebuiltCommon) AndroidMkEntries() []android.AndroidMkEntries { entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", !p.installable()) entries.AddStrings("LOCAL_OVERRIDES_MODULES", p.prebuiltCommonProperties.Overrides...) entries.SetString("LOCAL_APEX_KEY_PATH", p.apexKeysPath.String()) + if p.apkCertsFile != nil { + entries.SetString("LOCAL_APKCERTS_FILE", p.apkCertsFile.String()) + } + }, }, }, @@ -286,6 +296,14 @@ func (p *prebuiltCommon) hasExportedDeps() bool { len(p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments) > 0 } +type appInPrebuiltApexDepTag struct { + blueprint.BaseDependencyTag +} + +func (appInPrebuiltApexDepTag) ExcludeFromVisibilityEnforcement() {} + +var appInPrebuiltApexTag = appInPrebuiltApexDepTag{} + // prebuiltApexContentsDeps adds dependencies onto the prebuilt apex module's contents. func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) { module := ctx.Module() @@ -432,6 +450,12 @@ type PrebuiltProperties struct { ApexFileProperties PrebuiltCommonProperties + + // List of apps that are bundled inside this prebuilt apex. + // This will be used to create the certificate info of those apps for apkcerts.txt + // This dependency will only be used for apkcerts.txt processing. + // Notably, building the prebuilt apex will not build the source app. + Apps []string } func (a *Prebuilt) hasSanitizedSource(sanitizer string) bool { @@ -545,6 +569,9 @@ var ( func (p *Prebuilt) ComponentDepsMutator(ctx android.BottomUpMutatorContext) { p.prebuiltApexContentsDeps(ctx) + for _, app := range p.properties.Apps { + ctx.AddDependency(p, appInPrebuiltApexTag, app) + } } var _ ApexTransitionMutator = (*Prebuilt)(nil) @@ -677,11 +704,59 @@ func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { p.provenanceMetaDataFile = provenance.GenerateArtifactProvenanceMetaData(ctx, p.inputApex, p.installedFile) } + p.addApkCertsInfo(ctx) + ctx.SetOutputFiles(android.Paths{p.outputApex}, "") android.SetProvider(ctx, filesystem.ApexKeyPathInfoProvider, filesystem.ApexKeyPathInfo{p.apexKeysPath}) } +// `addApkCertsInfo` sets a provider that will be used to create apkcerts.txt +func (p *Prebuilt) addApkCertsInfo(ctx android.ModuleContext) { + formatLine := func(cert java.Certificate, name, partition string) string { + pem := cert.AndroidMkString() + var key string + if cert.Key == nil { + key = "" + } else { + key = cert.Key.String() + } + return fmt.Sprintf(`name="%s" certificate="%s" private_key="%s" partition="%s"`, name, pem, key, partition) + } + + // Determine if this prebuilt_apex contains any .apks + var appInfos java.AppInfos + ctx.VisitDirectDepsProxyWithTag(appInPrebuiltApexTag, func(app android.ModuleProxy) { + if appInfo, ok := android.OtherModuleProvider(ctx, app, java.AppInfoProvider); ok { + appInfos = append(appInfos, *appInfo) + } else { + ctx.ModuleErrorf("App %s does not set AppInfoProvider\n", app.Name()) + } + }) + sort.Slice(appInfos, func(i, j int) bool { + return appInfos[i].InstallApkName < appInfos[j].InstallApkName + }) + + if len(appInfos) == 0 { + return + } + + // Set a provider for use by `android_device`. + // `android_device` will create an apkcerts.txt with the list of installed apps for that device. + android.SetProvider(ctx, java.AppInfosProvider, appInfos) + + // Set a Make variable for legacy apkcerts.txt creation + // p.apkCertsFile will become `LOCAL_APKCERTS_FILE` + var lines []string + for _, appInfo := range appInfos { + lines = append(lines, formatLine(appInfo.Certificate, appInfo.InstallApkName+".apk", p.PartitionTag(ctx.DeviceConfig()))) + } + if len(lines) > 0 { + p.apkCertsFile = android.PathForModuleOut(ctx, "apkcerts.txt") + android.WriteFileRule(ctx, p.apkCertsFile, strings.Join(lines, "\n")) + } +} + func (p *Prebuilt) ProvenanceMetaDataFile() android.Path { return p.provenanceMetaDataFile } diff --git a/ci_tests/ci_test_package_zip.go b/ci_tests/ci_test_package_zip.go index d7aaa6686..4cadffddc 100644 --- a/ci_tests/ci_test_package_zip.go +++ b/ci_tests/ci_test_package_zip.go @@ -68,7 +68,7 @@ var ( pctx = android.NewPackageContext("android/soong/ci_tests") // test_package module type should only be used for the following modules. // TODO: remove "_soong" from the module names inside when eliminating the corresponding make modules - moduleNamesAllowed = []string{"continuous_native_tests_soong", "continuous_instrumentation_tests_soong", "platform_tests"} + moduleNamesAllowed = []string{"continuous_instrumentation_tests_soong", "continuous_instrumentation_metric_tests_soong", "continuous_native_tests_soong", "continuous_native_metric_tests_soong", "platform_tests"} ) func (p *testPackageZip) DepsMutator(ctx android.BottomUpMutatorContext) { @@ -150,12 +150,6 @@ func (p *testPackageZip) GenerateAndroidBuildActions(ctx android.ModuleContext) p.output = createOutput(ctx, pctx) ctx.SetOutputFiles(android.Paths{p.output}, "") - - // dist the test output - if ctx.ModuleName() == "platform_tests" { - distedName := ctx.Config().Getenv("TARGET_PRODUCT") + "-tests-FILE_NAME_TAG_PLACEHOLDER.zip" - ctx.DistForGoalWithFilename("platform_tests", p.output, distedName) - } } func createOutput(ctx android.ModuleContext, pctx android.PackageContext) android.ModuleOutPath { |