Make overrides work in Soong
This change adds `overrides` property to all module types. It is used
to prevent another module (or modules) from being installed or packaged.
Bug: 330141242
Test: go test ./...
Change-Id: I4f05c603f0c5dbb699d00327882c7498472b59de
diff --git a/android/packaging.go b/android/packaging.go
index 42009d5..61dfa7e 100644
--- a/android/packaging.go
+++ b/android/packaging.go
@@ -56,6 +56,12 @@
// ArchType of the module which produced this packaging spec
archType ArchType
+
+ // List of module names that this packaging spec overrides
+ overrides *[]string
+
+ // Name of the module where this packaging spec is output of
+ owner string
}
func (p *PackagingSpec) Equals(other *PackagingSpec) bool {
@@ -325,7 +331,10 @@
}
func (p *PackagingBase) GatherPackagingSpecsWithFilter(ctx ModuleContext, filter func(PackagingSpec) bool) map[string]PackagingSpec {
- m := make(map[string]PackagingSpec)
+ // all packaging specs gathered from the dep.
+ var all []PackagingSpec
+ // list of module names overridden
+ var overridden []string
var arches []ArchType
for _, target := range getSupportedTargets(ctx) {
@@ -357,17 +366,33 @@
continue
}
}
- dstPath := ps.relPathInPackage
- if existingPs, ok := m[dstPath]; ok {
- if !existingPs.Equals(&ps) {
- ctx.ModuleErrorf("packaging conflict at %v:\n%v\n%v", dstPath, existingPs, ps)
- }
- continue
+ all = append(all, ps)
+ if ps.overrides != nil {
+ overridden = append(overridden, *ps.overrides...)
}
-
- m[dstPath] = ps
}
})
+
+ // all minus packaging specs that are overridden
+ var filtered []PackagingSpec
+ for _, ps := range all {
+ if ps.owner != "" && InList(ps.owner, overridden) {
+ continue
+ }
+ filtered = append(filtered, ps)
+ }
+
+ m := make(map[string]PackagingSpec)
+ for _, ps := range filtered {
+ dstPath := ps.relPathInPackage
+ if existingPs, ok := m[dstPath]; ok {
+ if !existingPs.Equals(&ps) {
+ ctx.ModuleErrorf("packaging conflict at %v:\n%v\n%v", dstPath, existingPs, ps)
+ }
+ continue
+ }
+ m[dstPath] = ps
+ }
return m
}