summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-10-24 01:31:54 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2024-10-24 01:31:54 +0000
commit44b35ecc43347292a95dec396244f083f77c9bdc (patch)
tree4e86ebbaa5bb99ae872ea5b12838959f6a1359e2
parentd1c410a3d05fa59e0297debd9c0a3d66ef6e479b (diff)
parent222874daedf5eb67dcbb2eca476f32292a3b63b5 (diff)
Merge "Introduce Soong API CreateModuleInDirectory(...)" into main
-rw-r--r--android/hooks.go40
-rw-r--r--android/mutator.go6
2 files changed, 42 insertions, 4 deletions
diff --git a/android/hooks.go b/android/hooks.go
index bd2fa5e75..9f4e5b620 100644
--- a/android/hooks.go
+++ b/android/hooks.go
@@ -37,6 +37,7 @@ type LoadHookContext interface {
AppendProperties(...interface{})
PrependProperties(...interface{})
CreateModule(ModuleFactory, ...interface{}) Module
+ CreateModuleInDirectory(ModuleFactory, string, ...interface{}) Module
registerScopedModuleType(name string, factory blueprint.ModuleFactory)
moduleFactories() map[string]blueprint.ModuleFactory
@@ -93,13 +94,37 @@ func (l *loadHookContext) createModule(factory blueprint.ModuleFactory, name str
return l.bp.CreateModule(factory, name, props...)
}
+func (l *loadHookContext) createModuleInDirectory(factory blueprint.ModuleFactory, name, moduleDir string, props ...interface{}) blueprint.Module {
+ return l.bp.CreateModuleInDirectory(factory, name, moduleDir, props...)
+}
+
+type specifyDirectory struct {
+ specified bool
+ directory string
+}
+
+func doesNotSpecifyDirectory() specifyDirectory {
+ return specifyDirectory{
+ specified: false,
+ directory: "",
+ }
+}
+
+func specifiesDirectory(directory string) specifyDirectory {
+ return specifyDirectory{
+ specified: true,
+ directory: directory,
+ }
+}
+
type createModuleContext interface {
Module() Module
HasMutatorFinished(mutatorName string) bool
createModule(blueprint.ModuleFactory, string, ...interface{}) blueprint.Module
+ createModuleInDirectory(blueprint.ModuleFactory, string, string, ...interface{}) blueprint.Module
}
-func createModule(ctx createModuleContext, factory ModuleFactory, ext string, props ...interface{}) Module {
+func createModule(ctx createModuleContext, factory ModuleFactory, ext string, specifyDirectory specifyDirectory, props ...interface{}) Module {
if ctx.HasMutatorFinished("defaults") {
// Creating modules late is oftentimes problematic, because they don't have earlier
// mutators run on them. Prevent making modules after the defaults mutator has run.
@@ -119,7 +144,12 @@ func createModule(ctx createModuleContext, factory ModuleFactory, ext string, pr
}
typeName = typeName + "_" + ext
- module := ctx.createModule(ModuleFactoryAdaptor(factory), typeName, append(inherited, props...)...).(Module)
+ var module Module
+ if specifyDirectory.specified {
+ module = ctx.createModuleInDirectory(ModuleFactoryAdaptor(factory), typeName, specifyDirectory.directory, append(inherited, props...)...).(Module)
+ } else {
+ module = ctx.createModule(ModuleFactoryAdaptor(factory), typeName, append(inherited, props...)...).(Module)
+ }
if ctx.Module().base().variableProperties != nil && module.base().variableProperties != nil {
src := ctx.Module().base().variableProperties
@@ -139,7 +169,11 @@ func createModule(ctx createModuleContext, factory ModuleFactory, ext string, pr
}
func (l *loadHookContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
- return createModule(l, factory, "_loadHookModule", props...)
+ return createModule(l, factory, "_loadHookModule", doesNotSpecifyDirectory(), props...)
+}
+
+func (l *loadHookContext) CreateModuleInDirectory(factory ModuleFactory, directory string, props ...interface{}) Module {
+ return createModule(l, factory, "_loadHookModule", specifiesDirectory(directory), props...)
}
func (l *loadHookContext) registerScopedModuleType(name string, factory blueprint.ModuleFactory) {
diff --git a/android/mutator.go b/android/mutator.go
index 6bd2e60b8..f2b94ac34 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -742,8 +742,12 @@ func (b *bottomUpMutatorContext) createModule(factory blueprint.ModuleFactory, n
return b.bp.CreateModule(factory, name, props...)
}
+func (b *bottomUpMutatorContext) createModuleInDirectory(factory blueprint.ModuleFactory, name string, _ string, props ...interface{}) blueprint.Module {
+ panic("createModuleInDirectory is not implemented for bottomUpMutatorContext")
+}
+
func (b *bottomUpMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
- return createModule(b, factory, "_bottomUpMutatorModule", props...)
+ return createModule(b, factory, "_bottomUpMutatorModule", doesNotSpecifyDirectory(), props...)
}
func (b *bottomUpMutatorContext) AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module {