diff options
Diffstat (limited to 'android/module.go')
-rw-r--r-- | android/module.go | 87 |
1 files changed, 64 insertions, 23 deletions
diff --git a/android/module.go b/android/module.go index 196b095dd..11f63bd49 100644 --- a/android/module.go +++ b/android/module.go @@ -2812,44 +2812,85 @@ func (m *moduleContext) blueprintModuleContext() blueprint.ModuleContext { return m.bp } -// SrcIsModule decodes module references in the format ":name" into the module name, or empty string if the input -// was not a module reference. +// SrcIsModule decodes module references in the format ":unqualified-name" or "//namespace:name" +// into the module name, or empty string if the input was not a module reference. func SrcIsModule(s string) (module string) { - if len(s) > 1 && s[0] == ':' { - return s[1:] + if len(s) > 1 { + if s[0] == ':' { + module = s[1:] + if !isUnqualifiedModuleName(module) { + // The module name should be unqualified but is not so do not treat it as a module. + module = "" + } + } else if s[0] == '/' && s[1] == '/' { + module = s + } } - return "" + return module } -// SrcIsModule decodes module references in the format ":name{.tag}" into the module name and tag, ":name" into the -// module name and an empty string for the tag, or empty strings if the input was not a module reference. +// SrcIsModuleWithTag decodes module references in the format ":unqualified-name{.tag}" or +// "//namespace:name{.tag}" into the module name and tag, ":unqualified-name" or "//namespace:name" +// into the module name and an empty string for the tag, or empty strings if the input was not a +// module reference. func SrcIsModuleWithTag(s string) (module, tag string) { - if len(s) > 1 && s[0] == ':' { - module = s[1:] - if tagStart := strings.IndexByte(module, '{'); tagStart > 0 { - if module[len(module)-1] == '}' { - tag = module[tagStart+1 : len(module)-1] - module = module[:tagStart] - return module, tag + if len(s) > 1 { + if s[0] == ':' { + module = s[1:] + } else if s[0] == '/' && s[1] == '/' { + module = s + } + + if module != "" { + if tagStart := strings.IndexByte(module, '{'); tagStart > 0 { + if module[len(module)-1] == '}' { + tag = module[tagStart+1 : len(module)-1] + module = module[:tagStart] + } + } + + if s[0] == ':' && !isUnqualifiedModuleName(module) { + // The module name should be unqualified but is not so do not treat it as a module. + module = "" + tag = "" } } - return module, "" } - return "", "" + + return module, tag +} + +// isUnqualifiedModuleName makes sure that the supplied module is an unqualified module name, i.e. +// does not contain any /. +func isUnqualifiedModuleName(module string) bool { + return strings.IndexByte(module, '/') == -1 } +// sourceOrOutputDependencyTag is the dependency tag added automatically by pathDepsMutator for any +// module reference in a property annotated with `android:"path"` or passed to ExtractSourceDeps +// or ExtractSourcesDeps. +// +// If uniquely identifies the dependency that was added as it contains both the module name used to +// add the dependency as well as the tag. That makes it very simple to find the matching dependency +// in GetModuleFromPathDep as all it needs to do is find the dependency whose tag matches the tag +// used to add it. It does not need to check that the module name as returned by one of +// Module.Name(), BaseModuleContext.OtherModuleName() or ModuleBase.BaseModuleName() matches the +// name supplied in the tag. That means it does not need to handle differences in module names +// caused by prebuilt_ prefix, or fully qualified module names. type sourceOrOutputDependencyTag struct { blueprint.BaseDependencyTag + + // The name of the module. + moduleName string + + // The tag that will be passed to the module's OutputFileProducer.OutputFiles(tag) method. tag string } -func sourceOrOutputDepTag(tag string) blueprint.DependencyTag { - return sourceOrOutputDependencyTag{tag: tag} +func sourceOrOutputDepTag(moduleName, tag string) blueprint.DependencyTag { + return sourceOrOutputDependencyTag{moduleName: moduleName, tag: tag} } -// Deprecated, use IsSourceDepTagWithOutputTag(tag, "") instead. -var SourceDepTag = sourceOrOutputDepTag("") - // IsSourceDepTag returns true if the supplied blueprint.DependencyTag is one that was used to add // dependencies by either ExtractSourceDeps, ExtractSourcesDeps or automatically for properties // tagged with `android:"path"`. @@ -2880,7 +2921,7 @@ func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) { ctx.ModuleErrorf("found source dependency duplicate: %q!", s) } else { set[s] = true - ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m) + ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(m, t), m) } } } @@ -2893,7 +2934,7 @@ func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) { func ExtractSourceDeps(ctx BottomUpMutatorContext, s *string) { if s != nil { if m, t := SrcIsModuleWithTag(*s); m != "" { - ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m) + ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(m, t), m) } } } |