diff options
author | 2025-02-19 23:44:48 +0000 | |
---|---|---|
committer | 2025-02-20 19:41:43 +0000 | |
commit | 64371e06725fd63b92d0db830e59674dad1b7e5d (patch) | |
tree | 291f5d52e58a9083eff64d49a5ecc60ba087bf9c | |
parent | ebc3d69b42a6bf6efb7571afb9d0991531db13cf (diff) |
For modules that provide AndroidMkInfoProvider, only access modules'
internal data through providers.
Eventually all module should be converted to provide this provider, and
then we can change it to use VisitAllModuleProxies instead of
VisitAllModules.
Bug: 377723687
Test: Unit tests and compare the ninja and mk files generated.
Change-Id: I83b55c20f971c619fa39613c1fb1cb525f56d20e
-rw-r--r-- | android/aconfig_providers.go | 48 | ||||
-rw-r--r-- | android/androidmk.go | 102 | ||||
-rw-r--r-- | android/module.go | 33 | ||||
-rw-r--r-- | android/testing.go | 5 |
4 files changed, 129 insertions, 59 deletions
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/androidmk.go b/android/androidmk.go index c081ba372..d9d78f349 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -775,6 +775,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,28 +897,29 @@ 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 := info.PrimaryInfo.getDistContributions(ctx, mod, &commonInfo); contribution != nil { allDistContributions = append(allDistContributions, *contribution) } for _, ei := range info.ExtraInfo { - ei.fillInEntries(ctx, mod) + ei.fillInEntries(ctx, mod, &commonInfo) if ei.disabled() { continue } - if contribution := ei.getDistContributions(ctx, mod); contribution != nil { + if contribution := ei.getDistContributions(ctx, mod, &commonInfo); contribution != nil { allDistContributions = append(allDistContributions, *contribution) } } @@ -1333,9 +1336,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 +1351,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 +1484,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 +1499,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 +1533,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 +1548,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 +1581,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 +1660,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 := a.getDistContributions(ctx, mod, commonInfo) if distContributions == nil { return nil } @@ -1662,9 +1672,11 @@ func (a *AndroidMkInfo) GetDistForGoals(ctx fillInEntriesContext, mod Module) [] } // 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() +// TODO(b/397766191): Change the signature to take ModuleProxy +// Please only access the module's internal data through providers. +func (a *AndroidMkInfo) getDistContributions(ctx fillInEntriesContext, mod Module, + commonInfo *CommonModuleInfo) *distContributions { + name := commonInfo.BaseModuleName // Collate the set of associated tag/paths available for copying to the dist. // Start with an empty (nil) set. @@ -1700,12 +1712,12 @@ func (a *AndroidMkInfo) getDistContributions(ctx fillInEntriesContext, mod Modul // Collate the contributions this module makes to the dist. distContributions := &distContributions{} - if !exemptFromRequiredApplicableLicensesProperty(mod) { + if !commonInfo.ExemptFromRequiredApplicableLicensesProperty { distContributions.licenseMetadataFile = info.LicenseMetadataFile } // Iterate over this module's dist structs, merged from the dist and dists properties. - for _, dist := range amod.Dists() { + for _, dist := range commonInfo.Dists { // Get the list of goals this dist should be enabled for. e.g. sdk, droidcore goals := strings.Join(dist.Targets, " ") diff --git a/android/module.go b/android/module.go index f359e9f4d..996c64e52 100644 --- a/android/module.go +++ b/android/module.go @@ -1922,6 +1922,23 @@ type CommonModuleInfo struct { // 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 } type ApiLevelOrPlatform struct { @@ -2266,7 +2283,21 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) SkipInstall: m.commonProperties.SkipInstall, Host: m.Host(), PrimaryLicensesProperty: m.primaryLicensesProperty, - Owner: m.Owner(), + 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(), } if mm, ok := m.module.(interface { MinSdkVersion(ctx EarlyModuleContext) ApiLevel diff --git a/android/testing.go b/android/testing.go index fe9bcec26..d0ede210a 100644 --- a/android/testing.go +++ b/android/testing.go @@ -1191,10 +1191,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) } } |