diff options
| author | Alex Light <allight@google.com> | 2019-02-27 16:19:43 -0800 |
|---|---|---|
| committer | Alex Light <allight@google.com> | 2019-02-28 00:30:43 +0000 |
| commit | 2255c706d47ab499dbdb6ce1e90da222c4050ec5 (patch) | |
| tree | 9d7560f581e9e4601c7f265c3cb5f8dc57552906 | |
| parent | f01f87af850dd1905fd41c3bc9ebfd856c068e56 (diff) | |
| parent | 02c110735d44497cca7a2ca28956d815dddcd7c6 (diff) | |
| download | android_build_blueprint-2255c706d47ab499dbdb6ce1e90da222c4050ec5.tar.gz android_build_blueprint-2255c706d47ab499dbdb6ce1e90da222c4050ec5.tar.bz2 android_build_blueprint-2255c706d47ab499dbdb6ce1e90da222c4050ec5.zip | |
Merge remote-tracking branch 'aosp/upstream' into master
* aosp/upstream:
GetDirectDepWithTag needs to check all tags before panicing
Allow Context to query Singletons
Test: Manual
Bug: 124507633
Bug: 125933724
Change-Id: If0a51961133a7dcbe7c779220130a203bcabed70
| -rw-r--r-- | context.go | 20 | ||||
| -rw-r--r-- | module_ctx.go | 12 | ||||
| -rw-r--r-- | singleton_ctx.go | 7 |
3 files changed, 35 insertions, 4 deletions
@@ -2347,6 +2347,7 @@ func (c *Context) generateSingletonBuildActions(config interface{}, scope := newLocalScope(nil, singletonNamespacePrefix(info.name)) sctx := &singletonContext{ + name: info.name, context: c, config: config, scope: scope, @@ -2977,6 +2978,25 @@ func (c *Context) VisitAllModuleVariants(module Module, c.visitAllModuleVariants(c.moduleInfo[module], visit) } +// Singletons returns a list of all registered Singletons. +func (c *Context) Singletons() []Singleton { + var ret []Singleton + for _, s := range c.singletonInfo { + ret = append(ret, s.singleton) + } + return ret +} + +// SingletonName returns the name that the given singleton was registered with. +func (c *Context) SingletonName(singleton Singleton) string { + for _, s := range c.singletonInfo { + if s.singleton == singleton { + return s.name + } + } + return "" +} + // WriteBuildFile writes the Ninja manifeset text for the generated build // actions to w. If this is called before PrepareBuildActions successfully // completes then ErrBuildActionsNotReady is returned. diff --git a/module_ctx.go b/module_ctx.go index 62646f1..9dbf43d 100644 --- a/module_ctx.go +++ b/module_ctx.go @@ -338,16 +338,20 @@ func (m *baseModuleContext) GetDirectDep(name string) (Module, DependencyTag) { // GetDirectDepWithTag returns the Module the direct dependency with the specified name, or nil if // none exists. It panics if the dependency does not have the specified tag. func (m *baseModuleContext) GetDirectDepWithTag(name string, tag DependencyTag) Module { + var deps []depInfo for _, dep := range m.module.directDeps { if dep.module.Name() == name { - if dep.tag != tag { - panic(fmt.Errorf("found dependency %q with tag %#v, expected tag %#v", - dep.module, dep.tag, tag)) + if dep.tag == tag { + return dep.module.logicModule } - return dep.module.logicModule + deps = append(deps, dep) } } + if len(deps) != 0 { + panic(fmt.Errorf("Unable to find dependency %q with requested tag %#v. Found: %#v", deps[0].module, tag, deps)) + } + return nil } diff --git a/singleton_ctx.go b/singleton_ctx.go index 1b044fa..5ca8ee6 100644 --- a/singleton_ctx.go +++ b/singleton_ctx.go @@ -27,6 +27,8 @@ type Singleton interface { type SingletonContext interface { Config() interface{} + Name() string + ModuleName(module Module) string ModuleDir(module Module) string ModuleSubDir(module Module) string @@ -83,6 +85,7 @@ type SingletonContext interface { var _ SingletonContext = (*singletonContext)(nil) type singletonContext struct { + name string context *Context config interface{} scope *localScope @@ -98,6 +101,10 @@ func (s *singletonContext) Config() interface{} { return s.config } +func (s *singletonContext) Name() string { + return s.name +} + func (s *singletonContext) ModuleName(logicModule Module) string { return s.context.ModuleName(logicModule) } |
