Merge "Support fully qualified names in android:"path" properties"

This commit is contained in:
Paul Duffin
2021-07-15 16:02:34 +00:00
committed by Gerrit Code Review
4 changed files with 47 additions and 17 deletions

View File

@@ -2866,18 +2866,31 @@ 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"`.
@@ -2908,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)
}
}
}
@@ -2921,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)
}
}
}

View File

@@ -51,7 +51,7 @@ func addPathDepsForProps(ctx BottomUpMutatorContext, props []interface{}) {
// Add dependencies to anything that is a module reference.
for _, s := range pathProperties {
if m, t := SrcIsModuleWithTag(s); m != "" {
ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(t), m)
ctx.AddDependency(ctx.Module(), sourceOrOutputDepTag(m, t), m)
}
}
}

View File

@@ -88,7 +88,8 @@ func GlobFiles(ctx EarlyModulePathContext, globPattern string, excludes []string
// the Path methods that rely on module dependencies having been resolved.
type ModuleWithDepsPathContext interface {
EarlyModulePathContext
GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module
VisitDirectDepsBlueprint(visit func(blueprint.Module))
OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
}
// ModuleMissingDepsPathContext is a subset of *ModuleContext methods required by
@@ -484,10 +485,27 @@ func getPathsFromModuleDep(ctx ModuleWithDepsPathContext, path, moduleName, tag
//
// If tag is "" then the returned module will be the dependency that was added for ":moduleName".
// Otherwise, it is the dependency that was added for ":moduleName{tag}".
//
// TODO(b/193228441) Make this handle fully qualified names, e.g. //namespace:moduleName.
func GetModuleFromPathDep(ctx ModuleWithDepsPathContext, moduleName, tag string) blueprint.Module {
return ctx.GetDirectDepWithTag(moduleName, sourceOrOutputDepTag(tag))
var found blueprint.Module
// The sourceOrOutputDepTag uniquely identifies the module dependency as it contains both the
// module name and the tag. Dependencies added automatically for properties tagged with
// `android:"path"` are deduped so are guaranteed to be unique. It is possible for duplicate
// dependencies to be added manually using ExtractSourcesDeps or ExtractSourceDeps but even then
// it will always be the case that the dependencies will be identical, i.e. the same tag and same
// moduleName referring to the same dependency module.
//
// It does not matter whether the moduleName is a fully qualified name or if the module
// dependency is a prebuilt module. All that matters is the same information is supplied to
// create the tag here as was supplied to create the tag when the dependency was added so that
// this finds the matching dependency module.
expectedTag := sourceOrOutputDepTag(moduleName, tag)
ctx.VisitDirectDepsBlueprint(func(module blueprint.Module) {
depTag := ctx.OtherModuleDependencyTag(module)
if depTag == expectedTag {
found = module
}
})
return found
}
// PathsAndMissingDepsForModuleSrcExcludes returns a Paths{} containing the resolved references in

View File

@@ -1390,7 +1390,6 @@ func TestPathForModuleSrc(t *testing.T) {
}),
},
{
// TODO(b/193228441): Fix broken test.
name: "output file provider, fully qualified name",
bp: `
test {
@@ -1398,6 +1397,10 @@ func TestPathForModuleSrc(t *testing.T) {
src: "//other:b",
srcs: ["//other:c"],
}`,
src: "out/soong/.intermediates/other/b/gen/b",
rel: "gen/b",
srcs: []string{"out/soong/.intermediates/other/c/gen/c"},
rels: []string{"gen/c"},
preparer: FixtureAddTextFile("other/Android.bp", `
soong_namespace {}
@@ -1411,10 +1414,6 @@ func TestPathForModuleSrc(t *testing.T) {
outs: ["gen/c"],
}
`),
errorHandler: FixtureExpectsAllErrorsToMatchAPattern([]string{
`"foo": missing dependencies: //other:b, is the property annotated with android:"path"`,
`"foo": missing dependency on "//other:c", is the property annotated with android:"path"`,
}),
},
}