Add function to retrieve module by name. am: 030150d8f9
am: 2322a800cc
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1772793 Change-Id: Ibc01f9d5af34f9caeac114b98f7dfb2b5770f222
This commit is contained in:
commit
74137dfbbb
1 changed files with 25 additions and 0 deletions
|
@ -294,6 +294,14 @@ type BaseModuleContext interface {
|
|||
// passed to Context.SetNameInterface, or SimpleNameInterface if it was not called.
|
||||
OtherModuleExists(name string) bool
|
||||
|
||||
// ModuleFromName returns (module, true) if a module exists by the given name and same context namespace,
|
||||
// or (nil, false) if it does not exist. It panics if there is either more than one
|
||||
// module of the given name, or if the given name refers to an alias instead of a module.
|
||||
// There are no guarantees about which variant of the module will be returned.
|
||||
// Prefer retrieving the module using GetDirectDep or a visit function, when possible, as
|
||||
// this will guarantee the appropriate module-variant dependency is returned.
|
||||
ModuleFromName(name string) (Module, bool)
|
||||
|
||||
// OtherModuleDependencyVariantExists returns true if a module with the
|
||||
// specified name and variant exists. The variant must match the given
|
||||
// variations. It must also match all the non-local variations of the current
|
||||
|
@ -532,6 +540,23 @@ func (m *baseModuleContext) OtherModuleDependencyTag(logicModule Module) Depende
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *baseModuleContext) ModuleFromName(name string) (Module, bool) {
|
||||
moduleGroup, exists := m.context.nameInterface.ModuleFromName(name, m.module.namespace())
|
||||
if exists {
|
||||
if len(moduleGroup.modules) != 1 {
|
||||
panic(fmt.Errorf("Expected exactly one module named %q, but got %d", name, len(moduleGroup.modules)))
|
||||
}
|
||||
moduleInfo := moduleGroup.modules[0].module()
|
||||
if moduleInfo != nil {
|
||||
return moduleInfo.logicModule, true
|
||||
} else {
|
||||
panic(fmt.Errorf(`Expected actual module named %q, but group did not contain a module.
|
||||
There may instead be an alias by that name.`, name))
|
||||
}
|
||||
}
|
||||
return nil, exists
|
||||
}
|
||||
|
||||
func (m *baseModuleContext) OtherModuleExists(name string) bool {
|
||||
_, exists := m.context.nameInterface.ModuleFromName(name, m.module.namespace())
|
||||
return exists
|
||||
|
|
Loading…
Reference in a new issue