summaryrefslogtreecommitdiff
path: root/android/singleton.go
diff options
context:
space:
mode:
author Bob Badour <bbadour@google.com> 2022-05-16 12:20:04 -0700
committer Bob Badour <bbadour@google.com> 2022-05-18 16:38:19 -0700
commiteef4c1c5630269b255672827aeadde6e5ba88a69 (patch)
tree3598413fe580187623e56ac6efb1063e91ecfe0b /android/singleton.go
parent61c6eef064d2fc72be422c91a70b59fda119adfc (diff)
Add gen_notice module.
Refactor notices to support notices for multiple modules. Enforce visibility and handle missing dependencies. Bug: 213388645 Change-Id: Id6a81987f087419ad37d0cce57a71e8a7c4cd6e0
Diffstat (limited to 'android/singleton.go')
-rw-r--r--android/singleton.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/android/singleton.go b/android/singleton.go
index 7ff96c9d5..ec7f63eca 100644
--- a/android/singleton.go
+++ b/android/singleton.go
@@ -29,6 +29,10 @@ type SingletonContext interface {
ModuleType(module blueprint.Module) string
BlueprintFile(module blueprint.Module) string
+ // ModuleVariantsFromName returns the list of module variants named `name` in the same namespace as `referer` enforcing visibility rules.
+ // Allows generating build actions for `referer` based on the metadata for `name` deferred until the singleton context.
+ ModuleVariantsFromName(referer Module, name string) []Module
+
// ModuleProvider returns the value, if any, for the provider for a module. If the value for the
// provider was not set it returns the zero value of the type of the provider, which means the
// return value can always be type-asserted to the type of the provider. The return value should
@@ -251,3 +255,29 @@ func (s *singletonContextAdaptor) PrimaryModule(module Module) Module {
func (s *singletonContextAdaptor) FinalModule(module Module) Module {
return s.SingletonContext.FinalModule(module).(Module)
}
+
+func (s *singletonContextAdaptor) ModuleVariantsFromName(referer Module, name string) []Module {
+ // get qualified module name for visibility enforcement
+ qualified := createQualifiedModuleName(s.ModuleName(referer), s.ModuleDir(referer))
+
+ modules := s.SingletonContext.ModuleVariantsFromName(referer, name)
+ result := make([]Module, 0, len(modules))
+ for _, m := range modules {
+ if module, ok := m.(Module); ok {
+ // enforce visibility
+ depName := s.ModuleName(module)
+ depDir := s.ModuleDir(module)
+ depQualified := qualifiedModuleName{depDir, depName}
+ // Targets are always visible to other targets in their own package.
+ if depQualified.pkg != qualified.pkg {
+ rule := effectiveVisibilityRules(s.Config(), depQualified)
+ if !rule.matches(qualified) {
+ s.ModuleErrorf(referer, "references %s which is not visible to this module\nYou may need to add %q to its visibility", depQualified, "//"+s.ModuleDir(m))
+ continue
+ }
+ }
+ result = append(result, module)
+ }
+ }
+ return result
+}