diff options
author | colincross <github@colincross.com> | 2019-02-26 10:54:08 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-26 10:54:08 -0800 |
commit | 8908a0a8062251125786b1e518737dfc5d7abe83 (patch) | |
tree | fb3a8e104fbd8e3fe4839267d0fda59a61258723 | |
parent | d444506bf6383850531162839d09d854a4bba6e1 (diff) | |
parent | 9226d6c9f5c112afa678fbfdcb9528d82ef6b408 (diff) | |
download | android_build_blueprint-8908a0a8062251125786b1e518737dfc5d7abe83.tar.gz android_build_blueprint-8908a0a8062251125786b1e518737dfc5d7abe83.tar.bz2 android_build_blueprint-8908a0a8062251125786b1e518737dfc5d7abe83.zip |
Merge pull request #237 from colincross/singleton
Allow Context to query Singletons
-rw-r--r-- | context.go | 20 | ||||
-rw-r--r-- | singleton_ctx.go | 7 |
2 files changed, 27 insertions, 0 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/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) } |