diff options
93 files changed, 1636 insertions, 974 deletions
diff --git a/Android.bp b/Android.bp index 523f55c4b..337545bce 100644 --- a/Android.bp +++ b/Android.bp @@ -150,10 +150,11 @@ cc_defaults { arch: { arm64: { cflags: [ - // Prevent the compiler from optimizing code using SVE, as the - // baremetal environment might not have configured the hardware. - "-Xclang -target-feature", - "-Xclang -sve", + // Override the global -march= flag (as set by TARGET_ARCH_VARIANT) + // and explicitly use the baseline architecture (ARMv8-A is the first + // version with 64-bit support) to avoid emitting potentially + // unsupported instructions. + "-march=armv8-a", ], }, }, diff --git a/aconfig/exported_java_aconfig_library.go b/aconfig/exported_java_aconfig_library.go index 63d824a88..ffb2a0cbe 100644 --- a/aconfig/exported_java_aconfig_library.go +++ b/aconfig/exported_java_aconfig_library.go @@ -15,8 +15,9 @@ package aconfig import ( - "android/soong/android" "strconv" + + "android/soong/android" ) func ExportedJavaDeclarationsLibraryFactory() android.Singleton { @@ -30,7 +31,7 @@ type exportedJavaDeclarationsLibrarySingleton struct { func (this *exportedJavaDeclarationsLibrarySingleton) GenerateBuildActions(ctx android.SingletonContext) { // Find all of the aconfig_declarations modules var cacheFiles android.Paths - ctx.VisitAllModules(func(module android.Module) { + ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { decl, ok := android.OtherModuleProvider(ctx, module, android.AconfigDeclarationsProviderKey) if !ok { return diff --git a/android/Android.bp b/android/Android.bp index aef18fec0..1cc7ffe1d 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -112,6 +112,7 @@ bootstrap_go_package { "soong_config_modules.go", "team.go", "test_asserts.go", + "test_mapping_zip.go", "test_suites.go", "testing.go", "transition.go", diff --git a/android/aconfig_providers.go b/android/aconfig_providers.go index b698d24a5..205b85590 100644 --- a/android/aconfig_providers.go +++ b/android/aconfig_providers.go @@ -136,7 +136,7 @@ func aconfigUpdateAndroidBuildActions(ctx ModuleContext) { AconfigFiles: mergedAconfigFiles, ModeInfos: mergedModeInfos, }) - ctx.setAconfigPaths(getAconfigFilePaths(ctx.Module().base(), mergedAconfigFiles)) + ctx.setAconfigPaths(getAconfigFilePaths(getContainer(ctx.Module()), mergedAconfigFiles)) } } @@ -147,7 +147,8 @@ func aconfigUpdateAndroidMkData(ctx fillInEntriesContext, mod Module, data *Andr return } data.Extra = append(data.Extra, func(w io.Writer, outputFile Path) { - AndroidMkEmitAssignList(w, "LOCAL_ACONFIG_FILES", getAconfigFilePaths(mod.base(), info.AconfigFiles).Strings()) + AndroidMkEmitAssignList(w, "LOCAL_ACONFIG_FILES", getAconfigFilePaths( + getContainerUsingProviders(ctx, mod), info.AconfigFiles).Strings()) }) // If there is a Custom writer, it needs to support this provider. if data.Custom != nil { @@ -179,24 +180,29 @@ func aconfigUpdateAndroidMkEntries(ctx fillInEntriesContext, mod Module, entries // All of the files in the module potentially depend on the aconfig flag values. for idx, _ := range *entries { (*entries)[idx].ExtraEntries = append((*entries)[idx].ExtraEntries, - func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) { - entries.AddPaths("LOCAL_ACONFIG_FILES", getAconfigFilePaths(mod.base(), info.AconfigFiles)) + func(_ AndroidMkExtraEntriesContext, entries *AndroidMkEntries) { + entries.AddPaths("LOCAL_ACONFIG_FILES", getAconfigFilePaths( + getContainerUsingProviders(ctx, mod), info.AconfigFiles)) }, ) } } +// TODO(b/397766191): Change the signature to take ModuleProxy +// Please only access the module's internal data through providers. func aconfigUpdateAndroidMkInfos(ctx fillInEntriesContext, mod Module, infos *AndroidMkProviderInfo) { info, ok := OtherModuleProvider(ctx, mod, AconfigPropagatingProviderKey) if !ok || len(info.AconfigFiles) == 0 { return } // All of the files in the module potentially depend on the aconfig flag values. - infos.PrimaryInfo.AddPaths("LOCAL_ACONFIG_FILES", getAconfigFilePaths(mod.base(), info.AconfigFiles)) + infos.PrimaryInfo.AddPaths("LOCAL_ACONFIG_FILES", getAconfigFilePaths( + getContainerUsingProviders(ctx, mod), info.AconfigFiles)) if len(infos.ExtraInfo) > 0 { for _, ei := range (*infos).ExtraInfo { - ei.AddPaths("LOCAL_ACONFIG_FILES", getAconfigFilePaths(mod.base(), info.AconfigFiles)) + ei.AddPaths("LOCAL_ACONFIG_FILES", getAconfigFilePaths( + getContainerUsingProviders(ctx, mod), info.AconfigFiles)) } } } @@ -224,19 +230,39 @@ func mergeAconfigFiles(ctx ModuleContext, container string, inputs Paths, genera return Paths{output} } -func getAconfigFilePaths(m *ModuleBase, aconfigFiles map[string]Paths) (paths Paths) { - // TODO(b/311155208): The default container here should be system. +func getContainer(m Module) string { container := "system" + base := m.base() + if base.SocSpecific() { + container = "vendor" + } else if base.ProductSpecific() { + container = "product" + } else if base.SystemExtSpecific() { + // system_ext and system partitions should be treated as one container + container = "system" + } - if m.SocSpecific() { + return container +} + +// TODO(b/397766191): Change the signature to take ModuleProxy +// Please only access the module's internal data through providers. +func getContainerUsingProviders(ctx OtherModuleProviderContext, m Module) string { + container := "system" + commonInfo, _ := OtherModuleProvider(ctx, m, CommonModuleInfoKey) + if commonInfo.Vendor || commonInfo.Proprietary || commonInfo.SocSpecific { container = "vendor" - } else if m.ProductSpecific() { + } else if commonInfo.ProductSpecific { container = "product" - } else if m.SystemExtSpecific() { + } else if commonInfo.SystemExtSpecific { // system_ext and system partitions should be treated as one container container = "system" } + return container +} + +func getAconfigFilePaths(container string, aconfigFiles map[string]Paths) (paths Paths) { paths = append(paths, aconfigFiles[container]...) if container == "system" { // TODO(b/311155208): Once the default container is system, we can drop this. diff --git a/android/all_teams.go b/android/all_teams.go index 3b20107b9..8b55adebd 100644 --- a/android/all_teams.go +++ b/android/all_teams.go @@ -78,19 +78,19 @@ func (t *allTeamsSingleton) GenerateBuildActions(ctx SingletonContext) { t.teams = make(map[string]teamProperties) t.teams_for_mods = make(map[string]moduleTeamAndTestInfo) - ctx.VisitAllModules(func(module Module) { + ctx.VisitAllModuleProxies(func(module ModuleProxy) { bpFile := ctx.BlueprintFile(module) // Package Modules and Team Modules are stored in a map so we can look them up by name for // modules without a team. - if pack, ok := module.(*packageModule); ok { + if pack, ok := OtherModuleProvider(ctx, module, PackageInfoProvider); ok { // Packages don't have names, use the blueprint file as the key. we can't get qualifiedModuleId in t context. pkgKey := bpFile - t.packages[pkgKey] = pack.properties + t.packages[pkgKey] = pack.Properties return } - if team, ok := module.(*teamModule); ok { - t.teams[team.Name()] = team.properties + if team, ok := OtherModuleProvider(ctx, module, TeamInfoProvider); ok { + t.teams[module.Name()] = team.Properties return } @@ -116,7 +116,7 @@ func (t *allTeamsSingleton) GenerateBuildActions(ctx SingletonContext) { testOnly: testModInfo.TestOnly, topLevelTestTarget: testModInfo.TopLevelTarget, kind: ctx.ModuleType(module), - teamName: module.base().Team(), + teamName: OtherModuleProviderOrDefault(ctx, module, CommonModuleInfoKey).Team, } t.teams_for_mods[module.Name()] = entry diff --git a/android/androidmk.go b/android/androidmk.go index c081ba372..6a1701df3 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -107,8 +107,6 @@ type AndroidMkEntries struct { SubName string // If set, this value overrides the base module name. SubName is still appended. OverrideName string - // Dist files to output - DistFiles TaggedDistFiles // The output file for Kati to process and/or install. If absent, the module is skipped. OutputFile OptionalPath // If true, the module is skipped and does not appear on the final Android-<product name>.mk @@ -351,36 +349,15 @@ func (d *distCopies) Strings() (ret []string) { return } -// Compute the contributions that the module makes to the dist. -func (a *AndroidMkEntries) getDistContributions(mod Module) *distContributions { +// This gets the dist contributuions from the given module that were specified in the Android.bp +// file using the dist: property. It does not include contribututions that the module's +// implementation may have defined with ctx.DistForGoals(), for that, see DistProvider. +func getDistContributions(ctx ConfigAndOtherModuleProviderContext, mod Module) *distContributions { amod := mod.base() name := amod.BaseModuleName() - // Collate the set of associated tag/paths available for copying to the dist. - // Start with an empty (nil) set. - var availableTaggedDists TaggedDistFiles - - // Then merge in any that are provided explicitly by the module. - if a.DistFiles != nil { - // Merge the DistFiles into the set. - availableTaggedDists = availableTaggedDists.merge(a.DistFiles) - } - - // If no paths have been provided for the DefaultDistTag and the output file is - // valid then add that as the default dist path. - if _, ok := availableTaggedDists[DefaultDistTag]; !ok && a.OutputFile.Valid() { - availableTaggedDists = availableTaggedDists.addPathsForTag(DefaultDistTag, a.OutputFile.Path()) - } - - info := OtherModuleProviderOrDefault(a.entryContext, mod, InstallFilesProvider) - // If the distFiles created by GenerateTaggedDistFiles contains paths for the - // DefaultDistTag then that takes priority so delete any existing paths. - if _, ok := info.DistFiles[DefaultDistTag]; ok { - delete(availableTaggedDists, DefaultDistTag) - } - - // Finally, merge the distFiles created by GenerateTaggedDistFiles. - availableTaggedDists = availableTaggedDists.merge(info.DistFiles) + info := OtherModuleProviderOrDefault(ctx, mod, InstallFilesProvider) + availableTaggedDists := info.DistFiles if len(availableTaggedDists) == 0 { // Nothing dist-able for this module. @@ -454,7 +431,7 @@ func (a *AndroidMkEntries) getDistContributions(mod Module) *distContributions { productString := "" if dist.Append_artifact_with_product != nil && *dist.Append_artifact_with_product { - productString = fmt.Sprintf("_%s", a.entryContext.Config().DeviceProduct()) + productString = fmt.Sprintf("_%s", ctx.Config().DeviceProduct()) } if suffix != "" || productString != "" { @@ -502,7 +479,7 @@ func generateDistContributionsForMake(distContributions *distContributions) []st // Compute the list of Make strings to declare phony goals and dist-for-goals // calls from the module's dist and dists properties. func (a *AndroidMkEntries) GetDistForGoals(mod Module) []string { - distContributions := a.getDistContributions(mod) + distContributions := getDistContributions(a.entryContext, mod) if distContributions == nil { return nil } @@ -775,6 +752,8 @@ func (so *soongOnlyAndroidMkSingleton) GenerateBuildActions(ctx SingletonContext // In soong-only mode, we don't do most of the androidmk stuff. But disted files are still largely // defined through the androidmk mechanisms, so this function is an alternate implementation of // the androidmk singleton that just focuses on getting the dist contributions +// TODO(b/397766191): Change the signature to take ModuleProxy +// Please only access the module's internal data through providers. func (so *soongOnlyAndroidMkSingleton) soongOnlyBuildActions(ctx SingletonContext, mods []Module) { allDistContributions, moduleInfoJSONs := getSoongOnlyDataFromMods(ctx, mods) @@ -895,31 +874,23 @@ func getSoongOnlyDataFromMods(ctx fillInEntriesContext, mods []Module) ([]distCo } } - if shouldSkipAndroidMkProcessing(ctx, mod.base()) { + commonInfo, _ := OtherModuleProvider(ctx, mod, CommonModuleInfoKey) + if commonInfo.SkipAndroidMkProcessing { continue } if info, ok := OtherModuleProvider(ctx, mod, AndroidMkInfoProvider); ok { // Deep copy the provider info since we need to modify the info later info := deepCopyAndroidMkProviderInfo(info) - info.PrimaryInfo.fillInEntries(ctx, mod) + info.PrimaryInfo.fillInEntries(ctx, mod, &commonInfo) if info.PrimaryInfo.disabled() { continue } if moduleInfoJSON, ok := OtherModuleProvider(ctx, mod, ModuleInfoJSONProvider); ok { moduleInfoJSONs = append(moduleInfoJSONs, moduleInfoJSON...) } - if contribution := info.PrimaryInfo.getDistContributions(ctx, mod); contribution != nil { + if contribution := getDistContributions(ctx, mod); contribution != nil { allDistContributions = append(allDistContributions, *contribution) } - for _, ei := range info.ExtraInfo { - ei.fillInEntries(ctx, mod) - if ei.disabled() { - continue - } - if contribution := ei.getDistContributions(ctx, mod); contribution != nil { - allDistContributions = append(allDistContributions, *contribution) - } - } } else { if x, ok := mod.(AndroidMkDataProvider); ok { data := x.AndroidMk() @@ -935,7 +906,7 @@ func getSoongOnlyDataFromMods(ctx fillInEntriesContext, mods []Module) ([]distCo if moduleInfoJSON, ok := OtherModuleProvider(ctx, mod, ModuleInfoJSONProvider); ok { moduleInfoJSONs = append(moduleInfoJSONs, moduleInfoJSON...) } - if contribution := data.Entries.getDistContributions(mod); contribution != nil { + if contribution := getDistContributions(ctx, mod); contribution != nil { allDistContributions = append(allDistContributions, *contribution) } } @@ -949,7 +920,7 @@ func getSoongOnlyDataFromMods(ctx fillInEntriesContext, mods []Module) ([]distCo if moduleInfoJSON, ok := OtherModuleProvider(ctx, mod, ModuleInfoJSONProvider); ok { moduleInfoJSONs = append(moduleInfoJSONs, moduleInfoJSON...) } - if contribution := entries.getDistContributions(mod); contribution != nil { + if contribution := getDistContributions(ctx, mod); contribution != nil { allDistContributions = append(allDistContributions, *contribution) } } @@ -1292,8 +1263,6 @@ type AndroidMkInfo struct { SubName string // If set, this value overrides the base module name. SubName is still appended. OverrideName string - // Dist files to output - DistFiles TaggedDistFiles // The output file for Kati to process and/or install. If absent, the module is skipped. OutputFile OptionalPath // If true, the module is skipped and does not appear on the final Android-<product name>.mk @@ -1333,9 +1302,12 @@ type AndroidMkProviderInfoProducer interface { // TODO: rename it to AndroidMkEntriesProvider after AndroidMkEntriesProvider interface is gone. var AndroidMkInfoProvider = blueprint.NewProvider[*AndroidMkProviderInfo]() +// TODO(b/397766191): Change the signature to take ModuleProxy +// Please only access the module's internal data through providers. func translateAndroidMkEntriesInfoModule(ctx SingletonContext, w io.Writer, moduleInfoJSONs *[]*ModuleInfoJSON, mod Module, providerInfo *AndroidMkProviderInfo) error { - if shouldSkipAndroidMkProcessing(ctx, mod.base()) { + commonInfo, _ := OtherModuleProvider(ctx, mod, CommonModuleInfoKey) + if commonInfo.SkipAndroidMkProcessing { return nil } @@ -1345,11 +1317,11 @@ func translateAndroidMkEntriesInfoModule(ctx SingletonContext, w io.Writer, modu aconfigUpdateAndroidMkInfos(ctx, mod, &info) // Any new or special cases here need review to verify correct propagation of license information. - info.PrimaryInfo.fillInEntries(ctx, mod) + info.PrimaryInfo.fillInEntries(ctx, mod, &commonInfo) info.PrimaryInfo.write(w) if len(info.ExtraInfo) > 0 { for _, ei := range info.ExtraInfo { - ei.fillInEntries(ctx, mod) + ei.fillInEntries(ctx, mod, &commonInfo) ei.write(w) } } @@ -1478,13 +1450,14 @@ func (a *AndroidMkInfo) AddCompatibilityTestSuites(suites ...string) { a.AddStrings("LOCAL_COMPATIBILITY_SUITE", suites...) } -func (a *AndroidMkInfo) fillInEntries(ctx fillInEntriesContext, mod Module) { +// TODO(b/397766191): Change the signature to take ModuleProxy +// Please only access the module's internal data through providers. +func (a *AndroidMkInfo) fillInEntries(ctx fillInEntriesContext, mod Module, commonInfo *CommonModuleInfo) { helperInfo := AndroidMkInfo{ EntryMap: make(map[string][]string), } - base := mod.base() - name := base.BaseModuleName() + name := commonInfo.BaseModuleName if a.OverrideName != "" { name = a.OverrideName } @@ -1492,16 +1465,16 @@ func (a *AndroidMkInfo) fillInEntries(ctx fillInEntriesContext, mod Module) { if a.Include == "" { a.Include = "$(BUILD_PREBUILT)" } - a.Required = append(a.Required, mod.RequiredModuleNames(ctx)...) - a.Required = append(a.Required, mod.VintfFragmentModuleNames(ctx)...) - a.Host_required = append(a.Host_required, mod.HostRequiredModuleNames()...) - a.Target_required = append(a.Target_required, mod.TargetRequiredModuleNames()...) + a.Required = append(a.Required, commonInfo.RequiredModuleNames...) + a.Required = append(a.Required, commonInfo.VintfFragmentModuleNames...) + a.Host_required = append(a.Host_required, commonInfo.HostRequiredModuleNames...) + a.Target_required = append(a.Target_required, commonInfo.TargetRequiredModuleNames...) - for _, distString := range a.GetDistForGoals(ctx, mod) { + for _, distString := range a.GetDistForGoals(ctx, mod, commonInfo) { a.HeaderStrings = append(a.HeaderStrings, distString) } - a.HeaderStrings = append(a.HeaderStrings, fmt.Sprintf("\ninclude $(CLEAR_VARS) # type: %s, name: %s, variant: %s", ctx.ModuleType(mod), base.BaseModuleName(), ctx.ModuleSubDir(mod))) + a.HeaderStrings = append(a.HeaderStrings, fmt.Sprintf("\ninclude $(CLEAR_VARS) # type: %s, name: %s, variant: %s", ctx.ModuleType(mod), commonInfo.BaseModuleName, ctx.ModuleSubDir(mod))) // Collect make variable assignment entries. helperInfo.SetString("LOCAL_PATH", ctx.ModuleDir(mod)) @@ -1526,7 +1499,7 @@ func (a *AndroidMkInfo) fillInEntries(ctx fillInEntriesContext, mod Module) { // Soong may not have generated the install rule also when `no_full_install: true`. // Mark this module as uninstallable in order to prevent Make from creating an // install rule there. - helperInfo.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", proptools.Bool(base.commonProperties.No_full_install)) + helperInfo.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", commonInfo.NoFullInstall) } if info.UncheckedModule { @@ -1541,31 +1514,31 @@ func (a *AndroidMkInfo) fillInEntries(ctx fillInEntriesContext, mod Module) { helperInfo.AddStrings("LOCAL_TEST_DATA", androidMkDataPaths(info.TestData)...) } - if am, ok := mod.(ApexModule); ok { - helperInfo.SetBoolIfTrue("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", am.NotAvailableForPlatform()) + if commonInfo.IsApexModule { + helperInfo.SetBoolIfTrue("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", commonInfo.NotAvailableForPlatform) } - archStr := base.Arch().ArchType.String() + archStr := commonInfo.Target.Arch.ArchType.String() host := false - switch base.Os().Class { + switch commonInfo.Target.Os.Class { case Host: - if base.Target().HostCross { + if commonInfo.Target.HostCross { // Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common. - if base.Arch().ArchType != Common { + if commonInfo.Target.Arch.ArchType != Common { helperInfo.SetString("LOCAL_MODULE_HOST_CROSS_ARCH", archStr) } } else { // Make cannot identify LOCAL_MODULE_HOST_ARCH:= common. - if base.Arch().ArchType != Common { + if commonInfo.Target.Arch.ArchType != Common { helperInfo.SetString("LOCAL_MODULE_HOST_ARCH", archStr) } } host = true case Device: // Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common. - if base.Arch().ArchType != Common { - if base.Target().NativeBridge { - hostArchStr := base.Target().NativeBridgeHostArchName + if commonInfo.Target.Arch.ArchType != Common { + if commonInfo.Target.NativeBridge { + hostArchStr := commonInfo.Target.NativeBridgeHostArchName if hostArchStr != "" { helperInfo.SetString("LOCAL_MODULE_TARGET_ARCH", hostArchStr) } @@ -1574,27 +1547,28 @@ func (a *AndroidMkInfo) fillInEntries(ctx fillInEntriesContext, mod Module) { } } - if !base.InVendorRamdisk() { + if !commonInfo.InVendorRamdisk { helperInfo.AddPaths("LOCAL_FULL_INIT_RC", info.InitRcPaths) } if len(info.VintfFragmentsPaths) > 0 { helperInfo.AddPaths("LOCAL_FULL_VINTF_FRAGMENTS", info.VintfFragmentsPaths) } - helperInfo.SetBoolIfTrue("LOCAL_PROPRIETARY_MODULE", Bool(base.commonProperties.Proprietary)) - if Bool(base.commonProperties.Vendor) || Bool(base.commonProperties.Soc_specific) { + helperInfo.SetBoolIfTrue("LOCAL_PROPRIETARY_MODULE", commonInfo.Proprietary) + if commonInfo.Vendor || commonInfo.SocSpecific { helperInfo.SetString("LOCAL_VENDOR_MODULE", "true") } - helperInfo.SetBoolIfTrue("LOCAL_ODM_MODULE", Bool(base.commonProperties.Device_specific)) - helperInfo.SetBoolIfTrue("LOCAL_PRODUCT_MODULE", Bool(base.commonProperties.Product_specific)) - helperInfo.SetBoolIfTrue("LOCAL_SYSTEM_EXT_MODULE", Bool(base.commonProperties.System_ext_specific)) - if base.commonProperties.Owner != nil { - helperInfo.SetString("LOCAL_MODULE_OWNER", *base.commonProperties.Owner) + helperInfo.SetBoolIfTrue("LOCAL_ODM_MODULE", commonInfo.DeviceSpecific) + helperInfo.SetBoolIfTrue("LOCAL_PRODUCT_MODULE", commonInfo.ProductSpecific) + helperInfo.SetBoolIfTrue("LOCAL_SYSTEM_EXT_MODULE", commonInfo.SystemExtSpecific) + if commonInfo.Owner != "" { + helperInfo.SetString("LOCAL_MODULE_OWNER", commonInfo.Owner) } } if host { - makeOs := base.Os().String() - if base.Os() == Linux || base.Os() == LinuxBionic || base.Os() == LinuxMusl { + os := commonInfo.Target.Os + makeOs := os.String() + if os == Linux || os == LinuxBionic || os == LinuxMusl { makeOs = "linux" } helperInfo.SetString("LOCAL_MODULE_HOST_OS", makeOs) @@ -1652,8 +1626,10 @@ func (a *AndroidMkInfo) write(w io.Writer) { // Compute the list of Make strings to declare phony goals and dist-for-goals // calls from the module's dist and dists properties. -func (a *AndroidMkInfo) GetDistForGoals(ctx fillInEntriesContext, mod Module) []string { - distContributions := a.getDistContributions(ctx, mod) +// TODO(b/397766191): Change the signature to take ModuleProxy +// Please only access the module's internal data through providers. +func (a *AndroidMkInfo) GetDistForGoals(ctx fillInEntriesContext, mod Module, commonInfo *CommonModuleInfo) []string { + distContributions := getDistContributions(ctx, mod) if distContributions == nil { return nil } @@ -1661,131 +1637,6 @@ func (a *AndroidMkInfo) GetDistForGoals(ctx fillInEntriesContext, mod Module) [] return generateDistContributionsForMake(distContributions) } -// Compute the contributions that the module makes to the dist. -func (a *AndroidMkInfo) getDistContributions(ctx fillInEntriesContext, mod Module) *distContributions { - amod := mod.base() - name := amod.BaseModuleName() - - // Collate the set of associated tag/paths available for copying to the dist. - // Start with an empty (nil) set. - var availableTaggedDists TaggedDistFiles - - // Then merge in any that are provided explicitly by the module. - if a.DistFiles != nil { - // Merge the DistFiles into the set. - availableTaggedDists = availableTaggedDists.merge(a.DistFiles) - } - - // If no paths have been provided for the DefaultDistTag and the output file is - // valid then add that as the default dist path. - if _, ok := availableTaggedDists[DefaultDistTag]; !ok && a.OutputFile.Valid() { - availableTaggedDists = availableTaggedDists.addPathsForTag(DefaultDistTag, a.OutputFile.Path()) - } - - info := OtherModuleProviderOrDefault(ctx, mod, InstallFilesProvider) - // If the distFiles created by GenerateTaggedDistFiles contains paths for the - // DefaultDistTag then that takes priority so delete any existing paths. - if _, ok := info.DistFiles[DefaultDistTag]; ok { - delete(availableTaggedDists, DefaultDistTag) - } - - // Finally, merge the distFiles created by GenerateTaggedDistFiles. - availableTaggedDists = availableTaggedDists.merge(info.DistFiles) - - if len(availableTaggedDists) == 0 { - // Nothing dist-able for this module. - return nil - } - - // Collate the contributions this module makes to the dist. - distContributions := &distContributions{} - - if !exemptFromRequiredApplicableLicensesProperty(mod) { - distContributions.licenseMetadataFile = info.LicenseMetadataFile - } - - // Iterate over this module's dist structs, merged from the dist and dists properties. - for _, dist := range amod.Dists() { - // Get the list of goals this dist should be enabled for. e.g. sdk, droidcore - goals := strings.Join(dist.Targets, " ") - - // Get the tag representing the output files to be dist'd. e.g. ".jar", ".proguard_map" - var tag string - if dist.Tag == nil { - // If the dist struct does not specify a tag, use the default output files tag. - tag = DefaultDistTag - } else { - tag = *dist.Tag - } - - // Get the paths of the output files to be dist'd, represented by the tag. - // Can be an empty list. - tagPaths := availableTaggedDists[tag] - if len(tagPaths) == 0 { - // Nothing to dist for this tag, continue to the next dist. - continue - } - - if len(tagPaths) > 1 && (dist.Dest != nil || dist.Suffix != nil) { - errorMessage := "%s: Cannot apply dest/suffix for more than one dist " + - "file for %q goals tag %q in module %s. The list of dist files, " + - "which should have a single element, is:\n%s" - panic(fmt.Errorf(errorMessage, mod, goals, tag, name, tagPaths)) - } - - copiesForGoals := distContributions.getCopiesForGoals(goals) - - // Iterate over each path adding a copy instruction to copiesForGoals - for _, path := range tagPaths { - // It's possible that the Path is nil from errant modules. Be defensive here. - if path == nil { - tagName := "default" // for error message readability - if dist.Tag != nil { - tagName = *dist.Tag - } - panic(fmt.Errorf("Dist file should not be nil for the %s tag in %s", tagName, name)) - } - - dest := filepath.Base(path.String()) - - if dist.Dest != nil { - var err error - if dest, err = validateSafePath(*dist.Dest); err != nil { - // This was checked in ModuleBase.GenerateBuildActions - panic(err) - } - } - - ext := filepath.Ext(dest) - suffix := "" - if dist.Suffix != nil { - suffix = *dist.Suffix - } - - productString := "" - if dist.Append_artifact_with_product != nil && *dist.Append_artifact_with_product { - productString = fmt.Sprintf("_%s", ctx.Config().DeviceProduct()) - } - - if suffix != "" || productString != "" { - dest = strings.TrimSuffix(dest, ext) + suffix + productString + ext - } - - if dist.Dir != nil { - var err error - if dest, err = validateSafePath(*dist.Dir, dest); err != nil { - // This was checked in ModuleBase.GenerateBuildActions - panic(err) - } - } - - copiesForGoals.addCopyInstruction(path, dest) - } - } - - return distContributions -} - func deepCopyAndroidMkProviderInfo(providerInfo *AndroidMkProviderInfo) AndroidMkProviderInfo { info := AndroidMkProviderInfo{ PrimaryInfo: deepCopyAndroidMkInfo(&providerInfo.PrimaryInfo), @@ -1803,9 +1654,8 @@ func deepCopyAndroidMkInfo(mkinfo *AndroidMkInfo) AndroidMkInfo { Class: mkinfo.Class, SubName: mkinfo.SubName, OverrideName: mkinfo.OverrideName, - // There is no modification on DistFiles or OutputFile, so no need to + // There is no modification on OutputFile, so no need to // make their deep copy. - DistFiles: mkinfo.DistFiles, OutputFile: mkinfo.OutputFile, Disabled: mkinfo.Disabled, Include: mkinfo.Include, diff --git a/android/androidmk_test.go b/android/androidmk_test.go index 0a81fb8bf..cd61133ef 100644 --- a/android/androidmk_test.go +++ b/android/androidmk_test.go @@ -34,7 +34,6 @@ type customModule struct { } data AndroidMkData - distFiles TaggedDistFiles outputFile OptionalPath } @@ -73,7 +72,6 @@ func (m *customModule) GenerateAndroidBuildActions(ctx ModuleContext) { path := PathForTesting("default-dist.out") defaultDistPaths = Paths{path} m.setOutputFiles(ctx, defaultDistPaths) - m.distFiles = MakeDefaultDistFiles(path) case defaultDistFiles_Tagged: // Module types that set AndroidMkEntry.DistFiles to the result of calling @@ -84,11 +82,6 @@ func (m *customModule) GenerateAndroidBuildActions(ctx ModuleContext) { // will be the same as empty-string-tag output. defaultDistPaths = PathsForTesting("one.out") m.setOutputFiles(ctx, defaultDistPaths) - - // This must be called after setting defaultDistPaths/outputFile as - // GenerateTaggedDistFiles calls into outputFiles property which may use - // those fields. - m.distFiles = m.GenerateTaggedDistFiles(ctx) } } @@ -113,7 +106,6 @@ func (m *customModule) AndroidMkEntries() []AndroidMkEntries { return []AndroidMkEntries{ { Class: "CUSTOM_MODULE", - DistFiles: m.distFiles, OutputFile: m.outputFile, }, } @@ -354,7 +346,7 @@ func TestGetDistContributions(t *testing.T) { if len(entries) != 1 { t.Errorf("Expected a single AndroidMk entry, got %d", len(entries)) } - distContributions := entries[0].getDistContributions(module) + distContributions := getDistContributions(ctx, module) if err := compareContributions(expectedContributions, distContributions); err != nil { t.Errorf("%s\nExpected Contributions\n%sActualContributions\n%s", @@ -656,8 +648,8 @@ func TestGetDistContributions(t *testing.T) { default_dist_files: "none", dist_output_file: false, dists: [ - // The following is silently ignored because there is not default file - // in either the dist files or the output file. + // The following will dist one.out because there's no default dist file provided + // (default_dist_files: "none") and one.out is the outputfile for the "" tag. { targets: ["my_goal"], }, @@ -672,6 +664,12 @@ func TestGetDistContributions(t *testing.T) { { goals: "my_goal", copies: []distCopy{ + distCopyForTest("one.out", "one.out"), + }, + }, + { + goals: "my_goal", + copies: []distCopy{ distCopyForTest("two.out", "two.out"), distCopyForTest("three/four.out", "four.out"), }, diff --git a/android/apex.go b/android/apex.go index 91fa2c718..4e92f44f6 100644 --- a/android/apex.go +++ b/android/apex.go @@ -646,6 +646,13 @@ type ApexBundleDepsInfoIntf interface { FullListPath() Path } +type ApexBundleDepsData struct { + Updatable bool + FlatListPath Path +} + +var ApexBundleDepsDataProvider = blueprint.NewProvider[ApexBundleDepsData]() + func (d *ApexBundleDepsInfo) FlatListPath() Path { return d.flatListPath } diff --git a/android/compliance_metadata.go b/android/compliance_metadata.go index 35805a2a8..a6dbb8d17 100644 --- a/android/compliance_metadata.go +++ b/android/compliance_metadata.go @@ -275,16 +275,18 @@ func (c *complianceMetadataSingleton) GenerateBuildActions(ctx SingletonContext) writerToCsv(csvWriter, columnNames) rowId := -1 - ctx.VisitAllModules(func(module Module) { - if !module.Enabled(ctx) { + ctx.VisitAllModuleProxies(func(module ModuleProxy) { + commonInfo, _ := OtherModuleProvider(ctx, module, CommonModuleInfoKey) + if !commonInfo.Enabled { return } + moduleType := ctx.ModuleType(module) if moduleType == "package" { metadataMap := map[string]string{ ComplianceMetadataProp.NAME: ctx.ModuleName(module), ComplianceMetadataProp.MODULE_TYPE: ctx.ModuleType(module), - ComplianceMetadataProp.PKG_DEFAULT_APPLICABLE_LICENSES: strings.Join(module.base().primaryLicensesProperty.getStrings(), " "), + ComplianceMetadataProp.PKG_DEFAULT_APPLICABLE_LICENSES: strings.Join(commonInfo.PrimaryLicensesProperty.getStrings(), " "), } rowId = rowId + 1 metadata := []string{strconv.Itoa(rowId)} @@ -294,8 +296,7 @@ func (c *complianceMetadataSingleton) GenerateBuildActions(ctx SingletonContext) writerToCsv(csvWriter, metadata) return } - if provider, ok := ctx.otherModuleProvider(module, ComplianceMetadataProvider); ok { - metadataInfo := provider.(*ComplianceMetadataInfo) + if metadataInfo, ok := OtherModuleProvider(ctx, module, ComplianceMetadataProvider); ok { rowId = rowId + 1 metadata := []string{strconv.Itoa(rowId)} for _, propertyName := range COMPLIANCE_METADATA_PROPS { diff --git a/android/config.go b/android/config.go index 3867c1197..0a1ed98d2 100644 --- a/android/config.go +++ b/android/config.go @@ -2176,14 +2176,6 @@ func (c *config) UseOptimizedResourceShrinkingByDefault() bool { return c.productVariables.GetBuildFlagBool("RELEASE_USE_OPTIMIZED_RESOURCE_SHRINKING_BY_DEFAULT") } -func (c *config) UseResourceProcessorByDefault() bool { - return c.productVariables.GetBuildFlagBool("RELEASE_USE_RESOURCE_PROCESSOR_BY_DEFAULT") -} - -func (c *config) UseTransitiveJarsInClasspath() bool { - return c.productVariables.GetBuildFlagBool("RELEASE_USE_TRANSITIVE_JARS_IN_CLASSPATH") -} - func (c *config) UseR8FullModeByDefault() bool { return c.productVariables.GetBuildFlagBool("RELEASE_R8_FULL_MODE_BY_DEFAULT") } @@ -2196,6 +2188,10 @@ func (c *config) UseR8StoreStoreFenceConstructorInlining() bool { return c.productVariables.GetBuildFlagBool("RELEASE_R8_STORE_STORE_FENCE_CONSTRUCTOR_INLINING") } +func (c *config) UseR8GlobalCheckNotNullFlags() bool { + return c.productVariables.GetBuildFlagBool("RELEASE_R8_GLOBAL_CHECK_NOT_NULL_FLAGS") +} + func (c *config) UseDexV41() bool { return c.productVariables.GetBuildFlagBool("RELEASE_USE_DEX_V41") } @@ -2226,7 +2222,6 @@ var ( "RELEASE_APEX_CONTRIBUTIONS_NFC": "com.android.nfcservices", "RELEASE_APEX_CONTRIBUTIONS_ONDEVICEPERSONALIZATION": "com.android.ondevicepersonalization", "RELEASE_APEX_CONTRIBUTIONS_PERMISSION": "com.android.permission", - "RELEASE_APEX_CONTRIBUTIONS_PRIMARY_LIBS": "", "RELEASE_APEX_CONTRIBUTIONS_PROFILING": "com.android.profiling", "RELEASE_APEX_CONTRIBUTIONS_REMOTEKEYPROVISIONING": "com.android.rkpd", "RELEASE_APEX_CONTRIBUTIONS_RESOLV": "com.android.resolv", @@ -2279,10 +2274,18 @@ func (c *config) OemProperties() []string { } func (c *config) UseDebugArt() bool { + // If the ArtTargetIncludeDebugBuild product variable is set then return its value. if c.productVariables.ArtTargetIncludeDebugBuild != nil { return Bool(c.productVariables.ArtTargetIncludeDebugBuild) } + // If the RELEASE_APEX_CONTRIBUTIONS_ART build flag is set to use a prebuilt ART apex + // then don't use the debug apex. + if val, ok := c.GetBuildFlag("RELEASE_APEX_CONTRIBUTIONS_ART"); ok && val != "" { + return false + } + + // Default to the debug apex for eng builds. return Bool(c.productVariables.Eng) } diff --git a/android/filegroup.go b/android/filegroup.go index 47102b915..4fad52aaa 100644 --- a/android/filegroup.go +++ b/android/filegroup.go @@ -131,10 +131,11 @@ func (fg *fileGroup) Srcs() Paths { return append(Paths{}, fg.srcs...) } -func (fg *fileGroup) MakeVars(ctx MakeVarsModuleContext) { +func (fg *fileGroup) MakeVars(_ MakeVarsModuleContext) []ModuleMakeVarsValue { if makeVar := String(fg.properties.Export_to_make_var); makeVar != "" { - ctx.StrictRaw(makeVar, strings.Join(fg.srcs.Strings(), " ")) + return []ModuleMakeVarsValue{{makeVar, strings.Join(fg.srcs.Strings(), " ")}} } + return nil } // Defaults diff --git a/android/logtags.go b/android/logtags.go index abc37f997..88d36ec72 100644 --- a/android/logtags.go +++ b/android/logtags.go @@ -42,8 +42,8 @@ func MergedLogtagsPath(ctx PathContext) OutputPath { func (l *logtagsSingleton) GenerateBuildActions(ctx SingletonContext) { var allLogtags Paths - ctx.VisitAllModules(func(module Module) { - if !module.ExportedToMake() { + ctx.VisitAllModuleProxies(func(module ModuleProxy) { + if !OtherModuleProviderOrDefault(ctx, module, CommonModuleInfoKey).ExportedToMake { return } if logtagsInfo, ok := OtherModuleProvider(ctx, module, LogtagsProviderKey); ok { diff --git a/android/makevars.go b/android/makevars.go index 2931d0bed..692b27ec6 100644 --- a/android/makevars.go +++ b/android/makevars.go @@ -84,6 +84,7 @@ type MakeVarsContext interface { Errorf(format string, args ...interface{}) VisitAllModules(visit func(Module)) + VisitAllModuleProxies(visit func(proxy ModuleProxy)) VisitAllModulesIf(pred func(Module) bool, visit func(Module)) // Verify the make variable matches the Soong version, fail the build @@ -108,7 +109,7 @@ type MakeVarsContext interface { // MakeVarsModuleContext contains the set of functions available for modules // implementing the ModuleMakeVarsProvider interface. type MakeVarsModuleContext interface { - BaseMakeVarsContext + Config() Config } var _ PathContext = MakeVarsContext(nil) @@ -150,14 +151,21 @@ func singletonMakeVarsProviderAdapter(singleton SingletonMakeVarsProvider) MakeV return func(ctx MakeVarsContext) { singleton.MakeVars(ctx) } } +type ModuleMakeVarsValue struct { + // Make variable name. + Name string + // Make variable value. + Value string +} + // ModuleMakeVarsProvider is a Module with an extra method to provide extra values to be exported to Make. type ModuleMakeVarsProvider interface { - Module - // MakeVars uses a MakeVarsModuleContext to provide extra values to be exported to Make. - MakeVars(ctx MakeVarsModuleContext) + MakeVars(ctx MakeVarsModuleContext) []ModuleMakeVarsValue } +var ModuleMakeVarsInfoProvider = blueprint.NewProvider[[]ModuleMakeVarsValue]() + // ///////////////////////////////////////////////////////////////////////////// func makeVarsSingletonFunc() Singleton { @@ -250,19 +258,24 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) { dists = append(dists, singletonDists.dists...) singletonDists.lock.Unlock() - ctx.VisitAllModules(func(m Module) { - if provider, ok := m.(ModuleMakeVarsProvider); ok && m.Enabled(ctx) { + ctx.VisitAllModuleProxies(func(m ModuleProxy) { + commonInfo, _ := OtherModuleProvider(ctx, m, CommonModuleInfoKey) + if provider, ok := OtherModuleProvider(ctx, m, ModuleMakeVarsInfoProvider); ok && + commonInfo.Enabled { mctx := &makeVarsContext{ SingletonContext: ctx, } - - provider.MakeVars(mctx) + for _, val := range provider { + if val.Name != "" { + mctx.StrictRaw(val.Name, val.Value) + } + } vars = append(vars, mctx.vars...) phonies = append(phonies, mctx.phonies...) } - if m.ExportedToMake() { + if commonInfo.ExportedToMake { info := OtherModuleProviderOrDefault(ctx, m, InstallFilesProvider) katiInstalls = append(katiInstalls, info.KatiInstalls...) katiInitRcInstalls = append(katiInitRcInstalls, info.KatiInitRcInstalls...) diff --git a/android/metrics.go b/android/metrics.go index 6834b1bde..dc5170319 100644 --- a/android/metrics.go +++ b/android/metrics.go @@ -57,8 +57,8 @@ type soongMetricsSingleton struct{} func (soongMetricsSingleton) GenerateBuildActions(ctx SingletonContext) { metrics := getSoongMetrics(ctx.Config()) - ctx.VisitAllModules(func(m Module) { - if ctx.PrimaryModule(m) == m { + ctx.VisitAllModuleProxies(func(m ModuleProxy) { + if ctx.PrimaryModuleProxy(m) == m { metrics.modules++ } metrics.variants++ diff --git a/android/module.go b/android/module.go index c4a83777a..622399bb6 100644 --- a/android/module.go +++ b/android/module.go @@ -15,6 +15,7 @@ package android import ( + "errors" "fmt" "net/url" "path/filepath" @@ -613,17 +614,6 @@ func (t TaggedDistFiles) merge(other TaggedDistFiles) TaggedDistFiles { return t } -func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles { - for _, p := range paths { - if p == nil { - panic("The path to a dist file cannot be nil.") - } - } - - // The default OutputFile tag is the empty "" string. - return TaggedDistFiles{DefaultDistTag: paths} -} - type hostAndDeviceProperties struct { // If set to true, build a variant of the module for the host. Defaults to false. Host_supported *bool @@ -1230,6 +1220,13 @@ func (m *ModuleBase) GenerateTaggedDistFiles(ctx BaseModuleContext) TaggedDistFi tag := proptools.StringDefault(dist.Tag, DefaultDistTag) distFileForTagFromProvider, err := outputFilesForModuleFromProvider(ctx, m.module, tag) + + // If the module doesn't define output files for the DefaultDistTag, try the files under + // the "" tag. + if tag == DefaultDistTag && errors.Is(err, ErrUnsupportedOutputTag) { + distFileForTagFromProvider, err = outputFilesForModuleFromProvider(ctx, m.module, "") + } + if err != OutputFilesProviderNotSet { if err != nil && tag != DefaultDistTag { ctx.PropertyErrorf("dist.tag", "%s", err.Error()) @@ -1919,6 +1916,28 @@ type CommonModuleInfo struct { IsStubsModule bool Host bool IsApexModule bool + // The primary licenses property, may be nil, records license metadata for the module. + PrimaryLicensesProperty applicableLicensesProperty + Owner string + Vendor bool + Proprietary bool + SocSpecific bool + ProductSpecific bool + SystemExtSpecific bool + DeviceSpecific bool + // When set to true, this module is not installed to the full install path (ex: under + // out/target/product/<name>/<partition>). It can be installed only to the packaging + // modules like android_filesystem. + NoFullInstall bool + InVendorRamdisk bool + ExemptFromRequiredApplicableLicensesProperty bool + RequiredModuleNames []string + HostRequiredModuleNames []string + TargetRequiredModuleNames []string + VintfFragmentModuleNames []string + Dists []Dist + ExportedToMake bool + Team string } type ApiLevelOrPlatform struct { @@ -2254,6 +2273,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) buildComplianceMetadataProvider(ctx, m) commonData := CommonModuleInfo{ + Enabled: m.Enabled(ctx), ReplacedByPrebuilt: m.commonProperties.ReplacedByPrebuilt, Target: m.commonProperties.CompileTarget, SkipAndroidMkProcessing: shouldSkipAndroidMkProcessing(ctx, m), @@ -2261,6 +2281,24 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) HideFromMake: m.commonProperties.HideFromMake, SkipInstall: m.commonProperties.SkipInstall, Host: m.Host(), + PrimaryLicensesProperty: m.primaryLicensesProperty, + Owner: m.module.Owner(), + SocSpecific: Bool(m.commonProperties.Soc_specific), + Vendor: Bool(m.commonProperties.Vendor), + Proprietary: Bool(m.commonProperties.Proprietary), + ProductSpecific: Bool(m.commonProperties.Product_specific), + SystemExtSpecific: Bool(m.commonProperties.System_ext_specific), + DeviceSpecific: Bool(m.commonProperties.Device_specific), + NoFullInstall: proptools.Bool(m.commonProperties.No_full_install), + InVendorRamdisk: m.InVendorRamdisk(), + ExemptFromRequiredApplicableLicensesProperty: exemptFromRequiredApplicableLicensesProperty(m.module), + RequiredModuleNames: m.module.RequiredModuleNames(ctx), + HostRequiredModuleNames: m.module.HostRequiredModuleNames(), + TargetRequiredModuleNames: m.module.TargetRequiredModuleNames(), + VintfFragmentModuleNames: m.module.VintfFragmentModuleNames(ctx), + Dists: m.Dists(), + ExportedToMake: m.ExportedToMake(), + Team: m.Team(), } if mm, ok := m.module.(interface { MinSdkVersion(ctx EarlyModuleContext) ApiLevel @@ -2289,11 +2327,6 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) commonData.SdkVersion = mm.SdkVersion() } - if m.commonProperties.ForcedDisabled { - commonData.Enabled = false - } else { - commonData.Enabled = m.commonProperties.Enabled.GetOrDefault(m.ConfigurableEvaluator(ctx), !m.Os().DefaultDisabled) - } if am, ok := m.module.(ApexModule); ok { commonData.CanHaveApexVariants = am.CanHaveApexVariants() commonData.NotAvailableForPlatform = am.NotAvailableForPlatform() @@ -2336,6 +2369,10 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) GeneratedDeps: s.GeneratedDeps(), }) } + + if v, ok := m.module.(ModuleMakeVarsProvider); m.Enabled(ctx) && ok { + SetProvider(ctx, ModuleMakeVarsInfoProvider, v.MakeVars(ctx)) + } } func SetJarJarPrefixHandler(handler func(ModuleContext)) { @@ -2852,6 +2889,8 @@ func OutputFilesForModule(ctx PathContext, module Module, tag string) Paths { // OutputFileForModule returns the output file paths with the given tag. On error, including if the // module produced zero or multiple paths, it reports errors to the ctx and returns nil. +// TODO(b/397766191): Change the signature to take ModuleProxy +// Please only access the module's internal data through providers. func OutputFileForModule(ctx PathContext, module Module, tag string) Path { paths, err := outputFilesForModule(ctx, module, tag) if err != nil { @@ -2892,6 +2931,8 @@ type OutputFilesProviderModuleContext interface { EqualModules(m1, m2 Module) bool } +// TODO(b/397766191): Change the signature to take ModuleProxy +// Please only access the module's internal data through providers. func outputFilesForModule(ctx PathContext, module Module, tag string) (Paths, error) { outputFilesFromProvider, err := outputFilesForModuleFromProvider(ctx, module, tag) if outputFilesFromProvider != nil || err != OutputFilesProviderNotSet { @@ -2924,14 +2965,12 @@ func outputFilesForModule(ctx PathContext, module Module, tag string) (Paths, er // If a module doesn't have the OutputFilesProvider, nil is returned. func outputFilesForModuleFromProvider(ctx PathContext, module Module, tag string) (Paths, error) { var outputFiles OutputFilesInfo - fromProperty := false if mctx, isMctx := ctx.(OutputFilesProviderModuleContext); isMctx { if !mctx.EqualModules(mctx.Module(), module) { outputFiles, _ = OtherModuleProvider(mctx, module, OutputFilesProvider) } else { outputFiles = mctx.GetOutputFiles() - fromProperty = true } } else if cta, isCta := ctx.(*singletonContextAdaptor); isCta { outputFiles, _ = OtherModuleProvider(cta, module, OutputFilesProvider) @@ -2948,10 +2987,8 @@ func outputFilesForModuleFromProvider(ctx PathContext, module Module, tag string } else if taggedOutputFiles, hasTag := outputFiles.TaggedOutputFiles[tag]; hasTag { return taggedOutputFiles, nil } else { - if fromProperty { - return nil, fmt.Errorf("unsupported tag %q for module getting its own output files", tag) - } else { - return nil, fmt.Errorf("unsupported module reference tag %q", tag) + return nil, UnsupportedOutputTagError{ + tag: tag, } } } @@ -2970,8 +3007,24 @@ type OutputFilesInfo struct { var OutputFilesProvider = blueprint.NewProvider[OutputFilesInfo]() +type UnsupportedOutputTagError struct { + tag string +} + +func (u UnsupportedOutputTagError) Error() string { + return fmt.Sprintf("unsupported output tag %q", u.tag) +} + +func (u UnsupportedOutputTagError) Is(e error) bool { + _, ok := e.(UnsupportedOutputTagError) + return ok +} + +var _ error = UnsupportedOutputTagError{} + // This is used to mark the case where OutputFilesProvider is not set on some modules. var OutputFilesProviderNotSet = fmt.Errorf("No output files from provider") +var ErrUnsupportedOutputTag = UnsupportedOutputTagError{} // Modules can implement HostToolProvider and return a valid OptionalPath from HostToolPath() to // specify that they can be used as a tool by a genrule module. @@ -3037,7 +3090,7 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) { modulesInDir := make(map[string]Paths) - ctx.VisitAllModules(func(module Module) { + ctx.VisitAllModuleProxies(func(module ModuleProxy) { info := OtherModuleProviderOrDefault(ctx, module, FinalModuleBuildTargetsProvider) if info.CheckbuildTarget != nil { diff --git a/android/neverallow.go b/android/neverallow.go index 70af2acc3..14dc6d212 100644 --- a/android/neverallow.go +++ b/android/neverallow.go @@ -298,33 +298,29 @@ func createLimitDirgroupRule() []Rule { WithoutMatcher("visibility", InAllowedList([]string{"//trusty/vendor/google/aosp/scripts", "//trusty/vendor/google/proprietary/scripts"})).Because(reason), NeverAllow(). ModuleType("genrule"). - // TODO: remove the 4 below targets once new targets are submitted - Without("name", "trusty-arm64.lk.elf.gen"). - Without("name", "trusty-arm64-virt-test-debug.lk.elf.gen"). - Without("name", "trusty-x86_64.lk.elf.gen"). - Without("name", "trusty-x86_64-test.lk.elf.gen"). - // trusty vm target names moving forward - Without("name", "trusty-test_vm-arm64.elf.gen"). - Without("name", "trusty-test_vm-x86.elf.gen"). - Without("name", "trusty-security_vm-arm64.elf.gen"). - Without("name", "trusty-security_vm-x86.elf.gen"). - Without("name", "trusty-widevine_vm-arm64.elf.gen"). - Without("name", "trusty-widevine_vm-x86.elf.gen"). + // Trusty TEE target names + Without("name", "trusty_tee_package_goog"). + Without("name", "trusty_tee_package"). + // Trusty vm target names + Without("name", "trusty_test_vm_arm64.bin"). + Without("name", "trusty_test_vm_x86_64.elf"). + Without("name", "trusty_security_vm_arm64.bin"). + Without("name", "trusty_security_vm_x86_64.elf"). + Without("name", "trusty_widevine_vm_arm64.bin"). + Without("name", "trusty_widevine_vm_x86_64.elf"). WithMatcher("dir_srcs", isSetMatcherInstance).Because(reason), NeverAllow(). ModuleType("genrule"). - // TODO: remove the 4 below targets once new targets are submitted - Without("name", "trusty-arm64.lk.elf.gen"). - Without("name", "trusty-arm64-virt-test-debug.lk.elf.gen"). - Without("name", "trusty-x86_64.lk.elf.gen"). - Without("name", "trusty-x86_64-test.lk.elf.gen"). - // trusty vm target names moving forward - Without("name", "trusty-test_vm-arm64.elf.gen"). - Without("name", "trusty-test_vm-x86.elf.gen"). - Without("name", "trusty-security_vm-arm64.elf.gen"). - Without("name", "trusty-security_vm-x86.elf.gen"). - Without("name", "trusty-widevine_vm-arm64.elf.gen"). - Without("name", "trusty-widevine_vm-x86.elf.gen"). + // Trusty TEE target names + Without("name", "trusty_tee_package_goog"). + Without("name", "trusty_tee_package"). + // Trusty vm target names + Without("name", "trusty_test_vm_arm64.bin"). + Without("name", "trusty_test_vm_x86_64.elf"). + Without("name", "trusty_security_vm_arm64.bin"). + Without("name", "trusty_security_vm_x86_64.elf"). + Without("name", "trusty_widevine_vm_arm64.bin"). + Without("name", "trusty_widevine_vm_x86_64.elf"). With("keep_gendir", "true").Because(reason), } } diff --git a/android/package.go b/android/package.go index eb76751f5..42f17b1d5 100644 --- a/android/package.go +++ b/android/package.go @@ -38,6 +38,12 @@ type packageProperties struct { Default_team *string `android:"path"` } +type PackageInfo struct { + Properties packageProperties +} + +var PackageInfoProvider = blueprint.NewProvider[PackageInfo]() + type packageModule struct { ModuleBase @@ -56,7 +62,14 @@ func (p *packageModule) DepsMutator(ctx BottomUpMutatorContext) { } func (p *packageModule) GenerateBuildActions(ctx blueprint.ModuleContext) { - // Nothing to do. + ctx.SetProvider(CommonModuleInfoKey, CommonModuleInfo{ + Enabled: true, + PrimaryLicensesProperty: p.primaryLicensesProperty, + }) + + ctx.SetProvider(PackageInfoProvider, PackageInfo{ + Properties: p.properties, + }) } func (p *packageModule) qualifiedModuleId(ctx BaseModuleContext) qualifiedModuleName { diff --git a/android/path_properties.go b/android/path_properties.go index 55a4dc066..d769d58c4 100644 --- a/android/path_properties.go +++ b/android/path_properties.go @@ -54,12 +54,14 @@ func addPathDepsForProps(ctx BottomUpMutatorContext, props []interface{}) { var pathDeviceFirstPrefer32Properties []string var pathDeviceCommonProperties []string var pathCommonOsProperties []string + var pathHostCommonProperties []string for _, ps := range props { pathProperties = append(pathProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path")...) pathDeviceFirstProperties = append(pathDeviceFirstProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path_device_first")...) pathDeviceFirstPrefer32Properties = append(pathDeviceFirstPrefer32Properties, taggedPropertiesForPropertyStruct(ctx, ps, "path_device_first_prefer32")...) pathDeviceCommonProperties = append(pathDeviceCommonProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path_device_common")...) pathCommonOsProperties = append(pathCommonOsProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path_common_os")...) + pathHostCommonProperties = append(pathHostCommonProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path_host_common")...) } // Remove duplicates to avoid multiple dependencies. @@ -68,6 +70,7 @@ func addPathDepsForProps(ctx BottomUpMutatorContext, props []interface{}) { pathDeviceFirstPrefer32Properties = FirstUniqueStrings(pathDeviceFirstPrefer32Properties) pathDeviceCommonProperties = FirstUniqueStrings(pathDeviceCommonProperties) pathCommonOsProperties = FirstUniqueStrings(pathCommonOsProperties) + pathHostCommonProperties = FirstUniqueStrings(pathHostCommonProperties) // Add dependencies to anything that is a module reference. for _, s := range pathProperties { @@ -108,6 +111,12 @@ func addPathDepsForProps(ctx BottomUpMutatorContext, props []interface{}) { ctx.AddVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), sourceOrOutputDepTag(m, t), m) } } + // properties tagged "path_host_common" get the host common variant + for _, s := range pathHostCommonProperties { + if m, t := SrcIsModuleWithTag(s); m != "" { + ctx.AddVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), sourceOrOutputDepTag(m, t), m) + } + } // properties tagged "path_common_os" get the CommonOs variant for _, s := range pathCommonOsProperties { if m, t := SrcIsModuleWithTag(s); m != "" { diff --git a/android/paths.go b/android/paths.go index 1c0321c02..a944c48db 100644 --- a/android/paths.go +++ b/android/paths.go @@ -229,6 +229,8 @@ func ReportPathErrorf(ctx PathContext, format string, args ...interface{}) { } } +// TODO(b/397766191): Change the signature to take ModuleProxy +// Please only access the module's internal data through providers. func pathContextName(ctx PathContext, module blueprint.Module) string { if x, ok := ctx.(interface{ ModuleName(blueprint.Module) string }); ok { return x.ModuleName(module) diff --git a/android/phony.go b/android/phony.go index 7bdd9d31d..99ff0aaa4 100644 --- a/android/phony.go +++ b/android/phony.go @@ -55,7 +55,7 @@ var _ SingletonMakeVarsProvider = (*phonySingleton)(nil) func (p *phonySingleton) GenerateBuildActions(ctx SingletonContext) { p.phonyMap = getSingletonPhonyMap(ctx.Config()) - ctx.VisitAllModules(func(m Module) { + ctx.VisitAllModuleProxies(func(m ModuleProxy) { if info, ok := OtherModuleProvider(ctx, m, ModulePhonyProvider); ok { for k, v := range info.Phonies { p.phonyMap[k] = append(p.phonyMap[k], v...) diff --git a/android/prebuilt.go b/android/prebuilt.go index 6b076b7b4..72735991d 100644 --- a/android/prebuilt.go +++ b/android/prebuilt.go @@ -357,6 +357,17 @@ func IsModulePreferred(module Module) bool { return true } +func IsModulePreferredProxy(ctx OtherModuleProviderContext, module ModuleProxy) bool { + if OtherModuleProviderOrDefault(ctx, module, CommonModuleInfoKey).ReplacedByPrebuilt { + // A source module that has been replaced by a prebuilt counterpart. + return false + } + if p, ok := OtherModuleProvider(ctx, module, PrebuiltModuleInfoProvider); ok { + return p.UsePrebuilt + } + return true +} + // IsModulePrebuilt returns true if the module implements PrebuiltInterface and // has been initialized as a prebuilt and so returns a non-nil value from the // PrebuiltInterface.Prebuilt() method. diff --git a/android/prebuilt_build_tool.go b/android/prebuilt_build_tool.go index 17b323067..7773bf8af 100644 --- a/android/prebuilt_build_tool.go +++ b/android/prebuilt_build_tool.go @@ -84,13 +84,12 @@ func (t *prebuiltBuildTool) GenerateAndroidBuildActions(ctx ModuleContext) { t.toolPath = OptionalPathForPath(installedPath) } -func (t *prebuiltBuildTool) MakeVars(ctx MakeVarsModuleContext) { - if makeVar := String(t.properties.Export_to_make_var); makeVar != "" { - if t.Target().Os != ctx.Config().BuildOS { - return - } - ctx.StrictRaw(makeVar, t.toolPath.String()) +func (t *prebuiltBuildTool) MakeVars(ctx MakeVarsModuleContext) []ModuleMakeVarsValue { + if makeVar := String(t.properties.Export_to_make_var); makeVar != "" && + t.Target().Os == ctx.Config().BuildOS { + return []ModuleMakeVarsValue{{makeVar, t.toolPath.String()}} } + return nil } func (t *prebuiltBuildTool) HostToolPath() OptionalPath { diff --git a/android/provider.go b/android/provider.go index b48fd9148..d005daf55 100644 --- a/android/provider.go +++ b/android/provider.go @@ -16,6 +16,12 @@ var _ OtherModuleProviderContext = BottomUpMutatorContext(nil) var _ OtherModuleProviderContext = SingletonContext(nil) var _ OtherModuleProviderContext = (*TestContext)(nil) +// ConfigAndOtherModuleProviderContext is OtherModuleProviderContext + ConfigContext +type ConfigAndOtherModuleProviderContext interface { + OtherModuleProviderContext + ConfigContext +} + // OtherModuleProvider reads the provider for the given module. If the provider has been set the value is // returned and the boolean is true. If it has not been set the zero value of the provider's type is returned // and the boolean is false. The value returned may be a deep copy of the value originally passed to SetProvider. diff --git a/android/singleton.go b/android/singleton.go index df2204591..96b10223f 100644 --- a/android/singleton.go +++ b/android/singleton.go @@ -84,6 +84,9 @@ type SingletonContext interface { VisitAllModuleVariantProxies(module Module, visit func(proxy ModuleProxy)) PrimaryModule(module Module) Module + + PrimaryModuleProxy(module ModuleProxy) ModuleProxy + IsFinalModule(module Module) bool AddNinjaFileDeps(deps ...string) @@ -271,6 +274,26 @@ func predAdaptor(pred func(Module) bool) func(blueprint.Module) bool { } } +func (s *singletonContextAdaptor) ModuleName(module blueprint.Module) string { + return s.SingletonContext.ModuleName(getWrappedModule(module)) +} + +func (s *singletonContextAdaptor) ModuleDir(module blueprint.Module) string { + return s.SingletonContext.ModuleDir(getWrappedModule(module)) +} + +func (s *singletonContextAdaptor) ModuleSubDir(module blueprint.Module) string { + return s.SingletonContext.ModuleSubDir(getWrappedModule(module)) +} + +func (s *singletonContextAdaptor) ModuleType(module blueprint.Module) string { + return s.SingletonContext.ModuleType(getWrappedModule(module)) +} + +func (s *singletonContextAdaptor) BlueprintFile(module blueprint.Module) string { + return s.SingletonContext.BlueprintFile(getWrappedModule(module)) +} + func (s *singletonContextAdaptor) VisitAllModulesBlueprint(visit func(blueprint.Module)) { s.SingletonContext.VisitAllModules(visit) } @@ -315,6 +338,10 @@ func (s *singletonContextAdaptor) PrimaryModule(module Module) Module { return s.SingletonContext.PrimaryModule(module).(Module) } +func (s *singletonContextAdaptor) PrimaryModuleProxy(module ModuleProxy) ModuleProxy { + return ModuleProxy{s.SingletonContext.PrimaryModuleProxy(module.module)} +} + func (s *singletonContextAdaptor) IsFinalModule(module Module) bool { return s.SingletonContext.IsFinalModule(module) } diff --git a/android/team.go b/android/team.go index c273dc647..ad37f28c9 100644 --- a/android/team.go +++ b/android/team.go @@ -32,6 +32,12 @@ type teamProperties struct { Trendy_team_id *string `json:"trendy_team_id"` } +type TeamInfo struct { + Properties teamProperties +} + +var TeamInfoProvider = blueprint.NewProvider[TeamInfo]() + type teamModule struct { ModuleBase DefaultableModuleBase @@ -48,7 +54,11 @@ var TestOnlyProviderKey = blueprint.NewProvider[TestModuleInformation]() // Real work is done for the module that depends on us. // If needed, the team can serialize the config to json/proto file as well. -func (t *teamModule) GenerateAndroidBuildActions(ctx ModuleContext) {} +func (t *teamModule) GenerateAndroidBuildActions(ctx ModuleContext) { + SetProvider(ctx, TeamInfoProvider, TeamInfo{ + Properties: t.properties, + }) +} func (t *teamModule) TrendyTeamId(ctx ModuleContext) string { return *t.properties.Trendy_team_id diff --git a/android/test_mapping_zip.go b/android/test_mapping_zip.go new file mode 100644 index 000000000..8dc70d7fe --- /dev/null +++ b/android/test_mapping_zip.go @@ -0,0 +1,49 @@ +// Copyright 2025 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package android + +func init() { + InitRegistrationContext.RegisterSingletonType("test_mapping_zip_singleton", testMappingZipSingletonFactory) +} + +func testMappingZipSingletonFactory() Singleton { + return &testMappingZipSingleton{} +} + +type testMappingZipSingleton struct{} + +func (s *testMappingZipSingleton) GenerateBuildActions(ctx SingletonContext) { + fileListFile := PathForArbitraryOutput(ctx, ".module_paths", "TEST_MAPPING.list") + out := PathForOutput(ctx, "test_mappings.zip") + dep := PathForOutput(ctx, "test_mappings.zip.d") + + // disabled-presubmit-tests used to be filled out based on modules that set + // LOCAL_PRESUBMIT_DISABLED. But that's no longer used and there was never a soong equivalent + // anyways, so just always create an empty file. + disabledPresubmitTestsFile := PathForOutput(ctx, "disabled-presubmit-tests") + WriteFileRule(ctx, disabledPresubmitTestsFile, "") + + builder := NewRuleBuilder(pctx, ctx) + builder.Command().BuiltTool("soong_zip"). + FlagWithOutput("-o ", out). + FlagWithInput("-l ", fileListFile). + FlagWithArg("-e ", "disabled-presubmit-tests"). + FlagWithInput("-f ", disabledPresubmitTestsFile) + builder.Command().Textf("echo '%s : ' $(cat %s) > ", out, fileListFile).DepFile(dep) + builder.Build("test_mappings_zip", "build TEST_MAPPING zip") + + ctx.Phony("test_mapping", out) + ctx.DistForGoals([]string{"dist_files", "test_mapping"}, out) +} diff --git a/android/test_suites.go b/android/test_suites.go index 18744f1da..39317ec62 100644 --- a/android/test_suites.go +++ b/android/test_suites.go @@ -17,6 +17,8 @@ package android import ( "path/filepath" "strings" + + "github.com/google/blueprint" ) func init() { @@ -37,18 +39,24 @@ type TestSuiteModule interface { TestSuites() []string } +type TestSuiteInfo struct { + TestSuites []string +} + +var TestSuiteInfoProvider = blueprint.NewProvider[TestSuiteInfo]() + func (t *testSuiteFiles) GenerateBuildActions(ctx SingletonContext) { files := make(map[string]map[string]InstallPaths) - ctx.VisitAllModules(func(m Module) { - if tsm, ok := m.(TestSuiteModule); ok { - for _, testSuite := range tsm.TestSuites() { + ctx.VisitAllModuleProxies(func(m ModuleProxy) { + if tsm, ok := OtherModuleProvider(ctx, m, TestSuiteInfoProvider); ok { + for _, testSuite := range tsm.TestSuites { if files[testSuite] == nil { files[testSuite] = make(map[string]InstallPaths) } name := ctx.ModuleName(m) files[testSuite][name] = append(files[testSuite][name], - OtherModuleProviderOrDefault(ctx, tsm, InstallFilesProvider).InstallFiles...) + OtherModuleProviderOrDefault(ctx, m, InstallFilesProvider).InstallFiles...) } } }) diff --git a/android/test_suites_test.go b/android/test_suites_test.go index bf4de197e..dda93297a 100644 --- a/android/test_suites_test.go +++ b/android/test_suites_test.go @@ -110,6 +110,10 @@ func (f *fake_module) GenerateAndroidBuildActions(ctx ModuleContext) { for _, output := range f.props.Outputs { ctx.InstallFile(pathForTestCases(ctx), output, nil) } + + SetProvider(ctx, TestSuiteInfoProvider, TestSuiteInfo{ + TestSuites: f.TestSuites(), + }) } func (f *fake_module) TestSuites() []string { diff --git a/android/testing.go b/android/testing.go index fe9bcec26..1962fdea5 100644 --- a/android/testing.go +++ b/android/testing.go @@ -931,6 +931,7 @@ func (b baseTestingComponent) maybeBuildParamsFromRule(rule string) (TestingBuil } func (b baseTestingComponent) buildParamsFromRule(rule string) TestingBuildParams { + b.t.Helper() p, searchRules := b.maybeBuildParamsFromRule(rule) if p.Rule == nil { b.t.Fatalf("couldn't find rule %q.\nall rules:\n%s", rule, strings.Join(searchRules, "\n")) @@ -950,6 +951,7 @@ func (b baseTestingComponent) maybeBuildParamsFromDescription(desc string) (Test } func (b baseTestingComponent) buildParamsFromDescription(desc string) TestingBuildParams { + b.t.Helper() p, searchedDescriptions := b.maybeBuildParamsFromDescription(desc) if p.Rule == nil { b.t.Fatalf("couldn't find description %q\nall descriptions:\n%s", desc, strings.Join(searchedDescriptions, "\n")) @@ -983,6 +985,7 @@ func (b baseTestingComponent) maybeBuildParamsFromOutput(file string) (TestingBu } func (b baseTestingComponent) buildParamsFromOutput(file string) TestingBuildParams { + b.t.Helper() p, searchedOutputs := b.maybeBuildParamsFromOutput(file) if p.Rule == nil { b.t.Fatalf("couldn't find output %q.\nall outputs:\n %s\n", @@ -1008,6 +1011,7 @@ func (b baseTestingComponent) MaybeRule(rule string) TestingBuildParams { // Rule finds a call to ctx.Build with BuildParams.Rule set to a rule with the given name. Panics if no rule is found. func (b baseTestingComponent) Rule(rule string) TestingBuildParams { + b.t.Helper() return b.buildParamsFromRule(rule) } @@ -1021,6 +1025,7 @@ func (b baseTestingComponent) MaybeDescription(desc string) TestingBuildParams { // Description finds a call to ctx.Build with BuildParams.Description set to a the given string. Panics if no rule is // found. func (b baseTestingComponent) Description(desc string) TestingBuildParams { + b.t.Helper() return b.buildParamsFromDescription(desc) } @@ -1034,6 +1039,7 @@ func (b baseTestingComponent) MaybeOutput(file string) TestingBuildParams { // Output finds a call to ctx.Build with a BuildParams.Output or BuildParams.Outputs whose String() or Rel() // value matches the provided string. Panics if no rule is found. func (b baseTestingComponent) Output(file string) TestingBuildParams { + b.t.Helper() return b.buildParamsFromOutput(file) } @@ -1191,10 +1197,11 @@ func AndroidMkInfoForTest(t *testing.T, ctx *TestContext, mod Module) *AndroidMk info := OtherModuleProviderOrDefault(ctx, mod, AndroidMkInfoProvider) aconfigUpdateAndroidMkInfos(ctx, mod, info) - info.PrimaryInfo.fillInEntries(ctx, mod) + commonInfo, _ := OtherModuleProvider(ctx, mod, CommonModuleInfoKey) + info.PrimaryInfo.fillInEntries(ctx, mod, &commonInfo) if len(info.ExtraInfo) > 0 { for _, ei := range info.ExtraInfo { - ei.fillInEntries(ctx, mod) + ei.fillInEntries(ctx, mod, &commonInfo) } } diff --git a/apex/apex.go b/apex/apex.go index 4b510f8f1..4dd3d4cc0 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -82,10 +82,6 @@ type apexBundleProperties struct { // /system/sepolicy/apex/<module_name>_file_contexts. File_contexts *string `android:"path"` - // By default, file_contexts is amended by force-labelling / and /apex_manifest.pb as system_file - // to avoid mistakes. When set as true, no force-labelling. - Use_file_contexts_as_is *bool - // Path to the canned fs config file for customizing file's // uid/gid/mod/capabilities. The content of this file is appended to the // default config, so that the custom entries are preferred. The format is @@ -2262,6 +2258,11 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.enforcePartitionTagOnApexSystemServerJar(ctx) a.verifyNativeImplementationLibs(ctx) + + android.SetProvider(ctx, android.ApexBundleDepsDataProvider, android.ApexBundleDepsData{ + FlatListPath: a.FlatListPath(), + Updatable: a.Updatable(), + }) } // Set prebuiltInfoProvider. This will be used by `apex_prebuiltinfo_singleton` to print out a metadata file diff --git a/apex/apex_singleton.go b/apex/apex_singleton.go index a8bd984b2..dabec4930 100644 --- a/apex/apex_singleton.go +++ b/apex/apex_singleton.go @@ -90,11 +90,11 @@ var ( func (s *apexDepsInfoSingleton) GenerateBuildActions(ctx android.SingletonContext) { updatableFlatLists := android.Paths{} - ctx.VisitAllModules(func(module android.Module) { - if binaryInfo, ok := module.(android.ApexBundleDepsInfoIntf); ok { + ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { + if binaryInfo, ok := android.OtherModuleProvider(ctx, module, android.ApexBundleDepsDataProvider); ok { apexInfo, _ := android.OtherModuleProvider(ctx, module, android.ApexInfoProvider) - if path := binaryInfo.FlatListPath(); path != nil { - if binaryInfo.Updatable() || apexInfo.Updatable { + if path := binaryInfo.FlatListPath; path != nil { + if binaryInfo.Updatable || apexInfo.Updatable { if strings.HasPrefix(module.String(), "com.android.") { updatableFlatLists = append(updatableFlatLists, path) } @@ -160,11 +160,11 @@ type apexPrebuiltInfo struct { func (a *apexPrebuiltInfo) GenerateBuildActions(ctx android.SingletonContext) { prebuiltInfos := []android.PrebuiltInfo{} - ctx.VisitAllModules(func(m android.Module) { + ctx.VisitAllModuleProxies(func(m android.ModuleProxy) { prebuiltInfo, exists := android.OtherModuleProvider(ctx, m, android.PrebuiltInfoProvider) // Use prebuiltInfoProvider to filter out non apex soong modules. // Use HideFromMake to filter out the unselected variants of a specific apex. - if exists && !m.IsHideFromMake() { + if exists && !android.OtherModuleProviderOrDefault(ctx, m, android.CommonModuleInfoKey).HideFromMake { prebuiltInfos = append(prebuiltInfos, prebuiltInfo) } }) diff --git a/apex/apex_test.go b/apex/apex_test.go index 5519bd2fd..9eaf814d0 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -7874,7 +7874,7 @@ func TestJavaSDKLibrary_WithinApex(t *testing.T) { // The bar library should depend on the implementation jar. barLibrary := ctx.ModuleForTests(t, "bar", "android_common_apex10000").Rule("javac") - if expected, actual := `^-classpath [^:]*/turbine-combined/foo\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { + if expected, actual := `^-classpath [^:]*/turbine/foo\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { t.Errorf("expected %q, found %#q", expected, actual) } } @@ -7926,7 +7926,7 @@ func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { // The bar library should depend on the stubs jar. barLibrary := ctx.ModuleForTests(t, "bar", "android_common").Rule("javac") - if expected, actual := `^-classpath [^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { + if expected, actual := `^-classpath [^:]*/foo\.stubs\.from-text/foo\.stubs\.from-text\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { t.Errorf("expected %q, found %#q", expected, actual) } } @@ -8020,7 +8020,7 @@ func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { // The bar library should depend on the implementation jar. barLibrary := ctx.ModuleForTests(t, "bar", "android_common_apex10000").Rule("javac") - if expected, actual := `^-classpath [^:]*/turbine-combined/foo\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { + if expected, actual := `^-classpath [^:]*/turbine/foo\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { t.Errorf("expected %q, found %#q", expected, actual) } } diff --git a/apex/builder.go b/apex/builder.go index 842771920..2fc4902fb 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -428,8 +428,6 @@ func (a *apexBundle) buildFileContexts(ctx android.ModuleContext) android.Path { ctx.PropertyErrorf("file_contexts", "cannot find file_contexts file: %q", fileContexts.String()) } - useFileContextsAsIs := proptools.Bool(a.properties.Use_file_contexts_as_is) - output := android.PathForModuleOut(ctx, "file_contexts") rule := android.NewRuleBuilder(pctx, ctx) @@ -446,11 +444,9 @@ func (a *apexBundle) buildFileContexts(ctx android.ModuleContext) android.Path { rule.Command().Text("cat").Input(fileContexts).Text(">>").Output(output) // new line rule.Command().Text("echo").Text(">>").Output(output) - if !useFileContextsAsIs { - // force-label /apex_manifest.pb and / - rule.Command().Text("echo").Text("/apex_manifest\\\\.pb").Text(labelForManifest).Text(">>").Output(output) - rule.Command().Text("echo").Text("/").Text(labelForRoot).Text(">>").Output(output) - } + // force-label /apex_manifest.pb and / + rule.Command().Text("echo").Text("/apex_manifest\\\\.pb").Text(labelForManifest).Text(">>").Output(output) + rule.Command().Text("echo").Text("/").Text(labelForRoot).Text(">>").Output(output) rule.Build("file_contexts."+a.Name(), "Generate file_contexts") return output @@ -592,6 +588,7 @@ func (a *apexBundle) installApexSystemServerFiles(ctx android.ModuleContext) { } a.extraInstalledFiles = append(a.extraInstalledFiles, installedFile) a.extraInstalledPairs = append(a.extraInstalledPairs, installPair{install.OutputPathOnHost, installedFile}) + ctx.PackageFile(install.InstallDirOnDevice, install.InstallFileOnDevice, install.OutputPathOnHost) } if performInstalls { for _, dexJar := range fi.systemServerDexJars { diff --git a/apex/prebuilt.go b/apex/prebuilt.go index 3daa4f81a..0a970276a 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -245,6 +245,7 @@ func (p *prebuiltCommon) installApexSystemServerFiles(ctx android.ModuleContext) } p.extraInstalledFiles = append(p.extraInstalledFiles, installedFile) p.extraInstalledPairs = append(p.extraInstalledPairs, installPair{install.OutputPathOnHost, installedFile}) + ctx.PackageFile(install.InstallDirOnDevice, install.InstallFileOnDevice, install.OutputPathOnHost) } for _, dexJar := range p.systemServerDexJars { diff --git a/apex/systemserver_classpath_fragment_test.go b/apex/systemserver_classpath_fragment_test.go index cf7ea8af9..61f79d695 100644 --- a/apex/systemserver_classpath_fragment_test.go +++ b/apex/systemserver_classpath_fragment_test.go @@ -471,3 +471,120 @@ func assertProfileGuidedPrebuilt(t *testing.T, ctx *android.TestContext, apexNam t.Fatalf("Expected profile-guided to be %v, got %v", expected, actual) } } + +func TestCheckSystemServerOrderWithArtApex(t *testing.T) { + preparers := android.GroupFixturePreparers( + java.PrepareForTestWithDexpreopt, + java.PrepareForTestWithJavaSdkLibraryFiles, + PrepareForTestWithApexBuildComponents, + prepareForTestWithArtApex, + java.FixtureConfigureBootJars("com.android.art:framework-art"), + dexpreopt.FixtureSetApexSystemServerJars("com.android.apex1:service-apex1", "com.android.art:service-art"), + java.FixtureWithLastReleaseApis("baz"), + ) + + // Creates a com.android.art apex with a bootclasspath fragment and a systemserverclasspath fragment, and a + // com.android.apex1 prebuilt whose bootclasspath fragment depends on the com.android.art bootclasspath fragment. + // Verifies that the checkSystemServerOrder doesn't get confused by the bootclasspath dependencies and report + // that service-apex1 depends on service-art. + result := preparers.RunTestWithBp(t, ` + apex { + name: "com.android.art", + key: "com.android.art.key", + bootclasspath_fragments: ["art-bootclasspath-fragment"], + systemserverclasspath_fragments: ["art-systemserverclasspath-fragment"], + updatable: false, + } + + apex_key { + name: "com.android.art.key", + public_key: "com.android.art.avbpubkey", + private_key: "com.android.art.pem", + } + + bootclasspath_fragment { + name: "art-bootclasspath-fragment", + image_name: "art", + contents: ["framework-art"], + apex_available: [ + "com.android.art", + ], + hidden_api: { + split_packages: ["*"], + }, + } + + java_library { + name: "framework-art", + apex_available: ["com.android.art"], + srcs: ["a.java"], + compile_dex: true, + } + + systemserverclasspath_fragment { + name: "art-systemserverclasspath-fragment", + apex_available: ["com.android.art"], + contents: ["service-art"], + } + + java_library { + name: "service-art", + srcs: ["a.java"], + apex_available: ["com.android.art"], + compile_dex: true, + } + + prebuilt_apex { + name: "com.android.apex1", + arch: { + arm64: { + src: "myapex-arm64.apex", + }, + arm: { + src: "myapex-arm.apex", + }, + }, + exported_bootclasspath_fragments: ["com.android.apex1-bootclasspath-fragment"], + exported_systemserverclasspath_fragments: ["com.android.apex1-systemserverclasspath-fragment"], + } + + prebuilt_bootclasspath_fragment { + name: "com.android.apex1-bootclasspath-fragment", + visibility: ["//visibility:public"], + apex_available: ["com.android.apex1"], + contents: ["framework-apex1"], + fragments: [ + { + apex: "com.android.art", + module: "art-bootclasspath-fragment", + }, + ], + hidden_api: { + annotation_flags: "hiddenapi/annotation-flags.csv", + metadata: "hiddenapi/metadata.csv", + index: "hiddenapi/index.csv", + stub_flags: "hiddenapi/stub-flags.csv", + all_flags: "hiddenapi/all-flags.csv", + }, + } + + java_import { + name: "framework-apex1", + apex_available: ["com.android.apex1"], + } + + prebuilt_systemserverclasspath_fragment { + name: "com.android.apex1-systemserverclasspath-fragment", + apex_available: ["com.android.apex1"], + contents: ["service-apex1"], + } + + java_import { + name: "service-apex1", + installable: true, + apex_available: ["com.android.apex1"], + sdk_version: "current", + }`) + + _ = result +} diff --git a/cc/Android.bp b/cc/Android.bp index 3b29ae8cf..1ac5a4a8f 100644 --- a/cc/Android.bp +++ b/cc/Android.bp @@ -36,6 +36,7 @@ bootstrap_go_package { "linkable.go", "lto.go", "makevars.go", + "misc_disted_files.go", "orderfile.go", "prebuilt.go", "proto.go", diff --git a/cc/androidmk.go b/cc/androidmk.go index 03f229ef4..b016788ee 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -244,10 +244,6 @@ func (library *libraryDecorator) prepareAndroidMKProviderInfo(config android.Con entries.Class = "HEADER_LIBRARIES" } - if library.distFile != nil { - entries.DistFiles = android.MakeDefaultDistFiles(library.distFile) - } - library.androidMkWriteExportedFlags(entries) library.androidMkEntriesWriteAdditionalDependenciesForSourceAbiDiff(entries) @@ -336,7 +332,6 @@ func (binary *binaryDecorator) prepareAndroidMKProviderInfo(config android.Confi ctx.subAndroidMk(config, entries, binary.baseInstaller) entries.Class = "EXECUTABLES" - entries.DistFiles = binary.distFiles entries.SetString("LOCAL_SOONG_UNSTRIPPED_BINARY", binary.unstrippedOutputFile.String()) if len(binary.symlinks) > 0 { entries.AddStrings("LOCAL_MODULE_SYMLINKS", binary.symlinks...) diff --git a/cc/binary.go b/cc/binary.go index c4791c519..627d5e560 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -104,8 +104,8 @@ type binaryDecorator struct { // Output archive of gcno coverage information coverageOutputFile android.OptionalPath - // Location of the files that should be copied to dist dir when requested - distFiles android.TaggedDistFiles + // Location of the file that should be copied to dist dir when no explicit tag is requested + defaultDistFile android.Path // Action command lines to run directly after the binary is installed. For example, // may be used to symlink runtime dependencies (such as bionic) alongside installation. @@ -385,11 +385,11 @@ func (binary *binaryDecorator) link(ctx ModuleContext, // When dist'ing a library or binary that has use_version_lib set, always // distribute the stamped version, even for the device. versionedOutputFile := android.PathForModuleOut(ctx, "versioned", fileName) - binary.distFiles = android.MakeDefaultDistFiles(versionedOutputFile) + binary.defaultDistFile = versionedOutputFile if binary.stripper.NeedsStrip(ctx) { out := android.PathForModuleOut(ctx, "versioned-stripped", fileName) - binary.distFiles = android.MakeDefaultDistFiles(out) + binary.defaultDistFile = out binary.stripper.StripExecutableOrSharedLib(ctx, versionedOutputFile, out, stripFlags) } @@ -575,3 +575,10 @@ func (binary *binaryDecorator) verifyHostBionicLinker(ctx ModuleContext, in, lin }, }) } + +func (binary *binaryDecorator) defaultDistFiles() []android.Path { + if binary.defaultDistFile == nil { + return nil + } + return []android.Path{binary.defaultDistFile} +} @@ -93,6 +93,9 @@ type BinaryDecoratorInfo struct{} type LibraryDecoratorInfo struct { ExportIncludeDirs []string InjectBsslHash bool + // Location of the static library in the sysroot. Empty if the library is + // not included in the NDK. + NdkSysrootPath android.Path } type SnapshotInfo struct { @@ -104,14 +107,27 @@ type TestBinaryInfo struct { } type BenchmarkDecoratorInfo struct{} -type StubDecoratorInfo struct{} +type StubDecoratorInfo struct { + AbiDumpPath android.OutputPath + HasAbiDump bool + AbiDiffPaths android.Paths + InstallPath android.Path +} -type ObjectLinkerInfo struct{} +type ObjectLinkerInfo struct { + // Location of the object in the sysroot. Empty if the object is not + // included in the NDK. + NdkSysrootPath android.Path +} type LibraryInfo struct { BuildStubs bool } +type InstallerInfo struct { + StubDecoratorInfo *StubDecoratorInfo +} + // Common info about the cc module. type CcInfo struct { IsPrebuilt bool @@ -122,6 +138,7 @@ type CcInfo struct { LinkerInfo *LinkerInfo SnapshotInfo *SnapshotInfo LibraryInfo *LibraryInfo + InstallerInfo *InstallerInfo } var CcInfoProvider = blueprint.NewProvider[*CcInfo]() @@ -162,6 +179,7 @@ type LinkableInfo struct { OnlyInVendorRamdisk bool InRecovery bool OnlyInRecovery bool + InVendor bool Installable *bool // RelativeInstallPath returns the relative install path for this module. RelativeInstallPath string @@ -173,7 +191,8 @@ type LinkableInfo struct { ImplementationModuleNameForMake string IsStubsImplementationRequired bool // Symlinks returns a list of symlinks that should be created for this module. - Symlinks []string + Symlinks []string + APIListCoverageXMLPath android.ModuleOutPath } var LinkableInfoProvider = blueprint.NewProvider[*LinkableInfo]() @@ -752,6 +771,10 @@ type linker interface { // Get the deps that have been explicitly specified in the properties. linkerSpecifiedDeps(ctx android.ConfigurableEvaluatorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps + // Gets a list of files that will be disted when using the dist property without specifying + // an output file tag. + defaultDistFiles() []android.Path + moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) } @@ -2332,6 +2355,7 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { case *libraryDecorator: ccInfo.LinkerInfo.LibraryDecoratorInfo = &LibraryDecoratorInfo{ InjectBsslHash: Bool(c.linker.(*libraryDecorator).Properties.Inject_bssl_hash), + NdkSysrootPath: c.linker.(*libraryDecorator).ndkSysrootPath, } case *testBinary: ccInfo.LinkerInfo.TestBinaryInfo = &TestBinaryInfo{ @@ -2340,7 +2364,9 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { case *benchmarkDecorator: ccInfo.LinkerInfo.BenchmarkDecoratorInfo = &BenchmarkDecoratorInfo{} case *objectLinker: - ccInfo.LinkerInfo.ObjectLinkerInfo = &ObjectLinkerInfo{} + ccInfo.LinkerInfo.ObjectLinkerInfo = &ObjectLinkerInfo{ + NdkSysrootPath: c.linker.(*objectLinker).ndkSysrootPath, + } case *stubDecorator: ccInfo.LinkerInfo.StubDecoratorInfo = &StubDecoratorInfo{} } @@ -2360,6 +2386,17 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { BuildStubs: c.library.BuildStubs(), } } + if c.installer != nil { + ccInfo.InstallerInfo = &InstallerInfo{} + if installer, ok := c.installer.(*stubDecorator); ok { + ccInfo.InstallerInfo.StubDecoratorInfo = &StubDecoratorInfo{ + HasAbiDump: installer.hasAbiDump, + AbiDumpPath: installer.abiDumpPath, + AbiDiffPaths: installer.abiDiffPaths, + InstallPath: installer.installPath, + } + } + } android.SetProvider(ctx, CcInfoProvider, &ccInfo) c.setOutputFiles(ctx) @@ -2392,6 +2429,7 @@ func CreateCommonLinkableInfo(ctx android.ModuleContext, mod VersionedLinkableIn OnlyInVendorRamdisk: mod.OnlyInVendorRamdisk(), InRecovery: mod.InRecovery(), OnlyInRecovery: mod.OnlyInRecovery(), + InVendor: mod.InVendor(), Installable: mod.Installable(), RelativeInstallPath: mod.RelativeInstallPath(), // TODO(b/362509506): remove this once all apex_exclude uses are switched to stubs. @@ -2401,16 +2439,14 @@ func CreateCommonLinkableInfo(ctx android.ModuleContext, mod VersionedLinkableIn ImplementationModuleNameForMake: mod.ImplementationModuleNameForMake(), Symlinks: mod.Symlinks(), } - if mod.VersionedInterface() != nil { - info.IsStubsImplementationRequired = mod.VersionedInterface().IsStubsImplementationRequired() - } - return info -} -func setOutputFilesIfNotEmpty(ctx ModuleContext, files android.Paths, tag string) { - if len(files) > 0 { - ctx.SetOutputFiles(files, tag) + vi := mod.VersionedInterface() + if vi != nil { + info.IsStubsImplementationRequired = vi.IsStubsImplementationRequired() + info.APIListCoverageXMLPath = vi.GetAPIListCoverageXMLPath() } + + return info } func (c *Module) setOutputFiles(ctx ModuleContext) { @@ -2422,6 +2458,10 @@ func (c *Module) setOutputFiles(ctx ModuleContext) { if c.linker != nil { ctx.SetOutputFiles(android.PathsIfNonNil(c.linker.unstrippedOutputFilePath()), "unstripped") ctx.SetOutputFiles(android.PathsIfNonNil(c.linker.strippedAllOutputFilePath()), "stripped_all") + defaultDistFiles := c.linker.defaultDistFiles() + if len(defaultDistFiles) > 0 { + ctx.SetOutputFiles(defaultDistFiles, android.DefaultDistTag) + } } } @@ -4045,15 +4085,6 @@ func installable(c LinkableInterface, apexInfo android.ApexInfo) bool { return ret } - // Special case for modules that are configured to be installed to /data, which includes - // test modules. For these modules, both APEX and non-APEX variants are considered as - // installable. This is because even the APEX variants won't be included in the APEX, but - // will anyway be installed to /data/*. - // See b/146995717 - if c.InstallInData() { - return ret - } - return false } diff --git a/cc/fuzz.go b/cc/fuzz.go index a8e4cb70a..bd3d8e431 100644 --- a/cc/fuzz.go +++ b/cc/fuzz.go @@ -353,6 +353,7 @@ func PackageFuzzModule(ctx android.ModuleContext, fuzzPackagedModule fuzz.FuzzPa fuzzPackagedModule.Data = android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Data) fuzzPackagedModule.Data = append(fuzzPackagedModule.Data, android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Device_common_data)...) fuzzPackagedModule.Data = append(fuzzPackagedModule.Data, android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Device_first_data)...) + fuzzPackagedModule.Data = append(fuzzPackagedModule.Data, android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Host_common_data)...) if fuzzPackagedModule.FuzzProperties.Dictionary != nil { fuzzPackagedModule.Dictionary = android.PathForModuleSrc(ctx, *fuzzPackagedModule.FuzzProperties.Dictionary) diff --git a/cc/library.go b/cc/library.go index 532b7e9aa..ee7610d08 100644 --- a/cc/library.go +++ b/cc/library.go @@ -419,8 +419,8 @@ type libraryDecorator struct { // Location of the linked, stripped library for shared libraries, strip: "all" strippedAllOutputFile android.Path - // Location of the file that should be copied to dist dir when requested - distFile android.Path + // Location of the file that should be copied to dist dir when no explicit tag is requested + defaultDistFile android.Path versionScriptPath android.OptionalPath @@ -1066,7 +1066,7 @@ func (library *libraryDecorator) linkStatic(ctx ModuleContext, library.injectVersionSymbol(ctx, outputFile, versionedOutputFile) } else { versionedOutputFile := android.PathForModuleOut(ctx, "versioned", fileName) - library.distFile = versionedOutputFile + library.defaultDistFile = versionedOutputFile library.injectVersionSymbol(ctx, outputFile, versionedOutputFile) } } @@ -1206,11 +1206,11 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, library.injectVersionSymbol(ctx, outputFile, versionedOutputFile) } else { versionedOutputFile := android.PathForModuleOut(ctx, "versioned", fileName) - library.distFile = versionedOutputFile + library.defaultDistFile = versionedOutputFile if library.stripper.NeedsStrip(ctx) { out := android.PathForModuleOut(ctx, "versioned-stripped", fileName) - library.distFile = out + library.defaultDistFile = out library.stripper.StripExecutableOrSharedLib(ctx, versionedOutputFile, out, stripFlags) } @@ -2090,6 +2090,13 @@ func (library *libraryDecorator) overriddenModules() []string { return library.Properties.Overrides } +func (library *libraryDecorator) defaultDistFiles() []android.Path { + if library.defaultDistFile == nil { + return nil + } + return []android.Path{library.defaultDistFile} +} + var _ overridable = (*libraryDecorator)(nil) var versioningMacroNamesListKey = android.NewOnceKey("versioningMacroNamesList") diff --git a/cc/makevars.go b/cc/makevars.go index c94510280..9358755cc 100644 --- a/cc/makevars.go +++ b/cc/makevars.go @@ -100,15 +100,7 @@ func makeVarsProvider(ctx android.MakeVarsContext) { // Filter vendor_public_library that are exported to make var exportedVendorPublicLibraries []string - var warningsAllowed []string - var usingWnoErrors []string - var missingProfiles []string ctx.VisitAllModules(func(module android.Module) { - if v, ok := android.OtherModuleProvider(ctx, module, CcMakeVarsInfoProvider); ok { - warningsAllowed = android.AppendIfNotZero(warningsAllowed, v.WarningsAllowed) - usingWnoErrors = android.AppendIfNotZero(usingWnoErrors, v.UsingWnoError) - missingProfiles = android.AppendIfNotZero(missingProfiles, v.MissingProfile) - } if ccModule, ok := module.(*Module); ok { baseName := ccModule.BaseModuleName() if ccModule.IsVendorPublicLibrary() && module.ExportedToMake() { @@ -123,9 +115,6 @@ func makeVarsProvider(ctx android.MakeVarsContext) { ctx.Strict("LSDUMP_PATHS", strings.Join(lsdumpPaths, " ")) ctx.Strict("ANDROID_WARNING_ALLOWED_PROJECTS", makeStringOfWarningAllowedProjects()) - ctx.Strict("SOONG_MODULES_WARNINGS_ALLOWED", makeVarsString(warningsAllowed)) - ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeVarsString(usingWnoErrors)) - ctx.Strict("SOONG_MODULES_MISSING_PGO_PROFILE_FILE", makeVarsString(missingProfiles)) ctx.Strict("CLANG_COVERAGE_CONFIG_CFLAGS", strings.Join(clangCoverageCFlags, " ")) ctx.Strict("CLANG_COVERAGE_CONFIG_COMMFLAGS", strings.Join(clangCoverageCommonFlags, " ")) diff --git a/cc/misc_disted_files.go b/cc/misc_disted_files.go new file mode 100644 index 000000000..4bdffaa03 --- /dev/null +++ b/cc/misc_disted_files.go @@ -0,0 +1,89 @@ +// Copyright 2025 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cc + +import ( + "android/soong/android" + "strings" +) + +func init() { + android.InitRegistrationContext.RegisterSingletonType("cc_misc_disted_files", ccMiscDistedFilesSingletonFactory) +} + +func ccMiscDistedFilesSingletonFactory() android.Singleton { + return &ccMiscDistedFilesSingleton{} +} + +type ccMiscDistedFilesSingleton struct { + warningsAllowed []string + usingWnoErrors []string +} + +func (s *ccMiscDistedFilesSingleton) GenerateBuildActions(ctx android.SingletonContext) { + var warningsAllowed []string + var usingWnoErrors []string + var missingProfiles []string + ctx.VisitAllModules(func(module android.Module) { + if v, ok := android.OtherModuleProvider(ctx, module, CcMakeVarsInfoProvider); ok { + warningsAllowed = android.AppendIfNotZero(warningsAllowed, v.WarningsAllowed) + usingWnoErrors = android.AppendIfNotZero(usingWnoErrors, v.UsingWnoError) + missingProfiles = android.AppendIfNotZero(missingProfiles, v.MissingProfile) + } + }) + + warningsAllowed = android.SortedUniqueStrings(warningsAllowed) + usingWnoErrors = android.SortedUniqueStrings(usingWnoErrors) + missingProfiles = android.SortedUniqueStrings(missingProfiles) + + s.warningsAllowed = warningsAllowed + s.usingWnoErrors = usingWnoErrors + + var sb strings.Builder + sb.WriteString("# Modules using -Wno-error\n") + for _, nwe := range usingWnoErrors { + sb.WriteString(nwe) + sb.WriteString("\n") + } + sb.WriteString("# Modules that allow warnings\n") + for _, wa := range warningsAllowed { + sb.WriteString(wa) + sb.WriteString("\n") + } + wallWerrFile := android.PathForOutput(ctx, "wall_werror.txt") + android.WriteFileRuleVerbatim(ctx, wallWerrFile, sb.String()) + + // Only dist this file in soong-only builds. In soong+make builds, it contains information + // from make modules, so we'll still rely on make to build and dist it. + if !ctx.Config().KatiEnabled() { + ctx.DistForGoal("droidcore-unbundled", wallWerrFile) + } + + var sb2 strings.Builder + sb2.WriteString("# Modules missing PGO profile files\n") + for _, mp := range missingProfiles { + sb2.WriteString(mp) + sb2.WriteString("\n") + } + profileMissingFile := android.PathForOutput(ctx, "pgo_profile_file_missing.txt") + android.WriteFileRuleVerbatim(ctx, profileMissingFile, sb2.String()) + + ctx.DistForGoal("droidcore-unbundled", profileMissingFile) +} + +func (s *ccMiscDistedFilesSingleton) MakeVars(ctx android.MakeVarsContext) { + ctx.Strict("SOONG_MODULES_WARNINGS_ALLOWED", strings.Join(s.warningsAllowed, " ")) + ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", strings.Join(s.usingWnoErrors, " ")) +} diff --git a/cc/ndk_abi.go b/cc/ndk_abi.go index 2706261a8..a9f26a40e 100644 --- a/cc/ndk_abi.go +++ b/cc/ndk_abi.go @@ -39,15 +39,15 @@ type ndkAbiDumpSingleton struct{} func (n *ndkAbiDumpSingleton) GenerateBuildActions(ctx android.SingletonContext) { var depPaths android.Paths - ctx.VisitAllModules(func(module android.Module) { - if !module.Enabled(ctx) { + ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { + if !android.OtherModuleProviderOrDefault(ctx, module, android.CommonModuleInfoKey).Enabled { return } - if m, ok := module.(*Module); ok { - if installer, ok := m.installer.(*stubDecorator); ok { - if installer.hasAbiDump { - depPaths = append(depPaths, installer.abiDumpPath) + if ccInfo, ok := android.OtherModuleProvider(ctx, module, CcInfoProvider); ok { + if ccInfo.InstallerInfo != nil && ccInfo.InstallerInfo.StubDecoratorInfo != nil { + if ccInfo.InstallerInfo.StubDecoratorInfo.HasAbiDump { + depPaths = append(depPaths, ccInfo.InstallerInfo.StubDecoratorInfo.AbiDumpPath) } } } @@ -77,14 +77,14 @@ type ndkAbiDiffSingleton struct{} func (n *ndkAbiDiffSingleton) GenerateBuildActions(ctx android.SingletonContext) { var depPaths android.Paths - ctx.VisitAllModules(func(module android.Module) { - if m, ok := module.(android.Module); ok && !m.Enabled(ctx) { + ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { + if !android.OtherModuleProviderOrDefault(ctx, module, android.CommonModuleInfoKey).Enabled { return } - if m, ok := module.(*Module); ok { - if installer, ok := m.installer.(*stubDecorator); ok { - depPaths = append(depPaths, installer.abiDiffPaths...) + if ccInfo, ok := android.OtherModuleProvider(ctx, module, CcInfoProvider); ok { + if ccInfo.InstallerInfo != nil && ccInfo.InstallerInfo.StubDecoratorInfo != nil { + depPaths = append(depPaths, ccInfo.InstallerInfo.StubDecoratorInfo.AbiDiffPaths...) } } }) diff --git a/cc/ndk_headers.go b/cc/ndk_headers.go index 74819540b..6e26d4c87 100644 --- a/cc/ndk_headers.go +++ b/cc/ndk_headers.go @@ -80,6 +80,20 @@ type headerModule struct { licensePath android.Path } +type NdkHeaderInfo struct { + SrcPaths android.Paths + InstallPaths android.Paths + LicensePath android.Path + // Set to true if the headers installed by this module should skip + // verification. This step ensures that each header is self-contained (can + // be #included alone) and is valid C. This should not be disabled except in + // rare cases. Outside bionic and external, if you're using this option + // you've probably made a mistake. + SkipVerification bool +} + +var NdkHeaderInfoProvider = blueprint.NewProvider[NdkHeaderInfo]() + func getHeaderInstallDir(ctx android.ModuleContext, header android.Path, from string, to string) android.OutputPath { // Output path is the sysroot base + "usr/include" + to directory + directory component @@ -135,6 +149,13 @@ func (m *headerModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { if len(m.installPaths) == 0 { ctx.ModuleErrorf("srcs %q matched zero files", m.properties.Srcs) } + + android.SetProvider(ctx, NdkHeaderInfoProvider, NdkHeaderInfo{ + SrcPaths: m.srcPaths, + InstallPaths: m.installPaths, + LicensePath: m.licensePath, + SkipVerification: Bool(m.properties.Skip_verification), + }) } // ndk_headers installs the sets of ndk headers defined in the srcs property @@ -203,6 +224,8 @@ type preprocessedHeadersModule struct { licensePath android.Path } +var NdkPreprocessedHeaderInfoProvider = blueprint.NewProvider[NdkHeaderInfo]() + func (m *preprocessedHeadersModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { if String(m.properties.License) == "" { ctx.PropertyErrorf("license", "field is required") @@ -231,6 +254,13 @@ func (m *preprocessedHeadersModule) GenerateAndroidBuildActions(ctx android.Modu if len(m.installPaths) == 0 { ctx.ModuleErrorf("srcs %q matched zero files", m.properties.Srcs) } + + android.SetProvider(ctx, NdkPreprocessedHeaderInfoProvider, NdkHeaderInfo{ + SrcPaths: m.srcPaths, + InstallPaths: m.installPaths, + LicensePath: m.licensePath, + SkipVerification: Bool(m.properties.Skip_verification), + }) } // preprocessed_ndk_headers preprocesses all the ndk headers listed in the srcs diff --git a/cc/ndk_library.go b/cc/ndk_library.go index 1f0fc0764..c21fe564b 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -560,6 +560,10 @@ func (stub *stubDecorator) nativeCoverage() bool { return false } +func (stub *stubDecorator) defaultDistFiles() []android.Path { + return nil +} + // Returns the install path for unversioned NDK libraries (currently only static // libraries). func getUnversionedLibraryInstallPath(ctx ModuleContext) android.OutputPath { diff --git a/cc/ndk_sysroot.go b/cc/ndk_sysroot.go index a5f014b9f..34f6195a5 100644 --- a/cc/ndk_sysroot.go +++ b/cc/ndk_sysroot.go @@ -53,11 +53,12 @@ package cc // TODO(danalbert): Write `ndk_static_library` rule. import ( - "android/soong/android" "fmt" "path/filepath" "strings" + "android/soong/android" + "github.com/google/blueprint" ) @@ -209,57 +210,61 @@ func (n *ndkSingleton) GenerateBuildActions(ctx android.SingletonContext) { var headerCCompatVerificationTimestampPaths android.Paths var installPaths android.Paths var licensePaths android.Paths - ctx.VisitAllModules(func(module android.Module) { - if m, ok := module.(android.Module); ok && !m.Enabled(ctx) { + ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { + + if !android.OtherModuleProviderOrDefault(ctx, module, android.CommonModuleInfoKey).Enabled { return } - if m, ok := module.(*headerModule); ok { - headerSrcPaths = append(headerSrcPaths, m.srcPaths...) - headerInstallPaths = append(headerInstallPaths, m.installPaths...) - if !Bool(m.properties.Skip_verification) { - for i, installPath := range m.installPaths { + if m, ok := android.OtherModuleProvider(ctx, module, NdkHeaderInfoProvider); ok { + headerSrcPaths = append(headerSrcPaths, m.SrcPaths...) + headerInstallPaths = append(headerInstallPaths, m.InstallPaths...) + if !m.SkipVerification { + for i, installPath := range m.InstallPaths { headersToVerify = append(headersToVerify, srcDestPair{ - src: m.srcPaths[i], + src: m.SrcPaths[i], dest: installPath, }) } } - installPaths = append(installPaths, m.installPaths...) - licensePaths = append(licensePaths, m.licensePath) + installPaths = append(installPaths, m.InstallPaths...) + licensePaths = append(licensePaths, m.LicensePath) } - if m, ok := module.(*preprocessedHeadersModule); ok { - headerSrcPaths = append(headerSrcPaths, m.srcPaths...) - headerInstallPaths = append(headerInstallPaths, m.installPaths...) - if !Bool(m.properties.Skip_verification) { - for i, installPath := range m.installPaths { + if m, ok := android.OtherModuleProvider(ctx, module, NdkPreprocessedHeaderInfoProvider); ok { + headerSrcPaths = append(headerSrcPaths, m.SrcPaths...) + headerInstallPaths = append(headerInstallPaths, m.InstallPaths...) + if !m.SkipVerification { + for i, installPath := range m.InstallPaths { headersToVerify = append(headersToVerify, srcDestPair{ - src: m.srcPaths[i], + src: m.SrcPaths[i], dest: installPath, }) } } - installPaths = append(installPaths, m.installPaths...) - licensePaths = append(licensePaths, m.licensePath) + installPaths = append(installPaths, m.InstallPaths...) + licensePaths = append(licensePaths, m.LicensePath) } - if m, ok := module.(*Module); ok { - if installer, ok := m.installer.(*stubDecorator); ok && m.library.BuildStubs() { - installPaths = append(installPaths, installer.installPath) + if ccInfo, ok := android.OtherModuleProvider(ctx, module, CcInfoProvider); ok { + if installer := ccInfo.InstallerInfo; installer != nil && installer.StubDecoratorInfo != nil && + ccInfo.LibraryInfo != nil && ccInfo.LibraryInfo.BuildStubs { + installPaths = append(installPaths, installer.StubDecoratorInfo.InstallPath) } - if library, ok := m.linker.(*libraryDecorator); ok { - if library.ndkSysrootPath != nil { - staticLibInstallPaths = append( - staticLibInstallPaths, library.ndkSysrootPath) + if ccInfo.LinkerInfo != nil { + if library := ccInfo.LinkerInfo.LibraryDecoratorInfo; library != nil { + if library.NdkSysrootPath != nil { + staticLibInstallPaths = append( + staticLibInstallPaths, library.NdkSysrootPath) + } } - } - if object, ok := m.linker.(*objectLinker); ok { - if object.ndkSysrootPath != nil { - staticLibInstallPaths = append( - staticLibInstallPaths, object.ndkSysrootPath) + if object := ccInfo.LinkerInfo.ObjectLinkerInfo; object != nil { + if object.NdkSysrootPath != nil { + staticLibInstallPaths = append( + staticLibInstallPaths, object.NdkSysrootPath) + } } } } diff --git a/cc/object.go b/cc/object.go index bbfca94c5..95a8beb52 100644 --- a/cc/object.go +++ b/cc/object.go @@ -242,6 +242,10 @@ func (object *objectLinker) isCrt() bool { return Bool(object.Properties.Crt) } +func (object *objectLinker) defaultDistFiles() []android.Path { + return nil +} + func (object *objectLinker) moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON) { object.baseLinker.moduleInfoJSON(ctx, moduleInfoJSON) moduleInfoJSON.Class = []string{"STATIC_LIBRARIES"} diff --git a/cc/stub_library.go b/cc/stub_library.go index 9d7b5bc1a..21ef13915 100644 --- a/cc/stub_library.go +++ b/cc/stub_library.go @@ -43,9 +43,9 @@ func IsStubTarget(info *LinkableInfo) bool { } // Get target file name to be installed from this module -func getInstalledFileName(ctx android.SingletonContext, m LinkableInterface) string { +func getInstalledFileName(ctx android.SingletonContext, m android.ModuleProxy) string { for _, ps := range android.OtherModuleProviderOrDefault( - ctx, m.Module(), android.InstallFilesProvider).PackagingSpecs { + ctx, m, android.InstallFilesProvider).PackagingSpecs { if name := ps.FileName(); name != "" { return name } @@ -57,18 +57,18 @@ func (s *stubLibraries) GenerateBuildActions(ctx android.SingletonContext) { // Visit all generated soong modules and store stub library file names. stubLibraryMap := make(map[string]bool) vendorStubLibraryMap := make(map[string]bool) - ctx.VisitAllModules(func(module android.Module) { - if m, ok := module.(VersionedLinkableInterface); ok { - if IsStubTarget(android.OtherModuleProviderOrDefault(ctx, m, LinkableInfoProvider)) { - if name := getInstalledFileName(ctx, m); name != "" { + ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { + if linkableInfo, ok := android.OtherModuleProvider(ctx, module, LinkableInfoProvider); ok { + if IsStubTarget(linkableInfo) { + if name := getInstalledFileName(ctx, module); name != "" { stubLibraryMap[name] = true - if m.InVendor() { + if linkableInfo.InVendor { vendorStubLibraryMap[name] = true } } } - if m.CcLibraryInterface() && android.IsModulePreferred(m) { - if p := m.VersionedInterface().GetAPIListCoverageXMLPath().String(); p != "" { + if linkableInfo.CcLibraryInterface && android.IsModulePreferredProxy(ctx, module) { + if p := linkableInfo.APIListCoverageXMLPath.String(); p != "" { s.apiListCoverageXmlPaths = append(s.apiListCoverageXmlPaths, p) } } diff --git a/cc/test.go b/cc/test.go index 2c5c36eac..d2c4b28e8 100644 --- a/cc/test.go +++ b/cc/test.go @@ -94,6 +94,11 @@ type TestBinaryProperties struct { // of a host test. Device_first_data []string `android:"path_device_first"` + // Same as data, but will add dependencies on modules using the host's os variation and + // the common arch variation. Useful for a device test that wants to depend on a host + // module, for example to include a custom Tradefed test runner. + Host_common_data []string `android:"path_host_common"` + // list of shared library modules that should be installed alongside the test Data_libs []string `android:"arch_variant"` @@ -345,6 +350,7 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) { dataSrcPaths := android.PathsForModuleSrc(ctx, test.Properties.Data) dataSrcPaths = append(dataSrcPaths, android.PathsForModuleSrc(ctx, test.Properties.Device_common_data)...) dataSrcPaths = append(dataSrcPaths, android.PathsForModuleSrc(ctx, test.Properties.Device_first_data)...) + dataSrcPaths = append(dataSrcPaths, android.PathsForModuleSrc(ctx, test.Properties.Host_common_data)...) for _, dataSrcPath := range dataSrcPaths { test.data = append(test.data, android.DataPath{SrcPath: dataSrcPath}) diff --git a/ci_tests/ci_test_package_zip.go b/ci_tests/ci_test_package_zip.go index d9573a3e3..acfa8e073 100644 --- a/ci_tests/ci_test_package_zip.go +++ b/ci_tests/ci_test_package_zip.go @@ -190,6 +190,10 @@ func createOutput(ctx android.ModuleContext, pctx android.PackageContext) androi } for _, installedFile := range installedFilesInfo.InstallFiles { + // there are additional installed files for some app-class modules, we only need the .apk files in the test package + if class == "app" && installedFile.Ext() != ".apk" { + continue + } name := removeFileExtension(installedFile.Base()) f := strings.TrimPrefix(installedFile.String(), productOut+"/") if strings.HasPrefix(f, "out") { diff --git a/cmd/symbols_map/symbols_map.go b/cmd/symbols_map/symbols_map.go index c56cf93e8..3955c8ad1 100644 --- a/cmd/symbols_map/symbols_map.go +++ b/cmd/symbols_map/symbols_map.go @@ -72,6 +72,7 @@ func main() { elfFile := flags.String("elf", "", "extract identifier from an elf file") r8File := flags.String("r8", "", "extract identifier from an r8 dictionary") + locationFlag := flags.String("location", "", "an override for the value of the location field in the proto. If not specified, the filename will be used") merge := flags.String("merge", "", "merge multiple identifier protos") writeIfChanged := flags.Bool("write_if_changed", false, "only write output file if it is modified") @@ -134,6 +135,10 @@ func main() { panic("shouldn't get here") } + if *locationFlag != "" { + location = *locationFlag + } + mapping := symbols_map_proto.Mapping{ Identifier: proto.String(identifier), Location: proto.String(location), diff --git a/cmd/symbols_map/symbols_map_proto/regen.sh b/cmd/symbols_map/symbols_map_proto/regen.sh new file mode 100755 index 000000000..3c189d163 --- /dev/null +++ b/cmd/symbols_map/symbols_map_proto/regen.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +aprotoc --go_out=paths=source_relative:. symbols_map.proto + diff --git a/cmd/symbols_map/symbols_map_proto/symbols_map.pb.go b/cmd/symbols_map/symbols_map_proto/symbols_map.pb.go index f9c0ce5a3..07f4b39f3 100644 --- a/cmd/symbols_map/symbols_map_proto/symbols_map.pb.go +++ b/cmd/symbols_map/symbols_map_proto/symbols_map.pb.go @@ -14,8 +14,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.27.1 -// protoc v3.9.1 +// protoc-gen-go v1.30.0 +// protoc v3.21.12 // source: symbols_map.proto package symbols_map_proto @@ -93,6 +93,68 @@ func (Mapping_Type) EnumDescriptor() ([]byte, []int) { return file_symbols_map_proto_rawDescGZIP(), []int{0, 0} } +// LocationType is the place where to look for the file with the given +// identifier. +type Mapping_LocationType int32 + +const ( + // ZIP denotes the file with the given identifier is in the distribuited + // symbols.zip or proguard_dict.zip files, or the local disc. + Mapping_ZIP Mapping_LocationType = 0 + // AB denotes the file with the given identifier is in the AB artifacts but + // not in a symbols.zip or proguard_dict.zip. + Mapping_AB Mapping_LocationType = 1 +) + +// Enum value maps for Mapping_LocationType. +var ( + Mapping_LocationType_name = map[int32]string{ + 0: "ZIP", + 1: "AB", + } + Mapping_LocationType_value = map[string]int32{ + "ZIP": 0, + "AB": 1, + } +) + +func (x Mapping_LocationType) Enum() *Mapping_LocationType { + p := new(Mapping_LocationType) + *p = x + return p +} + +func (x Mapping_LocationType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (Mapping_LocationType) Descriptor() protoreflect.EnumDescriptor { + return file_symbols_map_proto_enumTypes[1].Descriptor() +} + +func (Mapping_LocationType) Type() protoreflect.EnumType { + return &file_symbols_map_proto_enumTypes[1] +} + +func (x Mapping_LocationType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Do not use. +func (x *Mapping_LocationType) UnmarshalJSON(b []byte) error { + num, err := protoimpl.X.UnmarshalJSONEnum(x.Descriptor(), b) + if err != nil { + return err + } + *x = Mapping_LocationType(num) + return nil +} + +// Deprecated: Use Mapping_LocationType.Descriptor instead. +func (Mapping_LocationType) EnumDescriptor() ([]byte, []int) { + return file_symbols_map_proto_rawDescGZIP(), []int{0, 1} +} + type Mapping struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -107,6 +169,9 @@ type Mapping struct { Location *string `protobuf:"bytes,2,opt,name=location" json:"location,omitempty"` // type is the type of the mapping, either ELF or R8. Type *Mapping_Type `protobuf:"varint,3,opt,name=type,enum=symbols_map.Mapping_Type" json:"type,omitempty"` + // location_type is the Location Type that dictates where to search for the + // file with the given identifier. Defaults to ZIP if not present. + LocationType *Mapping_LocationType `protobuf:"varint,4,opt,name=location_type,json=locationType,enum=symbols_map.Mapping_LocationType" json:"location_type,omitempty"` } func (x *Mapping) Reset() { @@ -162,6 +227,13 @@ func (x *Mapping) GetType() Mapping_Type { return Mapping_ELF } +func (x *Mapping) GetLocationType() Mapping_LocationType { + if x != nil && x.LocationType != nil { + return *x.LocationType + } + return Mapping_ZIP +} + type Mappings struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -214,23 +286,29 @@ var File_symbols_map_proto protoreflect.FileDescriptor var file_symbols_map_proto_rawDesc = []byte{ 0x0a, 0x11, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x73, 0x5f, 0x6d, 0x61, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x73, 0x5f, 0x6d, 0x61, 0x70, - 0x22, 0x8d, 0x01, 0x0a, 0x07, 0x4d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x12, 0x1e, 0x0a, 0x0a, + 0x22, 0xf6, 0x01, 0x0a, 0x07, 0x4d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x12, 0x1e, 0x0a, 0x0a, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x2d, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x19, 0x2e, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x73, 0x5f, 0x6d, 0x61, 0x70, 0x2e, 0x4d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x54, 0x79, 0x70, - 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x17, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, - 0x07, 0x0a, 0x03, 0x45, 0x4c, 0x46, 0x10, 0x00, 0x12, 0x06, 0x0a, 0x02, 0x52, 0x38, 0x10, 0x01, - 0x22, 0x3c, 0x0a, 0x08, 0x4d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x30, 0x0a, 0x08, - 0x6d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, + 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x46, 0x0a, 0x0d, 0x6c, 0x6f, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x21, 0x2e, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x73, 0x5f, 0x6d, 0x61, 0x70, 0x2e, 0x4d, 0x61, 0x70, - 0x70, 0x69, 0x6e, 0x67, 0x52, 0x08, 0x6d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x73, 0x42, 0x31, - 0x5a, 0x2f, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2f, 0x73, 0x6f, 0x6f, 0x6e, 0x67, 0x2f, - 0x63, 0x6d, 0x64, 0x2f, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x73, 0x5f, 0x6d, 0x61, 0x70, 0x2f, - 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x73, 0x5f, 0x6d, 0x61, 0x70, 0x5f, 0x70, 0x72, 0x6f, 0x74, - 0x6f, + 0x70, 0x69, 0x6e, 0x67, 0x2e, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x79, 0x70, + 0x65, 0x52, 0x0c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x22, + 0x17, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x07, 0x0a, 0x03, 0x45, 0x4c, 0x46, 0x10, 0x00, + 0x12, 0x06, 0x0a, 0x02, 0x52, 0x38, 0x10, 0x01, 0x22, 0x1f, 0x0a, 0x0c, 0x4c, 0x6f, 0x63, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x07, 0x0a, 0x03, 0x5a, 0x49, 0x50, 0x10, + 0x00, 0x12, 0x06, 0x0a, 0x02, 0x41, 0x42, 0x10, 0x01, 0x22, 0x3c, 0x0a, 0x08, 0x4d, 0x61, 0x70, + 0x70, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x30, 0x0a, 0x08, 0x6d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, + 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, + 0x73, 0x5f, 0x6d, 0x61, 0x70, 0x2e, 0x4d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x52, 0x08, 0x6d, + 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x73, 0x42, 0x31, 0x5a, 0x2f, 0x61, 0x6e, 0x64, 0x72, 0x6f, + 0x69, 0x64, 0x2f, 0x73, 0x6f, 0x6f, 0x6e, 0x67, 0x2f, 0x63, 0x6d, 0x64, 0x2f, 0x73, 0x79, 0x6d, + 0x62, 0x6f, 0x6c, 0x73, 0x5f, 0x6d, 0x61, 0x70, 0x2f, 0x73, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x73, + 0x5f, 0x6d, 0x61, 0x70, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, } var ( @@ -245,21 +323,23 @@ func file_symbols_map_proto_rawDescGZIP() []byte { return file_symbols_map_proto_rawDescData } -var file_symbols_map_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_symbols_map_proto_enumTypes = make([]protoimpl.EnumInfo, 2) var file_symbols_map_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_symbols_map_proto_goTypes = []interface{}{ - (Mapping_Type)(0), // 0: symbols_map.Mapping.Type - (*Mapping)(nil), // 1: symbols_map.Mapping - (*Mappings)(nil), // 2: symbols_map.Mappings + (Mapping_Type)(0), // 0: symbols_map.Mapping.Type + (Mapping_LocationType)(0), // 1: symbols_map.Mapping.LocationType + (*Mapping)(nil), // 2: symbols_map.Mapping + (*Mappings)(nil), // 3: symbols_map.Mappings } var file_symbols_map_proto_depIdxs = []int32{ 0, // 0: symbols_map.Mapping.type:type_name -> symbols_map.Mapping.Type - 1, // 1: symbols_map.Mappings.mappings:type_name -> symbols_map.Mapping - 2, // [2:2] is the sub-list for method output_type - 2, // [2:2] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 1, // 1: symbols_map.Mapping.location_type:type_name -> symbols_map.Mapping.LocationType + 2, // 2: symbols_map.Mappings.mappings:type_name -> symbols_map.Mapping + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_symbols_map_proto_init() } @@ -298,7 +378,7 @@ func file_symbols_map_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_symbols_map_proto_rawDesc, - NumEnums: 1, + NumEnums: 2, NumMessages: 2, NumExtensions: 0, NumServices: 0, diff --git a/cmd/symbols_map/symbols_map_proto/symbols_map.proto b/cmd/symbols_map/symbols_map_proto/symbols_map.proto index a76d17147..a52f75c2e 100644 --- a/cmd/symbols_map/symbols_map_proto/symbols_map.proto +++ b/cmd/symbols_map/symbols_map_proto/symbols_map.proto @@ -40,7 +40,7 @@ message Mapping { // LocationType is the place where to look for the file with the given // identifier. - Enum LocationType { + enum LocationType { // ZIP denotes the file with the given identifier is in the distribuited // symbols.zip or proguard_dict.zip files, or the local disc. ZIP = 0; @@ -56,4 +56,4 @@ message Mapping { message Mappings { repeated Mapping mappings = 4; -}
\ No newline at end of file +} diff --git a/dexpreopt/Android.bp b/dexpreopt/Android.bp index 679d06627..ea3f52bd2 100644 --- a/dexpreopt/Android.bp +++ b/dexpreopt/Android.bp @@ -9,6 +9,7 @@ bootstrap_go_package { "class_loader_context.go", "config.go", "dexpreopt.go", + "system_server_zip.go", "testing.go", ], testSrcs: [ diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go index 1452b412e..699a6757d 100644 --- a/dexpreopt/dexpreopt.go +++ b/dexpreopt/dexpreopt.go @@ -283,10 +283,7 @@ func dexpreoptCommand(ctx android.BuilderContext, globalSoong *GlobalSoongConfig clcHostString := "PCL[" + strings.Join(clcHost.Strings(), ":") + "]" clcTargetString := "PCL[" + strings.Join(clcTarget, ":") + "]" - if systemServerClasspathJars.ContainsJar(module.Name) { - // TODO(b/397461231): renable this check - //checkSystemServerOrder(ctx, jarIndex) - } else { + if !systemServerClasspathJars.ContainsJar(module.Name) { // Standalone jars are loaded by separate class loaders with SYSTEMSERVERCLASSPATH as the // parent. clcHostString = "PCL[];" + clcHostString @@ -578,29 +575,6 @@ func SystemServerDexJarHostPath(ctx android.PathContext, jar string) android.Out } } -// Check the order of jars on the system server classpath and give a warning/error if a jar precedes -// one of its dependencies. This is not an error, but a missed optimization, as dexpreopt won't -// have the dependency jar in the class loader context, and it won't be able to resolve any -// references to its classes and methods. -func checkSystemServerOrder(ctx android.PathContext, jarIndex int) { - mctx, isModule := ctx.(android.ModuleContext) - if isModule { - config := GetGlobalConfig(ctx) - jars := config.AllSystemServerClasspathJars(ctx) - mctx.WalkDeps(func(dep android.Module, parent android.Module) bool { - depIndex := jars.IndexOfJar(dep.Name()) - if jarIndex < depIndex && !config.BrokenSuboptimalOrderOfSystemServerJars { - jar := jars.Jar(jarIndex) - dep := jars.Jar(depIndex) - mctx.ModuleErrorf("non-optimal order of jars on the system server classpath:"+ - " '%s' precedes its dependency '%s', so dexpreopt is unable to resolve any"+ - " references from '%s' to '%s'.\n", jar, dep, jar, dep) - } - return true - }) - } -} - // Returns path to a file containing the reult of verify_uses_libraries check (empty if the check // has succeeded, or an error message if it failed). func UsesLibrariesStatusFile(ctx android.ModuleContext) android.WritablePath { diff --git a/dexpreopt/system_server_zip.go b/dexpreopt/system_server_zip.go new file mode 100644 index 000000000..cef847b7d --- /dev/null +++ b/dexpreopt/system_server_zip.go @@ -0,0 +1,49 @@ +package dexpreopt + +import "android/soong/android" + +func init() { + android.InitRegistrationContext.RegisterSingletonType("system_server_zip_singleton", systemServerZipSingletonFactory) +} + +func systemServerZipSingletonFactory() android.Singleton { + return &systemServerZipSingleton{} +} + +type systemServerZipSingleton struct{} + +func (s *systemServerZipSingleton) GenerateBuildActions(ctx android.SingletonContext) { + global := GetGlobalConfig(ctx) + if global.DisablePreopt || global.OnlyPreoptArtBootImage { + return + } + + systemServerDexjarsDir := android.PathForOutput(ctx, SystemServerDexjarsDir) + + out := android.PathForOutput(ctx, "system_server.zip") + builder := android.NewRuleBuilder(pctx, ctx) + cmd := builder.Command().BuiltTool("soong_zip"). + FlagWithOutput("-o ", out). + FlagWithArg("-C ", systemServerDexjarsDir.String()) + + for i := 0; i < global.SystemServerJars.Len(); i++ { + jar := global.SystemServerJars.Jar(i) + ".jar" + cmd.FlagWithInput("-f ", systemServerDexjarsDir.Join(ctx, jar)) + } + for i := 0; i < global.StandaloneSystemServerJars.Len(); i++ { + jar := global.StandaloneSystemServerJars.Jar(i) + ".jar" + cmd.FlagWithInput("-f ", systemServerDexjarsDir.Join(ctx, jar)) + } + for i := 0; i < global.ApexSystemServerJars.Len(); i++ { + jar := global.ApexSystemServerJars.Jar(i) + ".jar" + cmd.FlagWithInput("-f ", systemServerDexjarsDir.Join(ctx, jar)) + } + for i := 0; i < global.ApexStandaloneSystemServerJars.Len(); i++ { + jar := global.ApexStandaloneSystemServerJars.Jar(i) + ".jar" + cmd.FlagWithInput("-f ", systemServerDexjarsDir.Join(ctx, jar)) + } + + builder.Build("system_server_zip", "building system_server.zip") + + ctx.DistForGoal("droidcore", out) +} diff --git a/etc/prebuilt_etc.go b/etc/prebuilt_etc.go index a440c9113..fad8f0779 100644 --- a/etc/prebuilt_etc.go +++ b/etc/prebuilt_etc.go @@ -61,6 +61,7 @@ func RegisterPrebuiltEtcBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("prebuilt_usr_keychars", PrebuiltUserKeyCharsFactory) ctx.RegisterModuleType("prebuilt_usr_idc", PrebuiltUserIdcFactory) ctx.RegisterModuleType("prebuilt_usr_srec", PrebuiltUserSrecFactory) + ctx.RegisterModuleType("prebuilt_usr_odml", PrebuiltUserOdmlFactory) ctx.RegisterModuleType("prebuilt_font", PrebuiltFontFactory) ctx.RegisterModuleType("prebuilt_overlay", PrebuiltOverlayFactory) ctx.RegisterModuleType("prebuilt_firmware", PrebuiltFirmwareFactory) @@ -786,6 +787,17 @@ func PrebuiltUserSrecFactory() android.Module { return module } +// prebuilt_usr_odml is for a prebuilt artifact that is installed in +// <partition>/usr/odml/<sub_dir> directory. +func PrebuiltUserOdmlFactory() android.Module { + module := &PrebuiltEtc{} + InitPrebuiltEtcModule(module, "usr/odml") + // This module is device-only + android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) + android.InitDefaultableModule(module) + return module +} + // prebuilt_font installs a font in <partition>/fonts directory. func PrebuiltFontFactory() android.Module { module := &PrebuiltEtc{} diff --git a/filesystem/android_device.go b/filesystem/android_device.go index 4ee5681dc..178c716d4 100644 --- a/filesystem/android_device.go +++ b/filesystem/android_device.go @@ -17,16 +17,24 @@ package filesystem import ( "cmp" "fmt" + "path/filepath" "slices" "strings" "sync/atomic" "android/soong/android" + "android/soong/java" "github.com/google/blueprint" "github.com/google/blueprint/proptools" ) +var proguardDictToProto = pctx.AndroidStaticRule("proguard_dict_to_proto", blueprint.RuleParams{ + Command: `${symbols_map} -r8 $in -location $location -write_if_changed $out`, + Restat: true, + CommandDeps: []string{"${symbols_map}"}, +}, "location") + type PartitionNameProperties struct { // Name of the super partition filesystem module Super_partition_name *string @@ -89,6 +97,10 @@ type androidDevice struct { deviceProps DeviceProperties allImagesZip android.Path + + proguardDictZip android.Path + proguardDictMapping android.Path + proguardUsageZip android.Path } func AndroidDeviceFactory() android.Module { @@ -161,7 +173,11 @@ func (a *androidDevice) GenerateAndroidBuildActions(ctx android.ModuleContext) { } } + allInstalledModules := a.allInstalledModules(ctx) + a.buildTargetFilesZip(ctx) + a.buildProguardZips(ctx, allInstalledModules) + var deps []android.Path if proptools.String(a.partitionProps.Super_partition_name) != "" { superImage := ctx.GetDirectDepProxyWithTag(*a.partitionProps.Super_partition_name, superPartitionDepTag) @@ -214,7 +230,7 @@ func (a *androidDevice) GenerateAndroidBuildActions(ctx android.ModuleContext) { allImagesZip := android.PathForModuleOut(ctx, "all_images.zip") allImagesZipBuilder := android.NewRuleBuilder(pctx, ctx) - cmd := allImagesZipBuilder.Command().BuiltTool("soong_zip").Flag("--sort_entries") + cmd := allImagesZipBuilder.Command().BuiltTool("soong_zip") for _, dep := range deps { cmd.FlagWithArg("-e ", dep.Base()) cmd.FlagWithInput("-f ", dep) @@ -281,28 +297,89 @@ func (a *androidDevice) allInstalledModules(ctx android.ModuleContext) []android return ret } +func insertBeforeExtension(file, insertion string) string { + ext := filepath.Ext(file) + return strings.TrimSuffix(file, ext) + insertion + ext +} + func (a *androidDevice) distFiles(ctx android.ModuleContext) { - if !ctx.Config().KatiEnabled() { - if proptools.Bool(a.deviceProps.Main_device) { - fsInfoMap := a.getFsInfos(ctx) - for _, partition := range android.SortedKeys(fsInfoMap) { - fsInfo := fsInfoMap[partition] - if fsInfo.InstalledFiles.Json != nil { - ctx.DistForGoal("droidcore-unbundled", fsInfo.InstalledFiles.Json) - } - if fsInfo.InstalledFiles.Txt != nil { - ctx.DistForGoal("droidcore-unbundled", fsInfo.InstalledFiles.Txt) - } + if !ctx.Config().KatiEnabled() && proptools.Bool(a.deviceProps.Main_device) { + fsInfoMap := a.getFsInfos(ctx) + for _, partition := range android.SortedKeys(fsInfoMap) { + fsInfo := fsInfoMap[partition] + if fsInfo.InstalledFiles.Json != nil { + ctx.DistForGoal("droidcore-unbundled", fsInfo.InstalledFiles.Json) + } + if fsInfo.InstalledFiles.Txt != nil { + ctx.DistForGoal("droidcore-unbundled", fsInfo.InstalledFiles.Txt) } } - } + namePrefix := "" + if ctx.Config().HasDeviceProduct() { + namePrefix = ctx.Config().DeviceProduct() + "-" + } + ctx.DistForGoalWithFilename("droidcore-unbundled", a.proguardDictZip, namePrefix+insertBeforeExtension(a.proguardDictZip.Base(), "-FILE_NAME_TAG_PLACEHOLDER")) + ctx.DistForGoalWithFilename("droidcore-unbundled", a.proguardDictMapping, namePrefix+insertBeforeExtension(a.proguardDictMapping.Base(), "-FILE_NAME_TAG_PLACEHOLDER")) + ctx.DistForGoalWithFilename("droidcore-unbundled", a.proguardUsageZip, namePrefix+insertBeforeExtension(a.proguardUsageZip.Base(), "-FILE_NAME_TAG_PLACEHOLDER")) + } } -func (a *androidDevice) MakeVars(ctx android.MakeVarsModuleContext) { +func (a *androidDevice) MakeVars(_ android.MakeVarsModuleContext) []android.ModuleMakeVarsValue { if proptools.Bool(a.deviceProps.Main_device) { - ctx.StrictRaw("SOONG_ONLY_ALL_IMAGES_ZIP", a.allImagesZip.String()) + return []android.ModuleMakeVarsValue{{"SOONG_ONLY_ALL_IMAGES_ZIP", a.allImagesZip.String()}} + } + return nil +} + +func (a *androidDevice) buildProguardZips(ctx android.ModuleContext, allInstalledModules []android.Module) { + dictZip := android.PathForModuleOut(ctx, "proguard-dict.zip") + dictZipBuilder := android.NewRuleBuilder(pctx, ctx) + dictZipCmd := dictZipBuilder.Command().BuiltTool("soong_zip").Flag("-d").FlagWithOutput("-o ", dictZip) + + dictMapping := android.PathForModuleOut(ctx, "proguard-dict-mapping.textproto") + dictMappingBuilder := android.NewRuleBuilder(pctx, ctx) + dictMappingCmd := dictMappingBuilder.Command().BuiltTool("symbols_map").Flag("-merge").Output(dictMapping) + + protosDir := android.PathForModuleOut(ctx, "proguard_mapping_protos") + + usageZip := android.PathForModuleOut(ctx, "proguard-usage.zip") + usageZipBuilder := android.NewRuleBuilder(pctx, ctx) + usageZipCmd := usageZipBuilder.Command().BuiltTool("merge_zips").Output(usageZip) + + for _, mod := range allInstalledModules { + if proguardInfo, ok := android.OtherModuleProvider(ctx, mod, java.ProguardProvider); ok { + // Maintain these out/target/common paths for backwards compatibility. They may be able + // to be changed if tools look up file locations from the protobuf, but I'm not + // exactly sure how that works. + dictionaryFakePath := fmt.Sprintf("out/target/common/obj/%s/%s_intermediates/proguard_dictionary", proguardInfo.Class, proguardInfo.ModuleName) + dictZipCmd.FlagWithArg("-e ", dictionaryFakePath) + dictZipCmd.FlagWithInput("-f ", proguardInfo.ProguardDictionary) + dictZipCmd.Textf("-e out/target/common/obj/%s/%s_intermediates/classes.jar", proguardInfo.Class, proguardInfo.ModuleName) + dictZipCmd.FlagWithInput("-f ", proguardInfo.ClassesJar) + + protoFile := protosDir.Join(ctx, filepath.Dir(dictionaryFakePath), "proguard_dictionary.textproto") + ctx.Build(pctx, android.BuildParams{ + Rule: proguardDictToProto, + Input: proguardInfo.ProguardDictionary, + Output: protoFile, + Args: map[string]string{ + "location": dictionaryFakePath, + }, + }) + dictMappingCmd.Input(protoFile) + + usageZipCmd.Input(proguardInfo.ProguardUsageZip) + } } + + dictZipBuilder.Build("proguard_dict_zip", "Building proguard dictionary zip") + dictMappingBuilder.Build("proguard_dict_mapping_proto", "Building proguard mapping proto") + usageZipBuilder.Build("proguard_usage_zip", "Building proguard usage zip") + + a.proguardDictZip = dictZip + a.proguardDictMapping = dictMapping + a.proguardUsageZip = usageZip } // Helper structs for target_files.zip creation diff --git a/filesystem/filesystem.go b/filesystem/filesystem.go index 1ce6131aa..d4ea6a34c 100644 --- a/filesystem/filesystem.go +++ b/filesystem/filesystem.go @@ -33,11 +33,14 @@ import ( "github.com/google/blueprint/proptools" ) +var pctx = android.NewPackageContext("android/soong/filesystem") + func init() { registerBuildComponents(android.InitRegistrationContext) registerMutators(android.InitRegistrationContext) pctx.HostBinToolVariable("fileslist", "fileslist") pctx.HostBinToolVariable("fs_config", "fs_config") + pctx.HostBinToolVariable("symbols_map", "symbols_map") } func registerBuildComponents(ctx android.RegistrationContext) { @@ -576,8 +579,6 @@ func buildInstalledFiles(ctx android.ModuleContext, partition string, rootDir an return txt, json } -var pctx = android.NewPackageContext("android/soong/filesystem") - func (f *filesystem) GenerateAndroidBuildActions(ctx android.ModuleContext) { validatePartitionType(ctx, f) if f.filesystemBuilder.ShouldUseVintfFragmentModuleOnly() { @@ -1524,10 +1525,11 @@ func addAutogeneratedRroDeps(ctx android.BottomUpMutatorContext) { }) } -func (f *filesystem) MakeVars(ctx android.MakeVarsModuleContext) { +func (f *filesystem) MakeVars(ctx android.MakeVarsModuleContext) []android.ModuleMakeVarsValue { if f.Name() == ctx.Config().SoongDefinedSystemImage() { - ctx.StrictRaw("SOONG_DEFINED_SYSTEM_IMAGE_PATH", f.output.String()) + return []android.ModuleMakeVarsValue{{"SOONG_DEFINED_SYSTEM_IMAGE_PATH", f.output.String()}} } + return nil } func setCommonFilesystemInfo(ctx android.ModuleContext, m Filesystem) { diff --git a/fsgen/filesystem_creator.go b/fsgen/filesystem_creator.go index e2485a1d3..3d83706a3 100644 --- a/fsgen/filesystem_creator.go +++ b/fsgen/filesystem_creator.go @@ -347,11 +347,9 @@ func (f *filesystemCreator) createDeviceModule( superImageSubPartitions []string, ) { baseProps := &struct { - Name *string - Android_info *string + Name *string }{ - Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "device")), - Android_info: proptools.StringPtr(":" + generatedModuleName(ctx.Config(), "android_info.prop{.txt}")), + Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "device")), } // Currently, only the system and system_ext partition module is created. @@ -406,6 +404,7 @@ func (f *filesystemCreator) createDeviceModule( Ab_ota_partitions: ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.AbOtaPartitions, Ab_ota_postinstall_config: ctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse.AbOtaPostInstallConfig, Ramdisk_node_list: proptools.StringPtr(":ramdisk_node_list"), + Android_info: proptools.StringPtr(":" + generatedModuleName(ctx.Config(), "android_info.prop{.txt}")), } if bootloader, ok := f.createBootloaderFilegroup(ctx); ok { diff --git a/fuzz/fuzz_common.go b/fuzz/fuzz_common.go index 3fd79a719..83ccd89ae 100644 --- a/fuzz/fuzz_common.go +++ b/fuzz/fuzz_common.go @@ -427,6 +427,12 @@ type FuzzProperties struct { // device's first architecture's variant. Can be useful to add device-built apps to the data // of a host test. Device_first_data []string `android:"path_device_first"` + + // Same as data, but will add dependencies on modules using the host's os variation and + // the common arch variation. Useful for a device test that wants to depend on a host + // module, for example to include a custom Tradefed test runner. + Host_common_data []string `android:"path_host_common"` + // Optional dictionary to be installed to the fuzz target's output directory. Dictionary *string `android:"path"` // Define the fuzzing frameworks this fuzz target can be built for. If diff --git a/java/aar.go b/java/aar.go index f7c5c13de..0e27cb8fd 100644 --- a/java/aar.go +++ b/java/aar.go @@ -217,7 +217,7 @@ func (p propagateRROEnforcementTransitionMutator) Mutate(ctx android.BottomUpMut } func (a *aapt) useResourceProcessorBusyBox(ctx android.BaseModuleContext) bool { - return BoolDefault(a.aaptProperties.Use_resource_processor, ctx.Config().UseResourceProcessorByDefault()) && + return BoolDefault(a.aaptProperties.Use_resource_processor, true) && // TODO(b/331641946): remove this when ResourceProcessorBusyBox supports generating shared libraries. !slices.Contains(a.aaptProperties.Aaptflags, "--shared-lib") && // Use the legacy resource processor in kythe builds. @@ -945,6 +945,12 @@ type AndroidLibraryInfo struct { var AndroidLibraryInfoProvider = blueprint.NewProvider[AndroidLibraryInfo]() +type AARImportInfo struct { + // Empty for now +} + +var AARImportInfoProvider = blueprint.NewProvider[AARImportInfo]() + type AndroidLibrary struct { Library aapt @@ -1479,12 +1485,7 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { completeStaticLibsResourceJars := depset.New(depset.PREORDER, nil, transitiveStaticLibsResourceJars) var implementationJarFile android.Path - var combineJars android.Paths - if ctx.Config().UseTransitiveJarsInClasspath() { - combineJars = completeStaticLibsImplementationJars.ToList() - } else { - combineJars = append(android.Paths{classpathFile}, staticJars...) - } + combineJars := completeStaticLibsImplementationJars.ToList() if len(combineJars) > 1 { implementationJarOutputPath := android.PathForModuleOut(ctx, "combined", jarName) @@ -1495,12 +1496,8 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { } var resourceJarFile android.Path - var resourceJars android.Paths - if ctx.Config().UseTransitiveJarsInClasspath() { - resourceJars = completeStaticLibsResourceJars.ToList() - } else { - resourceJars = staticResourceJars - } + resourceJars := completeStaticLibsResourceJars.ToList() + if len(resourceJars) > 1 { combinedJar := android.PathForModuleOut(ctx, "res-combined", jarName) TransformJarsToJar(ctx, combinedJar, "for resources", resourceJars, android.OptionalPath{}, @@ -1511,12 +1508,8 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { } // merge implementation jar with resources if necessary - var implementationAndResourcesJars android.Paths - if ctx.Config().UseTransitiveJarsInClasspath() { - implementationAndResourcesJars = append(slices.Clone(resourceJars), combineJars...) - } else { - implementationAndResourcesJars = android.PathsIfNonNil(resourceJarFile, implementationJarFile) - } + implementationAndResourcesJars := append(slices.Clone(resourceJars), combineJars...) + var implementationAndResourcesJar android.Path if len(implementationAndResourcesJars) > 1 { combinedJar := android.PathForModuleOut(ctx, "withres", jarName) @@ -1531,12 +1524,7 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource a.implementationAndResourcesJarFile = implementationAndResourcesJar.WithoutRel() - var headerJars android.Paths - if ctx.Config().UseTransitiveJarsInClasspath() { - headerJars = completeStaticLibsHeaderJars.ToList() - } else { - headerJars = append(android.Paths{classpathFile}, staticHeaderJars...) - } + headerJars := completeStaticLibsHeaderJars.ToList() if len(headerJars) > 1 { headerJarFile := android.PathForModuleOut(ctx, "turbine-combined", jarName) TransformJarsToJar(ctx, headerJarFile, "combine header jars", headerJars, android.OptionalPath{}, false, nil, nil) @@ -1545,12 +1533,7 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.headerJarFile = headerJars[0] } - if ctx.Config().UseTransitiveJarsInClasspath() { - ctx.CheckbuildFile(classpathFile) - } else { - ctx.CheckbuildFile(a.headerJarFile) - ctx.CheckbuildFile(a.implementationJarFile) - } + ctx.CheckbuildFile(classpathFile) javaInfo := &JavaInfo{ HeaderJars: android.PathsIfNonNil(a.headerJarFile), @@ -1594,6 +1577,8 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { JniPackages: a.jniPackages, }) + android.SetProvider(ctx, AARImportInfoProvider, AARImportInfo{}) + ctx.SetOutputFiles([]android.Path{a.implementationAndResourcesJarFile}, "") ctx.SetOutputFiles([]android.Path{a.aarPath}, ".aar") diff --git a/java/app.go b/java/app.go index 9b10bf3cd..827b23526 100644 --- a/java/app.go +++ b/java/app.go @@ -452,6 +452,16 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { android.SetProvider(ctx, AppInfoProvider, appInfo) a.requiredModuleNames = a.getRequiredModuleNames(ctx) + + if a.dexer.proguardDictionary.Valid() { + android.SetProvider(ctx, ProguardProvider, ProguardInfo{ + ModuleName: ctx.ModuleName(), + Class: "APPS", + ProguardDictionary: a.dexer.proguardDictionary.Path(), + ProguardUsageZip: a.dexer.proguardUsageZip.Path(), + ClassesJar: a.implementationAndResourcesJar, + }) + } } func (a *AndroidApp) getRequiredModuleNames(ctx android.ModuleContext) []string { @@ -1114,6 +1124,11 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { android.SetProvider(ctx, JavaInfoProvider, javaInfo) } + android.SetProvider(ctx, android.ApexBundleDepsDataProvider, android.ApexBundleDepsData{ + FlatListPath: a.FlatListPath(), + Updatable: a.Updatable(), + }) + moduleInfoJSON := ctx.ModuleInfoJSON() moduleInfoJSON.Class = []string{"APPS"} if !a.embeddedJniLibs { @@ -1636,6 +1651,7 @@ func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_common_data)...) a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_first_data)...) a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_first_prefer32_data)...) + a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Host_common_data)...) // Install test deps if !ctx.Config().KatiEnabled() { diff --git a/java/app_test.go b/java/app_test.go index 4f23f61a4..5f5f04d78 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -887,15 +887,24 @@ func TestAndroidResourceProcessor(t *testing.T) { }, appSrcJars: []string{"out/soong/.intermediates/app/android_common/gen/android/R.srcjar"}, appClasspath: []string{ - "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", - "out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar", - "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar", - "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar", + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine/android_stubs_current.jar", + "out/soong/.intermediates/shared/android_common/turbine/shared.jar", + "out/soong/.intermediates/shared_transitive_static/android_common/turbine/shared_transitive_static.jar", + "out/soong/.intermediates/direct/android_common/turbine/direct.jar", + "out/soong/.intermediates/transitive/android_common/turbine/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", + "out/soong/.intermediates/direct_import/android_common/aar/direct_import.jar", + "out/soong/.intermediates/direct_import_dep/android_common/aar/direct_import_dep.jar", }, appCombined: []string{ "out/soong/.intermediates/app/android_common/javac/app.jar", - "out/soong/.intermediates/direct/android_common/combined/direct.jar", - "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar", + "out/soong/.intermediates/direct/android_common/javac/direct.jar", + "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", + "out/soong/.intermediates/direct_import/android_common/aar/direct_import.jar", + "out/soong/.intermediates/direct_import_dep/android_common/aar/direct_import_dep.jar", }, directResources: nil, @@ -908,21 +917,23 @@ func TestAndroidResourceProcessor(t *testing.T) { directImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, directSrcJars: []string{"out/soong/.intermediates/direct/android_common/gen/android/R.srcjar"}, directClasspath: []string{ - "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", - "out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar", - "out/soong/.intermediates/transitive_import/android_common/turbine-combined/transitive_import.jar", + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine/android_stubs_current.jar", + "out/soong/.intermediates/transitive/android_common/turbine/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", }, directCombined: []string{ "out/soong/.intermediates/direct/android_common/javac/direct.jar", "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", - "out/soong/.intermediates/transitive_import/android_common/combined/transitive_import.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", }, transitiveResources: []string{"out/soong/.intermediates/transitive/android_common/aapt2/transitive/res/values_strings.arsc.flat"}, transitiveOverlays: nil, transitiveImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, transitiveSrcJars: []string{"out/soong/.intermediates/transitive/android_common/gen/android/R.srcjar"}, - transitiveClasspath: []string{"out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar"}, + transitiveClasspath: []string{"out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine/android_stubs_current.jar"}, transitiveCombined: nil, sharedResources: nil, @@ -936,9 +947,9 @@ func TestAndroidResourceProcessor(t *testing.T) { }, sharedSrcJars: []string{"out/soong/.intermediates/shared/android_common/gen/android/R.srcjar"}, sharedClasspath: []string{ - "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", - "out/soong/.intermediates/shared_transitive_shared/android_common/turbine-combined/shared_transitive_shared.jar", - "out/soong/.intermediates/shared_transitive_static/android_common/turbine-combined/shared_transitive_static.jar", + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine/android_stubs_current.jar", + "out/soong/.intermediates/shared_transitive_shared/android_common/turbine/shared_transitive_shared.jar", + "out/soong/.intermediates/shared_transitive_static/android_common/turbine/shared_transitive_static.jar", }, sharedCombined: []string{ "out/soong/.intermediates/shared/android_common/javac/shared.jar", @@ -985,17 +996,26 @@ func TestAndroidResourceProcessor(t *testing.T) { }, appSrcJars: nil, appClasspath: []string{ - "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine/android_stubs_current.jar", "out/soong/.intermediates/app/android_common/busybox/R.jar", - "out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar", - "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar", - "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar", + "out/soong/.intermediates/shared/android_common/turbine/shared.jar", + "out/soong/.intermediates/shared_transitive_static/android_common/turbine/shared_transitive_static.jar", + "out/soong/.intermediates/direct/android_common/turbine/direct.jar", + "out/soong/.intermediates/transitive/android_common/turbine/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", + "out/soong/.intermediates/direct_import/android_common/aar/direct_import.jar", + "out/soong/.intermediates/direct_import_dep/android_common/aar/direct_import_dep.jar", }, appCombined: []string{ "out/soong/.intermediates/app/android_common/javac/app.jar", "out/soong/.intermediates/app/android_common/busybox/R.jar", - "out/soong/.intermediates/direct/android_common/combined/direct.jar", - "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar", + "out/soong/.intermediates/direct/android_common/javac/direct.jar", + "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", + "out/soong/.intermediates/direct_import/android_common/aar/direct_import.jar", + "out/soong/.intermediates/direct_import_dep/android_common/aar/direct_import_dep.jar", }, directResources: nil, @@ -1008,18 +1028,20 @@ func TestAndroidResourceProcessor(t *testing.T) { }, directSrcJars: nil, directClasspath: []string{ - "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine/android_stubs_current.jar", "out/soong/.intermediates/direct/android_common/busybox/R.jar", "out/soong/.intermediates/transitive/android_common/busybox/R.jar", "out/soong/.intermediates/transitive_import_dep/android_common/busybox/R.jar", "out/soong/.intermediates/transitive_import/android_common/busybox/R.jar", - "out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar", - "out/soong/.intermediates/transitive_import/android_common/turbine-combined/transitive_import.jar", + "out/soong/.intermediates/transitive/android_common/turbine/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", }, directCombined: []string{ "out/soong/.intermediates/direct/android_common/javac/direct.jar", "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", - "out/soong/.intermediates/transitive_import/android_common/combined/transitive_import.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", }, transitiveResources: []string{"out/soong/.intermediates/transitive/android_common/aapt2/transitive/res/values_strings.arsc.flat"}, @@ -1027,7 +1049,7 @@ func TestAndroidResourceProcessor(t *testing.T) { transitiveImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, transitiveSrcJars: nil, transitiveClasspath: []string{ - "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine/android_stubs_current.jar", "out/soong/.intermediates/transitive/android_common/busybox/R.jar", }, transitiveCombined: nil, @@ -1041,12 +1063,12 @@ func TestAndroidResourceProcessor(t *testing.T) { }, sharedSrcJars: nil, sharedClasspath: []string{ - "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine/android_stubs_current.jar", "out/soong/.intermediates/shared/android_common/busybox/R.jar", "out/soong/.intermediates/shared_transitive_static/android_common/busybox/R.jar", "out/soong/.intermediates/shared_transitive_shared/android_common/busybox/R.jar", - "out/soong/.intermediates/shared_transitive_shared/android_common/turbine-combined/shared_transitive_shared.jar", - "out/soong/.intermediates/shared_transitive_static/android_common/turbine-combined/shared_transitive_static.jar", + "out/soong/.intermediates/shared_transitive_shared/android_common/turbine/shared_transitive_shared.jar", + "out/soong/.intermediates/shared_transitive_static/android_common/turbine/shared_transitive_static.jar", }, sharedCombined: []string{ "out/soong/.intermediates/shared/android_common/javac/shared.jar", @@ -1090,18 +1112,27 @@ func TestAndroidResourceProcessor(t *testing.T) { }, appSrcJars: nil, appClasspath: []string{ - "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine/android_stubs_current.jar", // R.jar has to come before direct.jar "out/soong/.intermediates/app/android_common/busybox/R.jar", - "out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar", - "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar", - "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar", + "out/soong/.intermediates/shared/android_common/turbine/shared.jar", + "out/soong/.intermediates/shared_transitive_static/android_common/turbine/shared_transitive_static.jar", + "out/soong/.intermediates/direct/android_common/turbine/direct.jar", + "out/soong/.intermediates/transitive/android_common/turbine/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", + "out/soong/.intermediates/direct_import/android_common/aar/direct_import.jar", + "out/soong/.intermediates/direct_import_dep/android_common/aar/direct_import_dep.jar", }, appCombined: []string{ "out/soong/.intermediates/app/android_common/javac/app.jar", "out/soong/.intermediates/app/android_common/busybox/R.jar", - "out/soong/.intermediates/direct/android_common/combined/direct.jar", - "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar", + "out/soong/.intermediates/direct/android_common/javac/direct.jar", + "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", + "out/soong/.intermediates/direct_import/android_common/aar/direct_import.jar", + "out/soong/.intermediates/direct_import_dep/android_common/aar/direct_import_dep.jar", }, dontVerifyDirect: true, @@ -1133,15 +1164,24 @@ func TestAndroidResourceProcessor(t *testing.T) { }, appSrcJars: []string{"out/soong/.intermediates/app/android_common/gen/android/R.srcjar"}, appClasspath: []string{ - "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", - "out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar", - "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar", - "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar", + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine/android_stubs_current.jar", + "out/soong/.intermediates/shared/android_common/turbine/shared.jar", + "out/soong/.intermediates/shared_transitive_static/android_common/turbine/shared_transitive_static.jar", + "out/soong/.intermediates/direct/android_common/turbine/direct.jar", + "out/soong/.intermediates/transitive/android_common/turbine/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", + "out/soong/.intermediates/direct_import/android_common/aar/direct_import.jar", + "out/soong/.intermediates/direct_import_dep/android_common/aar/direct_import_dep.jar", }, appCombined: []string{ "out/soong/.intermediates/app/android_common/javac/app.jar", - "out/soong/.intermediates/direct/android_common/combined/direct.jar", - "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar", + "out/soong/.intermediates/direct/android_common/javac/direct.jar", + "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", + "out/soong/.intermediates/direct_import/android_common/aar/direct_import.jar", + "out/soong/.intermediates/direct_import_dep/android_common/aar/direct_import_dep.jar", }, directResources: nil, @@ -1154,17 +1194,19 @@ func TestAndroidResourceProcessor(t *testing.T) { }, directSrcJars: nil, directClasspath: []string{ - "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine/android_stubs_current.jar", "out/soong/.intermediates/direct/android_common/busybox/R.jar", "out/soong/.intermediates/transitive_import_dep/android_common/busybox/R.jar", "out/soong/.intermediates/transitive_import/android_common/busybox/R.jar", - "out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar", - "out/soong/.intermediates/transitive_import/android_common/turbine-combined/transitive_import.jar", + "out/soong/.intermediates/transitive/android_common/turbine/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", }, directCombined: []string{ "out/soong/.intermediates/direct/android_common/javac/direct.jar", "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", - "out/soong/.intermediates/transitive_import/android_common/combined/transitive_import.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", }, dontVerifyTransitive: true, @@ -1195,15 +1237,24 @@ func TestAndroidResourceProcessor(t *testing.T) { }, appSrcJars: []string{"out/soong/.intermediates/app/android_common/gen/android/R.srcjar"}, appClasspath: []string{ - "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", - "out/soong/.intermediates/shared/android_common/turbine-combined/shared.jar", - "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar", - "out/soong/.intermediates/direct_import/android_common/turbine-combined/direct_import.jar", + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine/android_stubs_current.jar", + "out/soong/.intermediates/shared/android_common/turbine/shared.jar", + "out/soong/.intermediates/shared_transitive_static/android_common/turbine/shared_transitive_static.jar", + "out/soong/.intermediates/direct/android_common/turbine/direct.jar", + "out/soong/.intermediates/transitive/android_common/turbine/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", + "out/soong/.intermediates/direct_import/android_common/aar/direct_import.jar", + "out/soong/.intermediates/direct_import_dep/android_common/aar/direct_import_dep.jar", }, appCombined: []string{ "out/soong/.intermediates/app/android_common/javac/app.jar", - "out/soong/.intermediates/direct/android_common/combined/direct.jar", - "out/soong/.intermediates/direct_import/android_common/combined/direct_import.jar", + "out/soong/.intermediates/direct/android_common/javac/direct.jar", + "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", + "out/soong/.intermediates/direct_import/android_common/aar/direct_import.jar", + "out/soong/.intermediates/direct_import_dep/android_common/aar/direct_import_dep.jar", }, directResources: nil, @@ -1216,14 +1267,16 @@ func TestAndroidResourceProcessor(t *testing.T) { directImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, directSrcJars: []string{"out/soong/.intermediates/direct/android_common/gen/android/R.srcjar"}, directClasspath: []string{ - "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", - "out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar", - "out/soong/.intermediates/transitive_import/android_common/turbine-combined/transitive_import.jar", + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine/android_stubs_current.jar", + "out/soong/.intermediates/transitive/android_common/turbine/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", }, directCombined: []string{ "out/soong/.intermediates/direct/android_common/javac/direct.jar", "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", - "out/soong/.intermediates/transitive_import/android_common/combined/transitive_import.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/transitive_import.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/aar/transitive_import_dep.jar", }, transitiveResources: []string{"out/soong/.intermediates/transitive/android_common/aapt2/transitive/res/values_strings.arsc.flat"}, @@ -1231,7 +1284,7 @@ func TestAndroidResourceProcessor(t *testing.T) { transitiveImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, transitiveSrcJars: nil, transitiveClasspath: []string{ - "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine/android_stubs_current.jar", "out/soong/.intermediates/transitive/android_common/busybox/R.jar", }, transitiveCombined: nil, @@ -1480,7 +1533,6 @@ func TestAndroidResourceOverlays(t *testing.T) { "device/vendor/blah/overlay/bar/res/values/strings.xml", }, {"lib", "android_common"}: { - "out/soong/.intermediates/lib2/android_common/package-res.apk", "lib/res/res/values/strings.xml", "device/vendor/blah/overlay/lib/res/values/strings.xml", }, @@ -1515,12 +1567,10 @@ func TestAndroidResourceOverlays(t *testing.T) { "device/vendor/blah/overlay/bar/res/values/strings.xml", }, {"lib", "android_common"}: { - "out/soong/.intermediates/lib2/android_common/package-res.apk", "lib/res/res/values/strings.xml", "device/vendor/blah/overlay/lib/res/values/strings.xml", }, {"lib", "android_common_rro"}: { - "out/soong/.intermediates/lib2/android_common_rro/package-res.apk", "lib/res/res/values/strings.xml", }, }, @@ -1560,7 +1610,6 @@ func TestAndroidResourceOverlays(t *testing.T) { }, {"bar", "android_common"}: {"device/vendor/blah/static_overlay/bar/res/values/strings.xml"}, {"lib", "android_common"}: { - "out/soong/.intermediates/lib2/android_common/package-res.apk", "lib/res/res/values/strings.xml", }, }, @@ -3000,14 +3049,14 @@ func TestOverrideAndroidAppDependency(t *testing.T) { // Verify baz, which depends on the overridden module foo, has the correct classpath javac arg. javac := ctx.ModuleForTests(t, "baz", "android_common").Rule("javac") - fooTurbine := "out/soong/.intermediates/foo/android_common/turbine-combined/foo.jar" + fooTurbine := "out/soong/.intermediates/foo/android_common/turbine/foo.jar" if !strings.Contains(javac.Args["classpath"], fooTurbine) { t.Errorf("baz classpath %v does not contain %q", javac.Args["classpath"], fooTurbine) } // Verify qux, which depends on the overriding module bar, has the correct classpath javac arg. javac = ctx.ModuleForTests(t, "qux", "android_common").Rule("javac") - barTurbine := "out/soong/.intermediates/foo/android_common_bar/turbine-combined/foo.jar" + barTurbine := "out/soong/.intermediates/foo/android_common_bar/turbine/foo.jar" if !strings.Contains(javac.Args["classpath"], barTurbine) { t.Errorf("qux classpath %v does not contain %q", javac.Args["classpath"], barTurbine) } @@ -3084,7 +3133,7 @@ func TestOverrideAndroidTest(t *testing.T) { // Check if javac classpath has the correct jar file path. This checks instrumentation_for overrides. javac := variant.Rule("javac") - turbine := filepath.Join("out", "soong", ".intermediates", "foo", expected.targetVariant, "turbine-combined", "foo.jar") + turbine := filepath.Join("out", "soong", ".intermediates", "foo", expected.targetVariant, "turbine", "foo.jar") if !strings.Contains(javac.Args["classpath"], turbine) { t.Errorf("classpath %q does not contain %q", javac.Args["classpath"], turbine) } diff --git a/java/base.go b/java/base.go index fccc80691..0833831fc 100644 --- a/java/base.go +++ b/java/base.go @@ -1298,15 +1298,11 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath } j.headerJarFile = combinedHeaderJarFile - if ctx.Config().UseTransitiveJarsInClasspath() { - if len(localHeaderJars) > 0 { - ctx.CheckbuildFile(localHeaderJars...) - } else { - // There are no local sources or resources in this module, so there is nothing to checkbuild. - ctx.UncheckedModule() - } + if len(localHeaderJars) > 0 { + ctx.CheckbuildFile(localHeaderJars...) } else { - ctx.CheckbuildFile(j.headerJarFile) + // There are no local sources or resources in this module, so there is nothing to checkbuild. + ctx.UncheckedModule() } j.outputFile = j.headerJarFile @@ -1604,12 +1600,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath completeStaticLibsResourceJars := depset.New(depset.PREORDER, localResourceJars, deps.transitiveStaticLibsResourceJars) var combinedResourceJar android.Path - var resourceJars android.Paths - if ctx.Config().UseTransitiveJarsInClasspath() { - resourceJars = completeStaticLibsResourceJars.ToList() - } else { - resourceJars = append(slices.Clone(localResourceJars), deps.staticResourceJars...) - } + resourceJars := completeStaticLibsResourceJars.ToList() if len(resourceJars) == 1 { combinedResourceJar = resourceJars[0] } else if len(resourceJars) > 0 { @@ -1630,12 +1621,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath completeStaticLibsImplementationJars := depset.New(depset.PREORDER, localImplementationJars, deps.transitiveStaticLibsImplementationJars) - var jars android.Paths - if ctx.Config().UseTransitiveJarsInClasspath() { - jars = completeStaticLibsImplementationJars.ToList() - } else { - jars = append(slices.Clone(localImplementationJars), deps.staticJars...) - } + jars := completeStaticLibsImplementationJars.ToList() jars = append(jars, extraDepCombinedJars...) @@ -1766,7 +1752,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath headerJarFile := android.PathForModuleOut(ctx, "javac-header", jarName) convertImplementationJarToHeaderJar(ctx, j.implementationJarFile, headerJarFile) j.headerJarFile = headerJarFile - if len(localImplementationJars) == 1 && ctx.Config().UseTransitiveJarsInClasspath() { + if len(localImplementationJars) == 1 { localHeaderJarFile := android.PathForModuleOut(ctx, "local-javac-header", jarName) convertImplementationJarToHeaderJar(ctx, localImplementationJars[0], localHeaderJarFile) localHeaderJars = append(localHeaderJars, localHeaderJarFile) @@ -1796,16 +1782,10 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath // merge implementation jar with resources if necessary var implementationAndResourcesJarsToCombine android.Paths - if ctx.Config().UseTransitiveJarsInClasspath() { - resourceJars := completeStaticLibsResourceJars.ToList() - if len(resourceJars) > 0 { - implementationAndResourcesJarsToCombine = append(resourceJars, completeStaticLibsImplementationJarsToCombine.ToList()...) - implementationAndResourcesJarsToCombine = append(implementationAndResourcesJarsToCombine, extraDepCombinedJars...) - } - } else { - if combinedResourceJar != nil { - implementationAndResourcesJarsToCombine = android.Paths{combinedResourceJar, outputFile} - } + combinedResourceJars := completeStaticLibsResourceJars.ToList() + if len(combinedResourceJars) > 0 { + implementationAndResourcesJarsToCombine = slices.Concat(combinedResourceJars, + completeStaticLibsImplementationJarsToCombine.ToList(), extraDepCombinedJars) } if len(implementationAndResourcesJarsToCombine) > 0 { @@ -1855,18 +1835,9 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath } // merge dex jar with resources if necessary - var dexAndResourceJarsToCombine android.Paths - if ctx.Config().UseTransitiveJarsInClasspath() { - resourceJars := completeStaticLibsResourceJars.ToList() - if len(resourceJars) > 0 { - dexAndResourceJarsToCombine = append(android.Paths{dexOutputFile}, resourceJars...) - } - } else { - if combinedResourceJar != nil { - dexAndResourceJarsToCombine = android.Paths{dexOutputFile, combinedResourceJar} - } - } - if len(dexAndResourceJarsToCombine) > 0 { + if len(combinedResourceJars) > 0 { + dexAndResourceJarsToCombine := append(android.Paths{dexOutputFile}, combinedResourceJars...) + combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName) TransformJarsToJar(ctx, combinedJar, "for dex resources", dexAndResourceJarsToCombine, android.OptionalPath{}, false, nil, nil) @@ -1938,18 +1909,13 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath j.collectTransitiveSrcFiles(ctx, srcFiles) - if ctx.Config().UseTransitiveJarsInClasspath() { - if len(localImplementationJars) > 0 || len(localResourceJars) > 0 || len(localHeaderJars) > 0 { - ctx.CheckbuildFile(localImplementationJars...) - ctx.CheckbuildFile(localResourceJars...) - ctx.CheckbuildFile(localHeaderJars...) - } else { - // There are no local sources or resources in this module, so there is nothing to checkbuild. - ctx.UncheckedModule() - } + if len(localImplementationJars) > 0 || len(localResourceJars) > 0 || len(localHeaderJars) > 0 { + ctx.CheckbuildFile(localImplementationJars...) + ctx.CheckbuildFile(localResourceJars...) + ctx.CheckbuildFile(localHeaderJars...) } else { - ctx.CheckbuildFile(j.implementationJarFile) - ctx.CheckbuildFile(j.headerJarFile) + // There are no local sources or resources in this module, so there is nothing to checkbuild. + ctx.UncheckedModule() } // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource @@ -2116,13 +2082,8 @@ func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars // Combine any static header libraries into classes-header.jar. If there is only // one input jar this step will be skipped. - var jars android.Paths - if ctx.Config().UseTransitiveJarsInClasspath() { - depSet := depset.New(depset.PREORDER, localHeaderJars, deps.transitiveStaticLibsHeaderJars) - jars = depSet.ToList() - } else { - jars = append(slices.Clone(localHeaderJars), deps.staticHeaderJars...) - } + depSet := depset.New(depset.PREORDER, localHeaderJars, deps.transitiveStaticLibsHeaderJars) + jars := depSet.ToList() // we cannot skip the combine step for now if there is only one jar // since we have to strip META-INF/TRANSITIVE dir from turbine.jar @@ -2634,14 +2595,12 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { deps.transitiveStaticLibsImplementationJars = transitiveStaticJarsImplementationLibs deps.transitiveStaticLibsResourceJars = transitiveStaticJarsResourceLibs - if ctx.Config().UseTransitiveJarsInClasspath() { - depSet := depset.New(depset.PREORDER, nil, transitiveClasspathHeaderJars) - deps.classpath = depSet.ToList() - depSet = depset.New(depset.PREORDER, nil, transitiveBootClasspathHeaderJars) - deps.bootClasspath = depSet.ToList() - depSet = depset.New(depset.PREORDER, nil, transitiveJava9ClasspathHeaderJars) - deps.java9Classpath = depSet.ToList() - } + depSet := depset.New(depset.PREORDER, nil, transitiveClasspathHeaderJars) + deps.classpath = depSet.ToList() + depSet = depset.New(depset.PREORDER, nil, transitiveBootClasspathHeaderJars) + deps.bootClasspath = depSet.ToList() + depSet = depset.New(depset.PREORDER, nil, transitiveJava9ClasspathHeaderJars) + deps.java9Classpath = depSet.ToList() if ctx.Device() { sdkDep := decodeSdkDep(ctx, android.SdkContext(j)) diff --git a/java/device_host_converter_test.go b/java/device_host_converter_test.go index 197bb9f95..42e3b4678 100644 --- a/java/device_host_converter_test.go +++ b/java/device_host_converter_test.go @@ -15,10 +15,11 @@ package java import ( - "android/soong/android" "slices" "strings" "testing" + + "android/soong/android" ) func TestDeviceForHost(t *testing.T) { @@ -54,12 +55,12 @@ func TestDeviceForHost(t *testing.T) { ctx, config := testJava(t, bp) deviceModule := ctx.ModuleForTests(t, "device_module", "android_common") - deviceTurbineCombined := deviceModule.Output("turbine-combined/device_module.jar") + deviceTurbine := deviceModule.Output("turbine/device_module.jar") deviceJavac := deviceModule.Output("javac/device_module.jar") deviceRes := deviceModule.Output("res/device_module.jar") deviceImportModule := ctx.ModuleForTests(t, "device_import_module", "android_common") - deviceImportCombined := deviceImportModule.Output("combined/device_import_module.jar") + deviceImportCombined := deviceImportModule.Output("local-combined/device_import_module.jar") hostModule := ctx.ModuleForTests(t, "host_module", config.BuildOSCommonTarget.String()) hostJavac := hostModule.Output("javac/host_module.jar") @@ -69,7 +70,7 @@ func TestDeviceForHost(t *testing.T) { // check classpath of host module with dependency on device_for_host_module expectedClasspath := "-classpath " + strings.Join(android.Paths{ - deviceTurbineCombined.Output, + deviceTurbine.Output, deviceImportCombined.Output, }.Strings(), ":") @@ -137,11 +138,11 @@ func TestHostForDevice(t *testing.T) { hostModule := ctx.ModuleForTests(t, "host_module", config.BuildOSCommonTarget.String()) hostJavac := hostModule.Output("javac/host_module.jar") - hostJavacHeader := hostModule.Output("javac-header/host_module.jar") + hostJavacHeader := hostModule.Output("local-javac-header/host_module.jar") hostRes := hostModule.Output("res/host_module.jar") hostImportModule := ctx.ModuleForTests(t, "host_import_module", config.BuildOSCommonTarget.String()) - hostImportCombined := hostImportModule.Output("combined/host_import_module.jar") + hostImportCombined := hostImportModule.Output("local-combined/host_import_module.jar") deviceModule := ctx.ModuleForTests(t, "device_module", "android_common") deviceJavac := deviceModule.Output("javac/device_module.jar") diff --git a/java/dex.go b/java/dex.go index c9d3f376d..ed2df2103 100644 --- a/java/dex.go +++ b/java/dex.go @@ -435,6 +435,11 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, dexParams *compileDexParams, android.PathForSource(ctx, "build/make/core/proguard.flags"), } + if ctx.Config().UseR8GlobalCheckNotNullFlags() { + flagFiles = append(flagFiles, android.PathForSource(ctx, + "build/make/core/proguard/checknotnull.flags")) + } + flagFiles = append(flagFiles, d.extraProguardFlagsFiles...) // TODO(ccross): static android library proguard files @@ -583,7 +588,6 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam var description string var artProfileOutputPath *android.OutputPath var implicitOutputs android.WritablePaths - var flags []string var deps android.Paths args := map[string]string{ "zipFlags": zipFlags, @@ -610,18 +614,13 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam description = "r8" debugMode := android.InList("--debug", commonFlags) r8Flags, r8Deps, r8ArtProfileOutputPath := d.r8Flags(ctx, dexParams, debugMode) - flags = append(flags, r8Flags...) deps = append(deps, r8Deps...) args["r8Flags"] = strings.Join(append(commonFlags, r8Flags...), " ") if r8ArtProfileOutputPath != nil { artProfileOutputPath = r8ArtProfileOutputPath - implicitOutputs = append( - implicitOutputs, - artProfileOutputPath, - ) // Add the implicit r8 Art profile output to args so that r8RE knows // about this implicit output - args["outR8ArtProfile"] = artProfileOutputPath.String() + args["outR8ArtProfile"] = r8ArtProfileOutputPath.String() } args["outDict"] = proguardDictionary.String() args["outConfig"] = proguardConfiguration.String() @@ -642,16 +641,11 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam if useD8 { description = "d8" d8Flags, d8Deps, d8ArtProfileOutputPath := d.d8Flags(ctx, dexParams) - flags = append(flags, d8Flags...) deps = append(deps, d8Deps...) deps = append(deps, commonDeps...) args["d8Flags"] = strings.Join(append(commonFlags, d8Flags...), " ") if d8ArtProfileOutputPath != nil { artProfileOutputPath = d8ArtProfileOutputPath - implicitOutputs = append( - implicitOutputs, - artProfileOutputPath, - ) } // If we are generating both d8 and r8, only use RBE when both are enabled. switch { @@ -667,6 +661,12 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam rule = d8 } } + if artProfileOutputPath != nil { + implicitOutputs = append( + implicitOutputs, + artProfileOutputPath, + ) + } ctx.Build(pctx, android.BuildParams{ Rule: rule, Description: description, @@ -697,3 +697,13 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam return javalibJar, artProfileOutputPath } + +type ProguardInfo struct { + ModuleName string + Class string + ProguardDictionary android.Path + ProguardUsageZip android.Path + ClassesJar android.Path +} + +var ProguardProvider = blueprint.NewProvider[ProguardInfo]() diff --git a/java/dex_test.go b/java/dex_test.go index 2126e42e8..66d801dcc 100644 --- a/java/dex_test.go +++ b/java/dex_test.go @@ -70,16 +70,17 @@ func TestR8(t *testing.T) { appR8 := app.Rule("r8") stableAppR8 := stableApp.Rule("r8") corePlatformAppR8 := corePlatformApp.Rule("r8") - libHeader := lib.Output("turbine-combined/lib.jar").Output - staticLibHeader := staticLib.Output("turbine-combined/static_lib.jar").Output + libHeader := lib.Output("turbine/lib.jar").Output + libCombinedHeader := lib.Output("turbine-combined/lib.jar").Output + staticLibHeader := staticLib.Output("turbine/static_lib.jar").Output android.AssertStringDoesContain(t, "expected lib header jar in app javac classpath", appJavac.Args["classpath"], libHeader.String()) android.AssertStringDoesContain(t, "expected static_lib header jar in app javac classpath", appJavac.Args["classpath"], staticLibHeader.String()) - android.AssertStringDoesContain(t, "expected lib header jar in app r8 classpath", - appR8.Args["r8Flags"], libHeader.String()) + android.AssertStringDoesContain(t, "expected lib combined header jar in app r8 classpath", + appR8.Args["r8Flags"], libCombinedHeader.String()) android.AssertStringDoesNotContain(t, "expected no static_lib header jar in app r8 classpath", appR8.Args["r8Flags"], staticLibHeader.String()) android.AssertStringDoesContain(t, "expected -ignorewarnings in app r8 flags", @@ -331,16 +332,17 @@ func TestD8(t *testing.T) { fooJavac := foo.Rule("javac") fooD8 := foo.Rule("d8") appD8 := app.Rule("d8") - libHeader := lib.Output("turbine-combined/lib.jar").Output - staticLibHeader := staticLib.Output("turbine-combined/static_lib.jar").Output + libHeader := lib.Output("turbine/lib.jar").Output + libCombinedHeader := lib.Output("turbine-combined/lib.jar").Output + staticLibHeader := staticLib.Output("turbine/static_lib.jar").Output android.AssertStringDoesContain(t, "expected lib header jar in foo javac classpath", fooJavac.Args["classpath"], libHeader.String()) android.AssertStringDoesContain(t, "expected static_lib header jar in foo javac classpath", fooJavac.Args["classpath"], staticLibHeader.String()) - android.AssertStringDoesContain(t, "expected lib header jar in foo d8 classpath", - fooD8.Args["d8Flags"], libHeader.String()) + android.AssertStringDoesContain(t, "expected lib combined header jar in foo d8 classpath", + fooD8.Args["d8Flags"], libCombinedHeader.String()) android.AssertStringDoesNotContain(t, "expected no static_lib header jar in foo javac classpath", fooD8.Args["d8Flags"], staticLibHeader.String()) diff --git a/java/dexpreopt.go b/java/dexpreopt.go index 5755dec23..b21cfc968 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -565,6 +565,10 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJa if !isApexSystemServerJar { d.builtInstalled = dexpreoptRule.Installs().String() } + + if isSystemServerJar { + checkSystemServerOrder(ctx, libName) + } } func getModuleInstallPathInfo(ctx android.ModuleContext, fullInstallPath string) (android.InstallPath, string, string) { @@ -631,3 +635,30 @@ func (d *dexpreopter) GetRewrittenProfile() android.Path { func (d *dexpreopter) SetRewrittenProfile(p android.Path) { d.rewrittenProfile = p } + +// Check the order of jars on the system server classpath and give a warning/error if a jar precedes +// one of its dependencies. This is not an error, but a missed optimization, as dexpreopt won't +// have the dependency jar in the class loader context, and it won't be able to resolve any +// references to its classes and methods. +func checkSystemServerOrder(ctx android.ModuleContext, libName string) { + config := dexpreopt.GetGlobalConfig(ctx) + jars := config.AllSystemServerClasspathJars(ctx) + jarIndex := config.AllSystemServerJars(ctx).IndexOfJar(libName) + ctx.WalkDeps(func(dep android.Module, parent android.Module) bool { + tag := ctx.OtherModuleDependencyTag(dep) + // Ideally this should only be walking relevant dependencies, but to maintain existing behavior + // for now just exclude any known irrelevant dependencies that would lead to incorrect errors. + if _, ok := tag.(bootclasspathDependencyTag); ok { + return false + } + depIndex := jars.IndexOfJar(dep.Name()) + if jarIndex < depIndex && !config.BrokenSuboptimalOrderOfSystemServerJars { + jar := jars.Jar(jarIndex) + dep := jars.Jar(depIndex) + ctx.ModuleErrorf("non-optimal order of jars on the system server classpath:"+ + " '%s' precedes its dependency '%s', so dexpreopt is unable to resolve any"+ + " references from '%s' to '%s'.\n", jar, dep, jar, dep) + } + return true + }) +} diff --git a/java/fuzz_test.go b/java/fuzz_test.go index 8cbe873ad..735b8da93 100644 --- a/java/fuzz_test.go +++ b/java/fuzz_test.go @@ -72,8 +72,8 @@ func TestJavaFuzz(t *testing.T) { } baz := result.ModuleForTests(t, "baz", osCommonTarget).Rule("javac").Output.String() - barOut := filepath.Join("out", "soong", ".intermediates", "bar", osCommonTarget, "javac-header", "bar.jar") - bazOut := filepath.Join("out", "soong", ".intermediates", "baz", osCommonTarget, "javac-header", "baz.jar") + barOut := filepath.Join("out", "soong", ".intermediates", "bar", osCommonTarget, "local-javac-header", "bar.jar") + bazOut := filepath.Join("out", "soong", ".intermediates", "baz", osCommonTarget, "local-javac-header", "baz.jar") android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], barOut) android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], bazOut) diff --git a/java/java.go b/java/java.go index 45e55d53c..38361bfa7 100644 --- a/java/java.go +++ b/java/java.go @@ -432,6 +432,9 @@ type JavaInfo struct { DexJarBuildPath OptionalDexJarPath DexpreopterInfo *DexpreopterInfo + + XrefJavaFiles android.Paths + XrefKotlinFiles android.Paths } var JavaInfoProvider = blueprint.NewProvider[*JavaInfo]() @@ -1172,6 +1175,16 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { buildComplianceMetadata(ctx) j.createApiXmlFile(ctx) + + if j.dexer.proguardDictionary.Valid() { + android.SetProvider(ctx, ProguardProvider, ProguardInfo{ + ModuleName: ctx.ModuleName(), + Class: "JAVA_LIBRARIES", + ProguardDictionary: j.dexer.proguardDictionary.Path(), + ProguardUsageZip: j.dexer.proguardUsageZip.Path(), + ClassesJar: j.implementationAndResourcesJar, + }) + } } func (j *Library) javaLibraryModuleInfoJSON(ctx android.ModuleContext) *android.ModuleInfoJSON { @@ -1539,6 +1552,11 @@ type testProperties struct { // host test. Device_first_prefer32_data []string `android:"path_device_first_prefer32"` + // Same as data, but will add dependencies on modules using the host's os variation and + // the common arch variation. Useful for a device test that wants to depend on a host + // module, for example to include a custom Tradefed test runner. + Host_common_data []string `android:"path_host_common"` + // Flag to indicate whether or not to create test config automatically. If AndroidTest.xml // doesn't exist next to the Android.bp, this attribute doesn't need to be set to true // explicitly. @@ -1837,6 +1855,7 @@ func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext, j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Device_common_data)...) j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Device_first_data)...) j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Device_first_prefer32_data)...) + j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Host_common_data)...) j.extraTestConfigs = android.PathsForModuleSrc(ctx, j.testProperties.Test_options.Extra_test_configs) @@ -3072,12 +3091,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { // file of the module to be named jarName. var outputFile android.Path combinedImplementationJar := android.PathForModuleOut(ctx, "combined", jarName) - var implementationJars android.Paths - if ctx.Config().UseTransitiveJarsInClasspath() { - implementationJars = completeStaticLibsImplementationJars.ToList() - } else { - implementationJars = append(slices.Clone(localJars), staticJars...) - } + implementationJars := completeStaticLibsImplementationJars.ToList() TransformJarsToJar(ctx, combinedImplementationJar, "combine prebuilt implementation jars", implementationJars, android.OptionalPath{}, false, j.properties.Exclude_files, j.properties.Exclude_dirs) outputFile = combinedImplementationJar @@ -3100,12 +3114,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { if reuseImplementationJarAsHeaderJar { headerJar = outputFile } else { - var headerJars android.Paths - if ctx.Config().UseTransitiveJarsInClasspath() { - headerJars = completeStaticLibsHeaderJars.ToList() - } else { - headerJars = append(slices.Clone(localJars), staticHeaderJars...) - } + headerJars := completeStaticLibsHeaderJars.ToList() headerOutputFile := android.PathForModuleOut(ctx, "turbine-combined", jarName) TransformJarsToJar(ctx, headerOutputFile, "combine prebuilt header jars", headerJars, android.OptionalPath{}, false, j.properties.Exclude_files, j.properties.Exclude_dirs) @@ -3169,11 +3178,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.properties.Aidl.Export_include_dirs) - if ctx.Config().UseTransitiveJarsInClasspath() { - ctx.CheckbuildFile(localJars...) - } else { - ctx.CheckbuildFile(outputFile) - } + ctx.CheckbuildFile(localJars...) if ctx.Device() { // Shared libraries deapexed from prebuilt apexes are no longer supported. @@ -3647,10 +3652,10 @@ type kytheExtractJavaSingleton struct { func (ks *kytheExtractJavaSingleton) GenerateBuildActions(ctx android.SingletonContext) { var xrefTargets android.Paths var xrefKotlinTargets android.Paths - ctx.VisitAllModules(func(module android.Module) { - if javaModule, ok := module.(xref); ok { - xrefTargets = append(xrefTargets, javaModule.XrefJavaFiles()...) - xrefKotlinTargets = append(xrefKotlinTargets, javaModule.XrefKotlinFiles()...) + ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { + if javaInfo, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok { + xrefTargets = append(xrefTargets, javaInfo.XrefJavaFiles...) + xrefKotlinTargets = append(xrefKotlinTargets, javaInfo.XrefKotlinFiles...) } }) // TODO(asmundak): perhaps emit a rule to output a warning if there were no xrefTargets @@ -3851,4 +3856,9 @@ func setExtraJavaInfo(ctx android.ModuleContext, module android.Module, javaInfo ApexSystemServerDexJars: di.ApexSystemServerDexJars(), } } + + if xr, ok := module.(xref); ok { + javaInfo.XrefJavaFiles = xr.XrefJavaFiles() + javaInfo.XrefKotlinFiles = xr.XrefKotlinFiles() + } } diff --git a/java/java_test.go b/java/java_test.go index f097762eb..a6290a628 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -110,7 +110,7 @@ func defaultModuleToPath(name string) string { case strings.HasSuffix(name, ".jar"): return name default: - return filepath.Join("out", "soong", ".intermediates", defaultJavaDir, name, "android_common", "turbine-combined", name+".jar") + return filepath.Join("out", "soong", ".intermediates", defaultJavaDir, name, "android_common", "turbine", name+".jar") } } @@ -240,11 +240,6 @@ func TestSimple(t *testing.T) { srcs: ["d.java"], }` - frameworkTurbineCombinedJars := []string{ - "out/soong/.intermediates/default/java/ext/android_common/turbine-combined/ext.jar", - "out/soong/.intermediates/default/java/framework/android_common/turbine-combined/framework.jar", - } - frameworkTurbineJars := []string{ "out/soong/.intermediates/default/java/ext/android_common/turbine/ext.jar", "out/soong/.intermediates/default/java/framework/android_common/turbine/framework.jar", @@ -270,43 +265,6 @@ func TestSimple(t *testing.T) { preparer: android.NullFixturePreparer, fooJavacInputs: []string{"a.java"}, fooJavacClasspath: slices.Concat( - frameworkTurbineCombinedJars, - []string{ - "out/soong/.intermediates/bar/android_common/turbine-combined/bar.jar", - "out/soong/.intermediates/baz/android_common/turbine-combined/baz.jar", - }, - ), - fooCombinedInputs: []string{ - "out/soong/.intermediates/foo/android_common/javac/foo.jar", - "out/soong/.intermediates/baz/android_common/combined/baz.jar", - }, - - fooHeaderCombinedInputs: []string{ - "out/soong/.intermediates/foo/android_common/turbine/foo.jar", - "out/soong/.intermediates/baz/android_common/turbine-combined/baz.jar", - }, - - barJavacInputs: []string{"b.java"}, - barJavacClasspath: slices.Concat( - frameworkTurbineCombinedJars, - []string{ - "out/soong/.intermediates/quz/android_common/turbine-combined/quz.jar", - }, - ), - barCombinedInputs: []string{ - "out/soong/.intermediates/bar/android_common/javac/bar.jar", - "out/soong/.intermediates/quz/android_common/javac/quz.jar", - }, - barHeaderCombinedInputs: []string{ - "out/soong/.intermediates/bar/android_common/turbine/bar.jar", - "out/soong/.intermediates/quz/android_common/turbine-combined/quz.jar", - }, - }, - { - name: "transitive classpath", - preparer: PrepareForTestWithTransitiveClasspathEnabled, - fooJavacInputs: []string{"a.java"}, - fooJavacClasspath: slices.Concat( frameworkTurbineJars, []string{ "out/soong/.intermediates/bar/android_common/turbine/bar.jar", @@ -627,6 +585,29 @@ func TestTest(t *testing.T) { } } +func TestHostCommonData(t *testing.T) { + t.Parallel() + ctx, _ := testJava(t, ` + java_library_host { + name: "host", + srcs: ["a.java"], + } + + java_test { + name: "foo", + srcs: ["a.java"], + host_common_data: [":host"], + } + `) + + foo := ctx.ModuleForTests(t, "foo", "android_common").Module().(*Test) + host := ctx.ModuleForTests(t, "host", ctx.Config().BuildOSCommonTarget.String()).Module().(*Library) + + if g, w := foo.data.RelativeToTop().Strings(), []string{host.outputFile.RelativeToTop().String()}; !slices.Equal(g, w) { + t.Errorf("expected test data %q, got %q\n", w, g) + } +} + func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) { t.Parallel() bp := ` @@ -726,11 +707,11 @@ func TestPrebuilts(t *testing.T) { javac := fooModule.Rule("javac") combineJar := ctx.ModuleForTests(t, "foo", "android_common").Description("for javac") barModule := ctx.ModuleForTests(t, "bar", "android_common") - barJar := barModule.Output("combined/bar.jar").Output + barJar := barModule.Output("local-combined/bar.jar").Output bazModule := ctx.ModuleForTests(t, "baz", "android_common") - bazJar := bazModule.Output("combined/baz.jar").Output + bazJar := bazModule.Output("local-combined/baz.jar").Output sdklibStubsJar := ctx.ModuleForTests(t, "sdklib.stubs", "android_common"). - Output("combined/sdklib.stubs.jar").Output + Output("local-combined/sdklib.stubs.jar").Output fooLibrary := fooModule.Module().(*Library) assertDeepEquals(t, "foo unique sources incorrect", @@ -858,7 +839,7 @@ func TestDefaults(t *testing.T) { t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs) } - barTurbine := filepath.Join("out", "soong", ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar") + barTurbine := filepath.Join("out", "soong", ".intermediates", "bar", "android_common", "turbine", "bar.jar") if !strings.Contains(javac.Args["classpath"], barTurbine) { t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barTurbine) } @@ -1047,7 +1028,7 @@ func TestIncludeSrcs(t *testing.T) { t.Errorf("bar combined resource jars %v does not contain %q", w, g) } - if g, w := barResCombined.Output.String(), bar.Inputs.Strings(); !inList(g, w) { + if g, w := barRes.Output.String(), bar.Inputs.Strings(); !inList(g, w) { t.Errorf("bar combined jars %v does not contain %q", w, g) } @@ -1131,7 +1112,7 @@ func TestTurbine(t *testing.T) { android.AssertPathsRelativeToTopEquals(t, "foo inputs", []string{"a.java"}, fooTurbine.Inputs) - fooHeaderJar := filepath.Join("out", "soong", ".intermediates", "foo", "android_common", "turbine-combined", "foo.jar") + fooHeaderJar := filepath.Join("out", "soong", ".intermediates", "foo", "android_common", "turbine", "foo.jar") barTurbineJar := filepath.Join("out", "soong", ".intermediates", "bar", "android_common", "turbine", "bar.jar") android.AssertStringDoesContain(t, "bar turbine classpath", barTurbine.Args["turbineFlags"], fooHeaderJar) android.AssertStringDoesContain(t, "bar javac classpath", barJavac.Args["classpath"], fooHeaderJar) @@ -1251,16 +1232,18 @@ func TestJavaImport(t *testing.T) { source := ctx.ModuleForTests(t, "source_library", "android_common") sourceJar := source.Output("javac/source_library.jar") - sourceHeaderJar := source.Output("turbine-combined/source_library.jar") + sourceHeaderJar := source.Output("turbine/source_library.jar") + sourceCombinedHeaderJar := source.Output("turbine-combined/source_library.jar") sourceJavaInfo, _ := android.OtherModuleProvider(ctx, source.Module(), JavaInfoProvider) // The source library produces separate implementation and header jars android.AssertPathsRelativeToTopEquals(t, "source library implementation jar", []string{sourceJar.Output.String()}, sourceJavaInfo.ImplementationAndResourcesJars) android.AssertPathsRelativeToTopEquals(t, "source library header jar", - []string{sourceHeaderJar.Output.String()}, sourceJavaInfo.HeaderJars) + []string{sourceCombinedHeaderJar.Output.String()}, sourceJavaInfo.HeaderJars) importWithNoDeps := ctx.ModuleForTests(t, "import_with_no_deps", "android_common") + importWithNoDepsLocalJar := importWithNoDeps.Output("local-combined/import_with_no_deps.jar") importWithNoDepsJar := importWithNoDeps.Output("combined/import_with_no_deps.jar") importWithNoDepsJavaInfo, _ := android.OtherModuleProvider(ctx, importWithNoDeps.Module(), JavaInfoProvider) @@ -1270,10 +1253,14 @@ func TestJavaImport(t *testing.T) { android.AssertPathsRelativeToTopEquals(t, "import with no deps header jar", []string{importWithNoDepsJar.Output.String()}, importWithNoDepsJavaInfo.HeaderJars) android.AssertPathsRelativeToTopEquals(t, "import with no deps combined inputs", - []string{"no_deps.jar"}, importWithNoDepsJar.Inputs) + []string{importWithNoDepsLocalJar.Output.String()}, importWithNoDepsJar.Inputs) + android.AssertPathsRelativeToTopEquals(t, "import with no deps local combined inputs", + []string{"no_deps.jar"}, importWithNoDepsLocalJar.Inputs) importWithSourceDeps := ctx.ModuleForTests(t, "import_with_source_deps", "android_common") + importWithSourceDepsLocalJar := importWithSourceDeps.Output("local-combined/import_with_source_deps.jar") importWithSourceDepsJar := importWithSourceDeps.Output("combined/import_with_source_deps.jar") + importWithSourceDepsLocalHeaderJar := importWithSourceDeps.Output("local-combined/import_with_source_deps.jar") importWithSourceDepsHeaderJar := importWithSourceDeps.Output("turbine-combined/import_with_source_deps.jar") importWithSourceDepsJavaInfo, _ := android.OtherModuleProvider(ctx, importWithSourceDeps.Module(), JavaInfoProvider) @@ -1283,11 +1270,16 @@ func TestJavaImport(t *testing.T) { android.AssertPathsRelativeToTopEquals(t, "import with source deps header jar", []string{importWithSourceDepsHeaderJar.Output.String()}, importWithSourceDepsJavaInfo.HeaderJars) android.AssertPathsRelativeToTopEquals(t, "import with source deps combined implementation jar inputs", - []string{"source_deps.jar", sourceJar.Output.String()}, importWithSourceDepsJar.Inputs) + []string{importWithSourceDepsLocalJar.Output.String(), sourceJar.Output.String()}, importWithSourceDepsJar.Inputs) android.AssertPathsRelativeToTopEquals(t, "import with source deps combined header jar inputs", - []string{"source_deps.jar", sourceHeaderJar.Output.String()}, importWithSourceDepsHeaderJar.Inputs) + []string{importWithSourceDepsLocalHeaderJar.Output.String(), sourceHeaderJar.Output.String()}, importWithSourceDepsHeaderJar.Inputs) + android.AssertPathsRelativeToTopEquals(t, "import with source deps local combined implementation jar inputs", + []string{"source_deps.jar"}, importWithSourceDepsLocalJar.Inputs) + android.AssertPathsRelativeToTopEquals(t, "import with source deps local combined header jar inputs", + []string{"source_deps.jar"}, importWithSourceDepsLocalHeaderJar.Inputs) importWithImportDeps := ctx.ModuleForTests(t, "import_with_import_deps", "android_common") + importWithImportDepsLocalJar := importWithImportDeps.Output("local-combined/import_with_import_deps.jar") importWithImportDepsJar := importWithImportDeps.Output("combined/import_with_import_deps.jar") importWithImportDepsJavaInfo, _ := android.OtherModuleProvider(ctx, importWithImportDeps.Module(), JavaInfoProvider) @@ -1297,7 +1289,9 @@ func TestJavaImport(t *testing.T) { android.AssertPathsRelativeToTopEquals(t, "import with import deps header jar", []string{importWithImportDepsJar.Output.String()}, importWithImportDepsJavaInfo.HeaderJars) android.AssertPathsRelativeToTopEquals(t, "import with import deps combined implementation jar inputs", - []string{"import_deps.jar", importWithNoDepsJar.Output.String()}, importWithImportDepsJar.Inputs) + []string{importWithImportDepsLocalJar.Output.String(), importWithNoDepsLocalJar.Output.String()}, importWithImportDepsJar.Inputs) + android.AssertPathsRelativeToTopEquals(t, "import with import deps local combined implementation jar inputs", + []string{"import_deps.jar"}, importWithImportDepsLocalJar.Inputs) } var compilerFlagsTestCases = []struct { @@ -1364,6 +1358,7 @@ func TestCompilerFlags(t *testing.T) { // TODO(jungjw): Consider making this more robust by ignoring path order. func checkPatchModuleFlag(t *testing.T, ctx *android.TestContext, moduleName string, expected string) { + t.Helper() variables := ctx.ModuleForTests(t, moduleName, "android_common").VariablesForTestsRelativeToTop() flags := strings.Split(variables["javacFlags"], " ") got := "" @@ -3107,7 +3102,6 @@ func TestCoverage(t *testing.T) { result := android.GroupFixturePreparers( PrepareForTestWithJavaDefaultModules, prepareForTestWithFrameworkJacocoInstrumentation, - PrepareForTestWithTransitiveClasspathEnabled, ).RunTestWithBp(t, ` android_app { name: "foo", diff --git a/java/jdeps.go b/java/jdeps.go index 927c1694d..07f8c4378 100644 --- a/java/jdeps.go +++ b/java/jdeps.go @@ -99,7 +99,7 @@ func (j *jdepsGeneratorSingleton) GenerateBuildActions(ctx android.SingletonCont Rule: android.Touch, Output: jfpath, }) - ctx.DistForGoal("general-tests", j.outputPath) + ctx.DistForGoals([]string{"general-tests", "dist_files"}, j.outputPath) } func createJsonFile(moduleInfos map[string]android.IdeInfo, jfpath android.WritablePath) error { diff --git a/java/kotlin_test.go b/java/kotlin_test.go index c7b1ece98..4b56cff1c 100644 --- a/java/kotlin_test.go +++ b/java/kotlin_test.go @@ -50,13 +50,6 @@ func TestKotlin(t *testing.T) { srcs: ["d.kt"], }` - kotlinStdlibTurbineCombinedJars := []string{ - "out/soong/.intermediates/default/java/kotlin-stdlib/android_common/turbine-combined/kotlin-stdlib.jar", - "out/soong/.intermediates/default/java/kotlin-stdlib-jdk7/android_common/turbine-combined/kotlin-stdlib-jdk7.jar", - "out/soong/.intermediates/default/java/kotlin-stdlib-jdk8/android_common/turbine-combined/kotlin-stdlib-jdk8.jar", - "out/soong/.intermediates/default/java/kotlin-annotations/android_common/turbine-combined/kotlin-annotations.jar", - } - kotlinStdlibTurbineJars := []string{ "out/soong/.intermediates/default/java/kotlin-stdlib/android_common/turbine/kotlin-stdlib.jar", "out/soong/.intermediates/default/java/kotlin-stdlib-jdk7/android_common/turbine/kotlin-stdlib-jdk7.jar", @@ -71,21 +64,11 @@ func TestKotlin(t *testing.T) { "out/soong/.intermediates/default/java/kotlin-annotations/android_common/javac/kotlin-annotations.jar", } - bootclasspathTurbineCombinedJars := []string{ - "out/soong/.intermediates/default/java/stable.core.platform.api.stubs/android_common/turbine-combined/stable.core.platform.api.stubs.jar", - "out/soong/.intermediates/default/java/core-lambda-stubs/android_common/turbine-combined/core-lambda-stubs.jar", - } - bootclasspathTurbineJars := []string{ "out/soong/.intermediates/default/java/stable.core.platform.api.stubs/android_common/turbine/stable.core.platform.api.stubs.jar", "out/soong/.intermediates/default/java/core-lambda-stubs/android_common/turbine/core-lambda-stubs.jar", } - frameworkTurbineCombinedJars := []string{ - "out/soong/.intermediates/default/java/ext/android_common/turbine-combined/ext.jar", - "out/soong/.intermediates/default/java/framework/android_common/turbine-combined/framework.jar", - } - frameworkTurbineJars := []string{ "out/soong/.intermediates/default/java/ext/android_common/turbine/ext.jar", "out/soong/.intermediates/default/java/framework/android_common/turbine/framework.jar", @@ -109,68 +92,8 @@ func TestKotlin(t *testing.T) { barHeaderCombinedInputs []string }{ { - name: "normal", - preparer: android.NullFixturePreparer, - fooKotlincInputs: []string{"a.java", "b.kt"}, - fooJavacInputs: []string{"a.java"}, - fooKotlincClasspath: slices.Concat( - bootclasspathTurbineCombinedJars, - frameworkTurbineCombinedJars, - []string{"out/soong/.intermediates/quz/android_common/turbine-combined/quz.jar"}, - kotlinStdlibTurbineCombinedJars, - ), - fooJavacClasspath: slices.Concat( - []string{"out/soong/.intermediates/foo/android_common/kotlin_headers/foo.jar"}, - frameworkTurbineCombinedJars, - []string{"out/soong/.intermediates/quz/android_common/turbine-combined/quz.jar"}, - kotlinStdlibTurbineCombinedJars, - ), - fooCombinedInputs: slices.Concat( - []string{ - "out/soong/.intermediates/foo/android_common/kotlin/foo.jar", - "out/soong/.intermediates/foo/android_common/javac/foo.jar", - "out/soong/.intermediates/quz/android_common/combined/quz.jar", - }, - kotlinStdlibJavacJars, - ), - fooHeaderCombinedInputs: slices.Concat( - []string{ - "out/soong/.intermediates/foo/android_common/turbine/foo.jar", - "out/soong/.intermediates/foo/android_common/kotlin_headers/foo.jar", - "out/soong/.intermediates/quz/android_common/turbine-combined/quz.jar", - }, - kotlinStdlibTurbineCombinedJars, - ), - - barKotlincInputs: []string{"b.kt"}, - barKotlincClasspath: slices.Concat( - bootclasspathTurbineCombinedJars, - frameworkTurbineCombinedJars, - []string{ - "out/soong/.intermediates/foo/android_common/turbine-combined/foo.jar", - "out/soong/.intermediates/baz/android_common/turbine-combined/baz.jar", - }, - kotlinStdlibTurbineCombinedJars, - ), - barCombinedInputs: slices.Concat( - []string{ - "out/soong/.intermediates/bar/android_common/kotlin/bar.jar", - "out/soong/.intermediates/baz/android_common/combined/baz.jar", - }, - kotlinStdlibJavacJars, - []string{}, - ), - barHeaderCombinedInputs: slices.Concat( - []string{ - "out/soong/.intermediates/bar/android_common/kotlin_headers/bar.jar", - "out/soong/.intermediates/baz/android_common/turbine-combined/baz.jar", - }, - kotlinStdlibTurbineCombinedJars, - ), - }, - { name: "transitive classpath", - preparer: PrepareForTestWithTransitiveClasspathEnabled, + preparer: android.NullFixturePreparer, fooKotlincInputs: []string{"a.java", "b.kt"}, fooJavacInputs: []string{"a.java"}, fooKotlincClasspath: slices.Concat( diff --git a/java/lint.go b/java/lint.go index 66f7f8549..c31dfd005 100644 --- a/java/lint.go +++ b/java/lint.go @@ -595,12 +595,12 @@ func (l *lintSingleton) GenerateBuildActions(ctx android.SingletonContext) { l.copyLintDependencies(ctx) } -func findModuleOrErr(ctx android.SingletonContext, moduleName string) android.Module { - var res android.Module - ctx.VisitAllModules(func(m android.Module) { +func findModuleOrErr(ctx android.SingletonContext, moduleName string) *android.ModuleProxy { + var res *android.ModuleProxy + ctx.VisitAllModuleProxies(func(m android.ModuleProxy) { if ctx.ModuleName(m) == moduleName { if res == nil { - res = m + res = &m } else { ctx.Errorf("lint: multiple %s modules found: %s and %s", moduleName, ctx.ModuleSubDir(m), ctx.ModuleSubDir(res)) @@ -635,13 +635,13 @@ func (l *lintSingleton) copyLintDependencies(ctx android.SingletonContext) { ctx.Build(pctx, android.BuildParams{ Rule: android.CpIfChanged, - Input: android.OutputFileForModule(ctx, sdkAnnotations, ""), + Input: android.OutputFileForModule(ctx, *sdkAnnotations, ""), Output: copiedLintDatabaseFilesPath(ctx, files.annotationCopiedName), }) ctx.Build(pctx, android.BuildParams{ Rule: android.CpIfChanged, - Input: android.OutputFileForModule(ctx, apiVersionsDb, ".api_versions.xml"), + Input: android.OutputFileForModule(ctx, *apiVersionsDb, ".api_versions.xml"), Output: copiedLintDatabaseFilesPath(ctx, files.apiVersionsCopiedName), }) } @@ -658,12 +658,13 @@ func (l *lintSingleton) generateLintReportZips(ctx android.SingletonContext) { var outputs []*LintInfo var dirs []string - ctx.VisitAllModules(func(m android.Module) { - if ctx.Config().KatiEnabled() && !m.ExportedToMake() { + ctx.VisitAllModuleProxies(func(m android.ModuleProxy) { + commonInfo, _ := android.OtherModuleProvider(ctx, m, android.CommonModuleInfoKey) + if ctx.Config().KatiEnabled() && !commonInfo.ExportedToMake { return } - if apex, ok := m.(android.ApexModule); ok && apex.NotAvailableForPlatform() { + if commonInfo.IsApexModule && commonInfo.NotAvailableForPlatform { apexInfo, _ := android.OtherModuleProvider(ctx, m, android.ApexInfoProvider) if apexInfo.IsForPlatform() { // There are stray platform variants of modules in apexes that are not available for diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index 363521a7f..ab4f8f81f 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -99,6 +99,14 @@ type platformCompatConfigMetadataProvider interface { includeInMergedXml() bool } +type PlatformCompatConfigMetadataInfo struct { + CompatConfigMetadata android.Path + // Whether to include it in the "merged" XML (merged_compat_config.xml) or not. + IncludeInMergedXml bool +} + +var PlatformCompatConfigMetadataInfoProvider = blueprint.NewProvider[PlatformCompatConfigMetadataInfo]() + type PlatformCompatConfigIntf interface { android.Module @@ -136,6 +144,11 @@ func (p *platformCompatConfig) GenerateAndroidBuildActions(ctx android.ModuleCon CompatConfig: p.CompatConfig(), SubDir: p.SubDir(), }) + + android.SetProvider(ctx, PlatformCompatConfigMetadataInfoProvider, PlatformCompatConfigMetadataInfo{ + CompatConfigMetadata: p.compatConfigMetadata(), + IncludeInMergedXml: p.includeInMergedXml(), + }) } func (p *platformCompatConfig) AndroidMkEntries() []android.AndroidMkEntries { @@ -238,6 +251,11 @@ var _ platformCompatConfigMetadataProvider = (*prebuiltCompatConfigModule)(nil) func (module *prebuiltCompatConfigModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { module.metadataFile = module.prebuilt.SingleSourcePath(ctx) + + android.SetProvider(ctx, PlatformCompatConfigMetadataInfoProvider, PlatformCompatConfigMetadataInfo{ + CompatConfigMetadata: module.compatConfigMetadata(), + IncludeInMergedXml: module.includeInMergedXml(), + }) } // A prebuilt version of platform_compat_config that provides the metadata. @@ -258,18 +276,18 @@ func (p *platformCompatConfigSingleton) GenerateBuildActions(ctx android.Singlet var compatConfigMetadata android.Paths - ctx.VisitAllModules(func(module android.Module) { - if !module.Enabled(ctx) { + ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { + if !android.OtherModuleProviderOrDefault(ctx, module, android.CommonModuleInfoKey).Enabled { return } - if c, ok := module.(platformCompatConfigMetadataProvider); ok { - if !android.IsModulePreferred(module) { + if c, ok := android.OtherModuleProvider(ctx, module, PlatformCompatConfigMetadataInfoProvider); ok { + if !android.IsModulePreferredProxy(ctx, module) { return } - if !c.includeInMergedXml() { + if !c.IncludeInMergedXml { return } - metadata := c.compatConfigMetadata() + metadata := c.CompatConfigMetadata compatConfigMetadata = append(compatConfigMetadata, metadata) } }) diff --git a/java/ravenwood.go b/java/ravenwood.go index 3b6c80bc6..c4078c587 100644 --- a/java/ravenwood.go +++ b/java/ravenwood.go @@ -267,6 +267,10 @@ func (r *ravenwoodTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { moduleInfoJSON.TestConfig = append(moduleInfoJSON.TestConfig, r.testConfig.String()) } moduleInfoJSON.CompatibilitySuites = []string{"general-tests", "ravenwood-tests"} + + android.SetProvider(ctx, android.TestSuiteInfoProvider, android.TestSuiteInfo{ + TestSuites: r.TestSuites(), + }) } func (r *ravenwoodTest) AndroidMkEntries() []android.AndroidMkEntries { @@ -384,6 +388,10 @@ func (r *ravenwoodLibgroup) GenerateAndroidBuildActions(ctx android.ModuleContex // Normal build should perform install steps ctx.Phony(r.BaseModuleName(), android.PathForPhony(ctx, r.BaseModuleName()+"-install")) + + android.SetProvider(ctx, android.TestSuiteInfoProvider, android.TestSuiteInfo{ + TestSuites: r.TestSuites(), + }) } // collectTransitiveJniDeps returns all JNI dependencies, including transitive diff --git a/java/robolectric.go b/java/robolectric.go index 43e17f9ea..be369f780 100644 --- a/java/robolectric.go +++ b/java/robolectric.go @@ -168,6 +168,7 @@ func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext) r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Device_common_data)...) r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Device_first_data)...) r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Device_first_prefer32_data)...) + r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Host_common_data)...) var ok bool var instrumentedApp *JavaInfo @@ -279,6 +280,10 @@ func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext) } else { moduleInfoJSON.CompatibilitySuites = append(moduleInfoJSON.CompatibilitySuites, "null-suite") } + + android.SetProvider(ctx, android.TestSuiteInfoProvider, android.TestSuiteInfo{ + TestSuites: r.TestSuites(), + }) } func generateSameDirRoboTestConfigJar(ctx android.ModuleContext, outputFile android.ModuleOutPath) { @@ -416,6 +421,10 @@ func (r *robolectricRuntimes) GenerateAndroidBuildActions(ctx android.ModuleCont android.SetProvider(ctx, RobolectricRuntimesInfoProvider, RobolectricRuntimesInfo{ Runtimes: r.runtimes, }) + + android.SetProvider(ctx, android.TestSuiteInfoProvider, android.TestSuiteInfo{ + TestSuites: r.TestSuites(), + }) } func (r *robolectricRuntimes) InstallInTestcases() bool { return true } diff --git a/java/sdk.go b/java/sdk.go index 27b2434c5..ab1c653d1 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -274,7 +274,7 @@ func createNonUpdatableFrameworkAidl(ctx android.SingletonContext) { func createFrameworkAidl(stubsModules []string, path android.WritablePath, ctx android.SingletonContext) *android.RuleBuilder { stubsJars := make([]android.Paths, len(stubsModules)) - ctx.VisitAllModules(func(module android.Module) { + ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { // Collect dex jar paths for the modules listed above. if j, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok { name := ctx.ModuleName(module) @@ -358,7 +358,7 @@ func createAPIFingerprint(ctx android.SingletonContext) { "api_fingerprint", } count := 0 - ctx.VisitAllModules(func(module android.Module) { + ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { name := ctx.ModuleName(module) if android.InList(name, apiTxtFileModules) { cmd.Inputs(android.OutputFilesForModule(ctx, module, "")) diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go index 2cb827dc2..6d27e54d0 100644 --- a/java/sdk_library_test.go +++ b/java/sdk_library_test.go @@ -149,7 +149,7 @@ func TestJavaSdkLibrary(t *testing.T) { bazJavac := result.ModuleForTests(t, "baz", "android_common").Rule("javac") // tests if baz is actually linked to the stubs lib - android.AssertStringDoesContain(t, "baz javac classpath", bazJavac.Args["classpath"], "foo.stubs.system.jar") + android.AssertStringDoesContain(t, "baz javac classpath", bazJavac.Args["classpath"], "foo.stubs.system.from-text.jar") // ... and not to the impl lib android.AssertStringDoesNotContain(t, "baz javac classpath", bazJavac.Args["classpath"], "foo.jar") // test if baz is not linked to the system variant of foo @@ -157,15 +157,15 @@ func TestJavaSdkLibrary(t *testing.T) { bazTestJavac := result.ModuleForTests(t, "baz-test", "android_common").Rule("javac") // tests if baz-test is actually linked to the test stubs lib - android.AssertStringDoesContain(t, "baz-test javac classpath", bazTestJavac.Args["classpath"], "foo.stubs.test.jar") + android.AssertStringDoesContain(t, "baz-test javac classpath", bazTestJavac.Args["classpath"], "foo.stubs.test.from-text.jar") baz29Javac := result.ModuleForTests(t, "baz-29", "android_common").Rule("javac") // tests if baz-29 is actually linked to the system 29 stubs lib - android.AssertStringDoesContain(t, "baz-29 javac classpath", baz29Javac.Args["classpath"], "prebuilts/sdk/sdk_system_29_foo/android_common/combined/sdk_system_29_foo.jar") + android.AssertStringDoesContain(t, "baz-29 javac classpath", baz29Javac.Args["classpath"], "prebuilts/sdk/sdk_system_29_foo/android_common/local-combined/sdk_system_29_foo.jar") bazModule30Javac := result.ModuleForTests(t, "baz-module-30", "android_common").Rule("javac") // tests if "baz-module-30" is actually linked to the module 30 stubs lib - android.AssertStringDoesContain(t, "baz-module-30 javac classpath", bazModule30Javac.Args["classpath"], "prebuilts/sdk/sdk_module-lib_30_foo/android_common/combined/sdk_module-lib_30_foo.jar") + android.AssertStringDoesContain(t, "baz-module-30 javac classpath", bazModule30Javac.Args["classpath"], "prebuilts/sdk/sdk_module-lib_30_foo/android_common/local-combined/sdk_module-lib_30_foo.jar") // test if baz has exported SDK lib names foo and bar to qux qux := result.ModuleForTests(t, "qux", "android_common") @@ -422,7 +422,7 @@ func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) { android.AssertStringContainsEquals(t, "bad classpath for "+sdklib, sdklibCp, "/"+dep+".jar", expected) combineJarInputs := result.ModuleForTests(t, sdklib, "android_common").Rule("combineJar").Inputs.Strings() - depPath := filepath.Join("out", "soong", ".intermediates", dep, "android_common", "turbine-combined", dep+".jar") + depPath := filepath.Join("out", "soong", ".intermediates", dep, "android_common", "turbine", dep+".jar") android.AssertStringListContainsEquals(t, "bad combined inputs for "+sdklib, combineJarInputs, depPath, combined) } for _, expectation := range expectations { @@ -458,7 +458,7 @@ func TestJavaSdkLibrary_DoNotAccessImplWhenItIsNotBuilt(t *testing.T) { // The bar library should depend on the stubs jar. barLibrary := result.ModuleForTests(t, "bar", "android_common").Rule("javac") - if expected, actual := `^-classpath .*:out/soong/[^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { + if expected, actual := `^-classpath .*:out/soong/[^:]*/foo\.stubs\.from-text/foo\.stubs\.from-text\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { t.Errorf("expected %q, found %#q", expected, actual) } } @@ -494,7 +494,7 @@ func TestJavaSdkLibrary_AccessOutputFiles_NoAnnotations(t *testing.T) { PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("foo"), ). - ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "bar" variant "android_common": unsupported module reference tag ".public.annotations.zip"`)). + ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "bar" variant "android_common": unsupported output tag ".public.annotations.zip"`)). RunTestWithBp(t, ` java_sdk_library { name: "foo", @@ -520,7 +520,7 @@ func TestJavaSdkLibrary_AccessOutputFiles_MissingScope(t *testing.T) { PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("foo"), ). - ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "bar" variant "android_common": unsupported module reference tag ".system.stubs.source"`)). + ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "bar" variant "android_common": unsupported output tag ".system.stubs.source"`)). RunTestWithBp(t, ` java_sdk_library { name: "foo", @@ -791,7 +791,7 @@ func TestJavaSdkLibrary_SystemServer_AccessToStubScopeLibs(t *testing.T) { stubsPath := func(name string, scope *apiScope) string { name = scope.stubsLibraryModuleName(name) - return fmt.Sprintf("out/soong/.intermediates/%[1]s/android_common/turbine-combined/%[1]s.jar", name) + return fmt.Sprintf("out/soong/.intermediates/%[1]s.from-text/android_common/%[1]s.from-text/%[1]s.from-text.jar", name) } // The bar library should depend on the highest (where system server is highest and public is @@ -853,7 +853,7 @@ func TestJavaSdkLibraryImport(t *testing.T) { fooModule := result.ModuleForTests(t, "foo"+scope, "android_common") javac := fooModule.Rule("javac") - sdklibStubsJar := result.ModuleForTests(t, "sdklib.stubs"+scope, "android_common").Output("combined/sdklib.stubs" + scope + ".jar").Output + sdklibStubsJar := result.ModuleForTests(t, "sdklib.stubs"+scope, "android_common").Output("local-combined/sdklib.stubs" + scope + ".jar").Output android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], sdklibStubsJar.String()) } @@ -1002,7 +1002,7 @@ func testJavaSdkLibraryImport_Preferred(t *testing.T, prefer string, preparer an public := result.ModuleForTests(t, "public", "android_common") rule := public.Output("javac/public.jar") inputs := rule.Implicits.Strings() - expected := "out/soong/.intermediates/prebuilt_sdklib.stubs/android_common/combined/sdklib.stubs.jar" + expected := "out/soong/.intermediates/prebuilt_sdklib.stubs/android_common/local-combined/sdklib.stubs.jar" if !android.InList(expected, inputs) { t.Errorf("expected %q to contain %q", inputs, expected) } @@ -1124,12 +1124,12 @@ func TestSdkLibraryImport_MetadataModuleSupersedesPreferred(t *testing.T) { inputs := rule.Implicits.Strings() expectedInputs := []string{ // source - "out/soong/.intermediates/sdklib.prebuilt_preferred_using_legacy_flags.stubs/android_common/turbine-combined/sdklib.prebuilt_preferred_using_legacy_flags.stubs.jar", - "out/soong/.intermediates/sdklib.prebuilt_preferred_using_legacy_flags.stubs.system/android_common/turbine-combined/sdklib.prebuilt_preferred_using_legacy_flags.stubs.system.jar", + "out/soong/.intermediates/sdklib.prebuilt_preferred_using_legacy_flags.stubs.from-text/android_common/sdklib.prebuilt_preferred_using_legacy_flags.stubs.from-text/sdklib.prebuilt_preferred_using_legacy_flags.stubs.from-text.jar", + "out/soong/.intermediates/sdklib.prebuilt_preferred_using_legacy_flags.stubs.system.from-text/android_common/sdklib.prebuilt_preferred_using_legacy_flags.stubs.system.from-text/sdklib.prebuilt_preferred_using_legacy_flags.stubs.system.from-text.jar", // prebuilt - "out/soong/.intermediates/prebuilt_sdklib.source_preferred_using_legacy_flags.stubs/android_common/combined/sdklib.source_preferred_using_legacy_flags.stubs.jar", - "out/soong/.intermediates/prebuilt_sdklib.source_preferred_using_legacy_flags.stubs.system/android_common/combined/sdklib.source_preferred_using_legacy_flags.stubs.system.jar", + "out/soong/.intermediates/prebuilt_sdklib.source_preferred_using_legacy_flags.stubs/android_common/local-combined/sdklib.source_preferred_using_legacy_flags.stubs.jar", + "out/soong/.intermediates/prebuilt_sdklib.source_preferred_using_legacy_flags.stubs.system/android_common/local-combined/sdklib.source_preferred_using_legacy_flags.stubs.system.jar", } for _, expected := range expectedInputs { if !android.InList(expected, inputs) { @@ -1578,7 +1578,8 @@ func TestStubResolutionOfJavaSdkLibraryInLibs(t *testing.T) { public := result.ModuleForTests(t, "mymodule", "android_common") rule := public.Output("javac/mymodule.jar") inputs := rule.Implicits.Strings() - android.AssertStringListContains(t, "Could not find the expected stub on classpath", inputs, "out/soong/.intermediates/sdklib.stubs/android_common/turbine-combined/sdklib.stubs.jar") + android.AssertStringListContains(t, "Could not find the expected stub on classpath", inputs, + "out/soong/.intermediates/sdklib.stubs.from-text/android_common/sdklib.stubs.from-text/sdklib.stubs.from-text.jar") } // test that rdep gets resolved to the correct version of a java_sdk_library (source or a specific prebuilt) @@ -1636,17 +1637,17 @@ func TestMultipleSdkLibraryPrebuilts(t *testing.T) { { desc: "Source library is selected using apex_contributions", selectedDependencyName: "sdklib", - expectedStubPath: "out/soong/.intermediates/sdklib.stubs/android_common/turbine-combined/sdklib.stubs.jar", + expectedStubPath: "out/soong/.intermediates/sdklib.stubs.from-text/android_common/sdklib.stubs.from-text/sdklib.stubs.from-text.jar", }, { desc: "Prebuilt library v1 is selected using apex_contributions", selectedDependencyName: "prebuilt_sdklib.v1", - expectedStubPath: "out/soong/.intermediates/prebuilt_sdklib.v1.stubs/android_common/combined/sdklib.stubs.jar", + expectedStubPath: "out/soong/.intermediates/prebuilt_sdklib.v1.stubs/android_common/local-combined/sdklib.stubs.jar", }, { desc: "Prebuilt library v2 is selected using apex_contributions", selectedDependencyName: "prebuilt_sdklib.v2", - expectedStubPath: "out/soong/.intermediates/prebuilt_sdklib.v2.stubs/android_common/combined/sdklib.stubs.jar", + expectedStubPath: "out/soong/.intermediates/prebuilt_sdklib.v2.stubs/android_common/local-combined/sdklib.stubs.jar", }, } diff --git a/java/sdk_test.go b/java/sdk_test.go index 49983ada2..6386a00d5 100644 --- a/java/sdk_test.go +++ b/java/sdk_test.go @@ -391,21 +391,16 @@ func TestClasspath(t *testing.T) { t.Run("basic", func(t *testing.T) { t.Parallel() - testClasspathTestCases(t, classpathTestcases, false, false) + testClasspathTestCases(t, classpathTestcases, false) }) t.Run("Always_use_prebuilt_sdks=true", func(t *testing.T) { t.Parallel() - testClasspathTestCases(t, classpathTestcases, true, false) - }) - - t.Run("UseTransitiveJarsInClasspath", func(t *testing.T) { - t.Parallel() - testClasspathTestCases(t, classpathTestcases, false, true) + testClasspathTestCases(t, classpathTestcases, true) }) } -func testClasspathTestCases(t *testing.T, classpathTestcases []classpathTestCase, alwaysUsePrebuiltSdks, useTransitiveJarsInClasspath bool) { +func testClasspathTestCases(t *testing.T, classpathTestcases []classpathTestCase, alwaysUsePrebuiltSdks bool) { for _, testcase := range classpathTestcases { if testcase.forAlwaysUsePrebuiltSdks != nil && *testcase.forAlwaysUsePrebuiltSdks != alwaysUsePrebuiltSdks { continue @@ -446,10 +441,8 @@ func testClasspathTestCases(t *testing.T, classpathTestcases []classpathTestCase switch { case e == `""`, strings.HasSuffix(e, ".jar"): ret[i] = e - case useTransitiveJarsInClasspath: - ret[i] = filepath.Join("out", "soong", ".intermediates", defaultJavaDir, e, "android_common", "turbine", e+".jar") default: - ret[i] = filepath.Join("out", "soong", ".intermediates", defaultJavaDir, e, "android_common", "turbine-combined", e+".jar") + ret[i] = filepath.Join("out", "soong", ".intermediates", defaultJavaDir, e, "android_common", "turbine", e+".jar") } } return ret @@ -544,9 +537,6 @@ func testClasspathTestCases(t *testing.T, classpathTestcases []classpathTestCase variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) }) } - if useTransitiveJarsInClasspath { - preparer = PrepareForTestWithTransitiveClasspathEnabled - } fixtureFactory := android.GroupFixturePreparers( prepareForJavaTest, diff --git a/java/support_libraries.go b/java/support_libraries.go index c483fc17a..f76eb116e 100644 --- a/java/support_libraries.go +++ b/java/support_libraries.go @@ -28,7 +28,7 @@ func init() { func supportLibrariesMakeVarsProvider(ctx android.MakeVarsContext) { var supportAars, supportJars []string - ctx.VisitAllModules(func(module android.Module) { + ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { dir := ctx.ModuleDir(module) switch { case strings.HasPrefix(dir, "prebuilts/sdk/current/extras"), @@ -47,11 +47,16 @@ func supportLibrariesMakeVarsProvider(ctx android.MakeVarsContext) { return } - switch module.(type) { - case *AndroidLibrary, *AARImport: + _, isAndroidLibrary := android.OtherModuleProvider(ctx, module, AndroidLibraryInfoProvider) + _, isAARImport := android.OtherModuleProvider(ctx, module, AARImportInfoProvider) + if isAndroidLibrary || isAARImport { supportAars = append(supportAars, name) - case *Library, *Import: - supportJars = append(supportJars, name) + } else { + _, isJavaLibrary := android.OtherModuleProvider(ctx, module, JavaLibraryInfoProvider) + _, isJavaPlugin := android.OtherModuleProvider(ctx, module, JavaPluginInfoProvider) + if isJavaLibrary && !isJavaPlugin { + supportJars = append(supportJars, name) + } } }) diff --git a/java/testing.go b/java/testing.go index 35319ae58..3abbb8453 100644 --- a/java/testing.go +++ b/java/testing.go @@ -825,5 +825,3 @@ func FixtureSetBootImageInstallDirOnDevice(name string, installDir string) andro config.installDir = installDir }) } - -var PrepareForTestWithTransitiveClasspathEnabled = android.PrepareForTestWithBuildFlag("RELEASE_USE_TRANSITIVE_JARS_IN_CLASSPATH", "true") diff --git a/rust/rust.go b/rust/rust.go index 4eebda301..d8a044423 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -60,6 +60,7 @@ type RustInfo struct { CompilerInfo *CompilerInfo SnapshotInfo *cc.SnapshotInfo SourceProviderInfo *SourceProviderInfo + XrefRustFiles android.Paths } var RustInfoProvider = blueprint.NewProvider[*RustInfo]() @@ -1171,6 +1172,7 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { AndroidMkSuffix: mod.AndroidMkSuffix(), RustSubName: mod.Properties.RustSubName, TransitiveAndroidMkSharedLibs: mod.transitiveAndroidMkSharedLibs, + XrefRustFiles: mod.XrefRustFiles(), } if mod.compiler != nil { rustInfo.CompilerInfo = &CompilerInfo{ @@ -2236,9 +2238,9 @@ type kytheExtractRustSingleton struct { func (k kytheExtractRustSingleton) GenerateBuildActions(ctx android.SingletonContext) { var xrefTargets android.Paths - ctx.VisitAllModules(func(module android.Module) { - if rustModule, ok := module.(xref); ok { - xrefTargets = append(xrefTargets, rustModule.XrefRustFiles()...) + ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { + if rustModule, ok := android.OtherModuleProvider(ctx, module, RustInfoProvider); ok { + xrefTargets = append(xrefTargets, rustModule.XrefRustFiles...) } }) if len(xrefTargets) > 0 { diff --git a/rust/test.go b/rust/test.go index 5c183bc67..9833ffdb6 100644 --- a/rust/test.go +++ b/rust/test.go @@ -46,9 +46,16 @@ type TestProperties struct { // the test Data []string `android:"path,arch_variant"` - // Same as data, but will add dependencies on the device's + // Same as data, but adds dependencies on modules using the device's os variant, and common + // architecture's variant. Can be useful to add device-built apps to the data of a host + // test. Device_common_data []string `android:"path_device_common"` + // Same as data, but will add dependencies on modules using the host's os variation and + // the common arch variation. Useful for a device test that wants to depend on a host + // module, for example to include a custom Tradefed test runner. + Host_common_data []string `android:"path_host_common"` + // list of shared library modules that should be installed alongside the test Data_libs []string `android:"arch_variant"` @@ -147,6 +154,7 @@ func (test *testDecorator) install(ctx ModuleContext) { dataSrcPaths := android.PathsForModuleSrc(ctx, test.Properties.Data) dataSrcPaths = append(dataSrcPaths, android.PathsForModuleSrc(ctx, test.Properties.Device_common_data)...) + dataSrcPaths = append(dataSrcPaths, android.PathsForModuleSrc(ctx, test.Properties.Host_common_data)...) ctx.VisitDirectDepsProxyWithTag(dataLibDepTag, func(dep android.ModuleProxy) { depName := ctx.OtherModuleName(dep) diff --git a/sdk/sdk.go b/sdk/sdk.go index aa82abbb4..ab50659cd 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -178,22 +178,24 @@ func (s *sdk) GenerateAndroidBuildActions(ctx android.ModuleContext) { s.buildSnapshot(ctx, sdkVariants) } + if s.snapshotFile.Valid() != s.infoFile.Valid() { + panic(fmt.Sprintf("Snapshot (%q) and info file (%q) should both be set or neither should be set.", s.snapshotFile, s.infoFile)) + } + if s.snapshotFile.Valid() { ctx.SetOutputFiles([]android.Path{s.snapshotFile.Path()}, "") + ctx.SetOutputFiles([]android.Path{s.snapshotFile.Path(), s.infoFile.Path()}, android.DefaultDistTag) } } func (s *sdk) AndroidMkEntries() []android.AndroidMkEntries { - if !s.snapshotFile.Valid() != !s.infoFile.Valid() { - panic("Snapshot (%q) and info file (%q) should both be set or neither should be set.") - } else if !s.snapshotFile.Valid() { + if !s.snapshotFile.Valid() { return []android.AndroidMkEntries{} } return []android.AndroidMkEntries{android.AndroidMkEntries{ Class: "FAKE", OutputFile: s.snapshotFile, - DistFiles: android.MakeDefaultDistFiles(s.snapshotFile.Path(), s.infoFile.Path()), Include: "$(BUILD_PHONY_PACKAGE)", ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { diff --git a/sh/sh_binary.go b/sh/sh_binary.go index c0c6ff2ae..f8d1ce523 100644 --- a/sh/sh_binary.go +++ b/sh/sh_binary.go @@ -138,6 +138,11 @@ type TestProperties struct { // host test. Device_first_data []string `android:"path_device_first"` + // Same as data, but will add dependencies on modules using the host's os variation and + // the common arch variation. Useful for a device test that wants to depend on a host + // module, for example to include a custom Tradefed test runner. + Host_common_data []string `android:"path_host_common"` + // Add RootTargetPreparer to auto generated test config. This guarantees the test to run // with root permission. Require_root *bool @@ -436,6 +441,7 @@ func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { expandedData := android.PathsForModuleSrc(ctx, s.testProperties.Data) expandedData = append(expandedData, android.PathsForModuleSrc(ctx, s.testProperties.Device_common_data)...) expandedData = append(expandedData, android.PathsForModuleSrc(ctx, s.testProperties.Device_first_data)...) + expandedData = append(expandedData, android.PathsForModuleSrc(ctx, s.testProperties.Host_common_data)...) // Emulate the data property for java_data dependencies. for _, javaData := range ctx.GetDirectDepsProxyWithTag(shTestJavaDataTag) { expandedData = append(expandedData, android.OutputFilesForModule(ctx, javaData, "")...) diff --git a/sysprop/sysprop_test.go b/sysprop/sysprop_test.go index 06c5e9c9c..b2cfaa7dc 100644 --- a/sysprop/sysprop_test.go +++ b/sysprop/sysprop_test.go @@ -339,7 +339,7 @@ func TestSyspropLibrary(t *testing.T) { // Java modules linking against system API should use public stub javaSystemApiClient := result.ModuleForTests(t, "java-platform", "android_common").Rule("javac") - syspropPlatformPublic := result.ModuleForTests(t, "sysprop-platform_public", "android_common").Description("for turbine") + syspropPlatformPublic := result.ModuleForTests(t, "sysprop-platform_public", "android_common").Description("turbine") if g, w := javaSystemApiClient.Implicits.Strings(), syspropPlatformPublic.Output.String(); !android.InList(w, g) { t.Errorf("system api client should use public stub %q, got %q", w, g) } diff --git a/zip/cmd/main.go b/zip/cmd/main.go index 831f6d421..37537ab8b 100644 --- a/zip/cmd/main.go +++ b/zip/cmd/main.go @@ -164,7 +164,6 @@ func main() { directories := flags.Bool("d", false, "include directories in zip") compLevel := flags.Int("L", 5, "deflate compression level (0-9)") emulateJar := flags.Bool("jar", false, "modify the resultant .zip to emulate the output of 'jar'") - sortEntries := flags.Bool("sort_entries", false, "sort the zip entries") writeIfChanged := flags.Bool("write_if_changed", false, "only update resultant .zip if it has changed") ignoreMissingFiles := flags.Bool("ignore_missing_files", false, "continue if a requested file does not exist") symlinks := flags.Bool("symlinks", true, "store symbolic links in zip instead of following them") @@ -229,7 +228,6 @@ func main() { FileArgs: fileArgsBuilder.FileArgs(), OutputFilePath: *out, EmulateJar: *emulateJar, - SortEntries: *sortEntries, SrcJar: *srcJar, AddDirectoryEntriesToZip: *directories, CompressionLevel: *compLevel, diff --git a/zip/zip.go b/zip/zip.go index e4e9585d5..22b770474 100644 --- a/zip/zip.go +++ b/zip/zip.go @@ -272,7 +272,6 @@ type ZipArgs struct { FileArgs []FileArg OutputFilePath string EmulateJar bool - SortEntries bool SrcJar bool AddDirectoryEntriesToZip bool CompressionLevel int @@ -395,7 +394,7 @@ func zipTo(args ZipArgs, w io.Writer) error { } } - return z.write(w, pathMappings, args.ManifestSourcePath, args.EmulateJar, args.SortEntries, args.SrcJar, args.NumParallelJobs) + return z.write(w, pathMappings, args.ManifestSourcePath, args.EmulateJar, args.SrcJar, args.NumParallelJobs) } // Zip creates an output zip archive from given sources. @@ -476,6 +475,42 @@ func fillPathPairs(fa FileArg, src string, pathMappings *[]pathMapping, return nil } +func (z *ZipWriter) moveJavaFileBasedOnPackage(mapping *pathMapping) error { + src := mapping.src + var s os.FileInfo + var err error + if z.followSymlinks { + s, err = z.fs.Stat(src) + } else { + s, err = z.fs.Lstat(src) + } + if err != nil { + if os.IsNotExist(err) && z.ignoreMissingFiles { + return nil + } + return err + } + if !s.Mode().IsRegular() { + return nil + } + r, err := z.fs.Open(src) + if err != nil { + return err + } + // rewrite the destination using the package path if it can be determined + pkg, err := jar.JavaPackage(r, src) + err2 := r.Close() + if err2 != nil { + return err2 + } + if err != nil { + // ignore errors for now, leaving the file at in its original location in the zip + } else { + mapping.dest = filepath.Join(filepath.Join(strings.Split(pkg, ".")...), filepath.Base(src)) + } + return nil +} + func jarSort(mappings []pathMapping) { sort.SliceStable(mappings, func(i int, j int) bool { return jar.EntryNamesLess(mappings[i].dest, mappings[j].dest) @@ -483,7 +518,7 @@ func jarSort(mappings []pathMapping) { } func (z *ZipWriter) write(f io.Writer, pathMappings []pathMapping, manifest string, - emulateJar, sortEntries, srcJar bool, + emulateJar, srcJar bool, parallelJobs int) error { z.errors = make(chan error) @@ -513,16 +548,38 @@ func (z *ZipWriter) write(f io.Writer, pathMappings []pathMapping, manifest stri return errors.New("must specify --jar when specifying a manifest via -m") } - if emulateJar && sortEntries { - return errors.New("Cannot specify both --jar and --sort_entries (--jar implies sorting with a different algorithm)") + // move java source files to the correct folder based on the package statement inside of them. + // This is done before the entry sorting so that they're still in the right order. + if srcJar { + var javaMoveErrors []error + var javaMoveErrorsLock sync.Mutex + var wg sync.WaitGroup + for i := range pathMappings { + if filepath.Ext(pathMappings[i].src) == ".java" { + wg.Add(1) + go func() { + err := z.moveJavaFileBasedOnPackage(&pathMappings[i]) + if err != nil { + javaMoveErrorsLock.Lock() + javaMoveErrors = append(javaMoveErrors, err) + javaMoveErrorsLock.Unlock() + } + wg.Done() + }() + } + } + wg.Wait() + if len(javaMoveErrors) > 0 { + return errors.Join(javaMoveErrors...) + } } + if emulateJar { // manifest may be empty, in which case addManifest will fill in a default pathMappings = append(pathMappings, pathMapping{jar.ManifestFile, manifest, zip.Deflate}) jarSort(pathMappings) - } - if sortEntries { + } else { sort.SliceStable(pathMappings, func(i int, j int) bool { return pathMappings[i].dest < pathMappings[j].dest }) @@ -536,7 +593,7 @@ func (z *ZipWriter) write(f io.Writer, pathMappings []pathMapping, manifest stri if emulateJar && ele.dest == jar.ManifestFile { err = z.addManifest(ele.dest, ele.src, ele.zipMethod) } else { - err = z.addFile(ele.dest, ele.src, ele.zipMethod, emulateJar, srcJar) + err = z.addFile(ele.dest, ele.src, ele.zipMethod, emulateJar) } if err != nil { z.errors <- err @@ -635,7 +692,7 @@ func (z *ZipWriter) write(f io.Writer, pathMappings []pathMapping, manifest stri } // imports (possibly with compression) <src> into the zip at sub-path <dest> -func (z *ZipWriter) addFile(dest, src string, method uint16, emulateJar, srcJar bool) error { +func (z *ZipWriter) addFile(dest, src string, method uint16, emulateJar bool) error { var fileSize int64 var executable bool @@ -709,21 +766,6 @@ func (z *ZipWriter) addFile(dest, src string, method uint16, emulateJar, srcJar return err } - if srcJar && filepath.Ext(src) == ".java" { - // rewrite the destination using the package path if it can be determined - pkg, err := jar.JavaPackage(r, src) - if err != nil { - // ignore errors for now, leaving the file at in its original location in the zip - } else { - dest = filepath.Join(filepath.Join(strings.Split(pkg, ".")...), filepath.Base(src)) - } - - _, err = r.Seek(0, io.SeekStart) - if err != nil { - return err - } - } - fileSize = s.Size() executable = s.Mode()&0100 != 0 diff --git a/zip/zip_test.go b/zip/zip_test.go index c64c3f499..8f100d8dc 100644 --- a/zip/zip_test.go +++ b/zip/zip_test.go @@ -159,10 +159,10 @@ func TestZip(t *testing.T) { compressionLevel: 9, files: []zip.FileHeader{ + fh("[", fileEmpty, zip.Store), fh("a/a/a", fileA, zip.Deflate), fh("a/a/b", fileB, zip.Deflate), fh("c", fileC, zip.Deflate), - fh("[", fileEmpty, zip.Store), }, }, { @@ -261,10 +261,10 @@ func TestZip(t *testing.T) { compressionLevel: 9, files: []zip.FileHeader{ + fh("[", fileEmpty, zip.Store), fh("a/a/a", fileA, zip.Deflate), fh("a/a/b", fileB, zip.Deflate), fh("c", fileC, zip.Deflate), - fh("[", fileEmpty, zip.Store), }, }, { @@ -274,10 +274,10 @@ func TestZip(t *testing.T) { compressionLevel: 9, files: []zip.FileHeader{ + fh("[", fileEmpty, zip.Store), fh("a/a/a", fileA, zip.Deflate), fh("a/a/b", fileB, zip.Deflate), fh("c", fileC, zip.Deflate), - fh("[", fileEmpty, zip.Store), }, }, { @@ -287,11 +287,11 @@ func TestZip(t *testing.T) { compressionLevel: 9, files: []zip.FileHeader{ + fh("@", fileC, zip.Deflate), + fh("[", fileEmpty, zip.Store), fh("a/a/a", fileA, zip.Deflate), fh("a/a/b", fileB, zip.Deflate), - fh("@", fileC, zip.Deflate), fh("foo'bar", fileC, zip.Deflate), - fh("[", fileEmpty, zip.Store), }, }, { @@ -463,8 +463,8 @@ func TestZip(t *testing.T) { compressionLevel: 9, files: []zip.FileHeader{ - fh("foo", fileA, zip.Deflate), fh("a/a/b", fileB, zip.Deflate), + fh("foo", fileA, zip.Deflate), }, }, { @@ -477,8 +477,8 @@ func TestZip(t *testing.T) { compressionLevel: 9, files: []zip.FileHeader{ - fh("prefix/foo", fileA, zip.Deflate), fh("prefix/a/a/b", fileB, zip.Deflate), + fh("prefix/foo", fileA, zip.Deflate), }, }, { @@ -490,8 +490,8 @@ func TestZip(t *testing.T) { compressionLevel: 9, files: []zip.FileHeader{ - fh("foo", fileA, zip.Deflate), fh("a/a/b", fileB, zip.Deflate), + fh("foo", fileA, zip.Deflate), }, }, { @@ -504,8 +504,8 @@ func TestZip(t *testing.T) { compressionLevel: 9, files: []zip.FileHeader{ - fh("foo/bar", fileA, zip.Deflate), fh("b", fileB, zip.Deflate), + fh("foo/bar", fileA, zip.Deflate), }, }, @@ -688,8 +688,8 @@ func TestSrcJar(t *testing.T) { want := []string{ "foo/", - "foo/wrong_package.java", "foo/correct_package.java", + "foo/wrong_package.java", "no_package.java", "src2/", "src2/parse_error.java", |