Divorce disting from androidmk
Change AndroidMkEntries.getDistContributions and
AndroidMkInfo.getDistContributions into a freestanding
getDistContributions.
This enables us to not call the AndroidMk related functions in
soong-only builds.
Bug: 398938465
Test: Diff'd the ninja files from "m nothing dist" before/after this cl, no changes
Change-Id: I2f9d537c0d66f0ae3715f083e2f55436e4c0a59f
diff --git a/android/androidmk.go b/android/androidmk.go
index 5cb5a66..6a1701d 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -349,30 +349,15 @@
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
-
- // If no paths have been provided for the DefaultDistTag and the output file is
- // valid then add that as the default dist path.
- if 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.
@@ -446,7 +431,7 @@
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 != "" {
@@ -494,7 +479,7 @@
// 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
}
@@ -903,18 +888,9 @@
if moduleInfoJSON, ok := OtherModuleProvider(ctx, mod, ModuleInfoJSONProvider); ok {
moduleInfoJSONs = append(moduleInfoJSONs, moduleInfoJSON...)
}
- if contribution := info.PrimaryInfo.getDistContributions(ctx, mod, &commonInfo); contribution != nil {
+ if contribution := getDistContributions(ctx, mod); contribution != nil {
allDistContributions = append(allDistContributions, *contribution)
}
- for _, ei := range info.ExtraInfo {
- ei.fillInEntries(ctx, mod, &commonInfo)
- if ei.disabled() {
- continue
- }
- if contribution := ei.getDistContributions(ctx, mod, &commonInfo); contribution != nil {
- allDistContributions = append(allDistContributions, *contribution)
- }
- }
} else {
if x, ok := mod.(AndroidMkDataProvider); ok {
data := x.AndroidMk()
@@ -930,7 +906,7 @@
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)
}
}
@@ -944,7 +920,7 @@
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)
}
}
@@ -1653,7 +1629,7 @@
// 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)
+ distContributions := getDistContributions(ctx, mod)
if distContributions == nil {
return nil
}
@@ -1661,127 +1637,6 @@
return generateDistContributionsForMake(distContributions)
}
-// Compute the contributions that the module makes to the dist.
-// 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.
- var availableTaggedDists TaggedDistFiles
-
- // If no paths have been provided for the DefaultDistTag and the output file is
- // valid then add that as the default dist path.
- if 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 !commonInfo.ExemptFromRequiredApplicableLicensesProperty {
- distContributions.licenseMetadataFile = info.LicenseMetadataFile
- }
-
- // Iterate over this module's dist structs, merged from the dist and dists properties.
- 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, " ")
-
- // 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),