diff options
Diffstat (limited to 'android/module.go')
-rw-r--r-- | android/module.go | 74 |
1 files changed, 57 insertions, 17 deletions
diff --git a/android/module.go b/android/module.go index 0716b5dac..d64b5163c 100644 --- a/android/module.go +++ b/android/module.go @@ -503,8 +503,12 @@ type Dist struct { // A suffix to add to the artifact file name (before any extension). Suffix *string `android:"arch_variant"` - // A string tag to select the OutputFiles associated with the tag. Defaults to the - // the empty "" string. + // A string tag to select the OutputFiles associated with the tag. + // + // If no tag is specified then it will select the default dist paths provided + // by the module type. If a tag of "" is specified then it will return the + // default output files provided by the modules, i.e. the result of calling + // OutputFiles(""). Tag *string `android:"arch_variant"` } @@ -733,9 +737,45 @@ type distProperties struct { Dists []Dist `android:"arch_variant"` } +// The key to use in TaggedDistFiles when a Dist structure does not specify a +// tag property. This intentionally does not use "" as the default because that +// would mean that an empty tag would have a different meaning when used in a dist +// structure that when used to reference a specific set of output paths using the +// :module{tag} syntax, which passes tag to the OutputFiles(tag) method. +const DefaultDistTag = "<default-dist-tag>" + // A map of OutputFile tag keys to Paths, for disting purposes. type TaggedDistFiles map[string]Paths +// addPathsForTag adds a mapping from the tag to the paths. If the map is nil +// then it will create a map, update it and then return it. If a mapping already +// exists for the tag then the paths are appended to the end of the current list +// of paths, ignoring any duplicates. +func (t TaggedDistFiles) addPathsForTag(tag string, paths ...Path) TaggedDistFiles { + if t == nil { + t = make(TaggedDistFiles) + } + + for _, distFile := range paths { + if distFile != nil && !t[tag].containsPath(distFile) { + t[tag] = append(t[tag], distFile) + } + } + + return t +} + +// merge merges the entries from the other TaggedDistFiles object into this one. +// If the TaggedDistFiles is nil then it will create a new instance, merge the +// other into it, and then return it. +func (t TaggedDistFiles) merge(other TaggedDistFiles) TaggedDistFiles { + for tag, paths := range other { + t = t.addPathsForTag(tag, paths...) + } + + return t +} + func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles { for _, path := range paths { if path == nil { @@ -744,7 +784,7 @@ func MakeDefaultDistFiles(paths ...Path) TaggedDistFiles { } // The default OutputFile tag is the empty "" string. - return TaggedDistFiles{"": paths} + return TaggedDistFiles{DefaultDistTag: paths} } type hostAndDeviceProperties struct { @@ -1071,24 +1111,24 @@ func (m *ModuleBase) Dists() []Dist { } func (m *ModuleBase) GenerateTaggedDistFiles(ctx BaseModuleContext) TaggedDistFiles { - distFiles := make(TaggedDistFiles) + var distFiles TaggedDistFiles for _, dist := range m.Dists() { - var tag string - var distFilesForTag Paths - if dist.Tag == nil { - tag = "" - } else { - tag = *dist.Tag - } + // If no tag is specified then it means to use the default dist paths so use + // the special tag name which represents that. + tag := proptools.StringDefault(dist.Tag, DefaultDistTag) + + // Call the OutputFiles(tag) method to get the paths associated with the tag. distFilesForTag, err := m.base().module.(OutputFileProducer).OutputFiles(tag) - if err != nil { + + // If the tag was not supported and is not DefaultDistTag then it is an error. + // Failing to find paths for DefaultDistTag is not an error. It just means + // that the module type requires the legacy behavior. + if err != nil && tag != DefaultDistTag { ctx.PropertyErrorf("dist.tag", "%s", err.Error()) + continue } - for _, distFile := range distFilesForTag { - if distFile != nil && !distFiles[tag].containsPath(distFile) { - distFiles[tag] = append(distFiles[tag], distFile) - } - } + + distFiles = distFiles.addPathsForTag(tag, distFilesForTag...) } return distFiles |