Support fully qualified names in `android:"path"` properties
Previously, a module reference in a path property would be parsed into
two parts, the module name and the optional output tag, which defaults
to an empty string if not specified. The output tag would be stored in
a sourceOrOutputDependencyTag which would then be used, along with the
module name to add a dependency on the module.
Later, when the paths were processed the same module reference would be
parsed into the same two parts again and the module name used to find a
matching Module by comparing it against the name returned by either
Module.Name(), ctx.OtherModuleName() or ModuleBase.BaseModuleName().
Once the module had been found then if it supported OutputFilesProducer
then the tag would be passed to its OutputFiles(tag) method. Otherwise,
it would fall back to treating it as SourceFilesProducer.
The problem with that is the module name retrieved from the module in
some way (either directly or through a context name) could be different
to that originally supplied when adding the dependency. e.g.
1. If the original dependency was added onto a source module but there
existed a suitable and preferred prebuilt module then the dependency
onto the source module would have been replaced by the prebuilt
module which has a different name.
2. If the path property included a fully qualified name that included
a qualifying path then it would not match the name retrieved from
the module which would not include the qualifying path.
This change circumvents that whole issue by adding the module name that
was originally used to add the dependency into the DependencyTag. Now
the DependencyTag uniquely identifies the original module/outputTag
pair parsed from the module reference. The pathDepsMutator guarantees
that they are unique as it dedups them before adding the dependencies.
It is possible that calling ExtractSource(s)Deps() would add some
duplicate but if they did they would be identical, i.e. the same
sourceOrOutputDependencyTag would be used to add a dependency onto the
exact same module. In that case it would not matter which of the
dependencies was found as it would still return the same module.
Bug: 193228441
Test: m nothing
Change-Id: I661514a2984818e5c26577411cede53eb57bcd02
diff --git a/android/module.go b/android/module.go
index 126d629..385b63a 100644
--- a/android/module.go
+++ b/android/module.go
@@ -2865,18 +2865,31 @@
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"`.
@@ -2907,7 +2920,7 @@
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)
}
}
}
@@ -2920,7 +2933,7 @@
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)
}
}
}