summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuK1337 <priv.luk@gmail.com>2021-01-10 17:47:46 +0100
committerLuK1337 <priv.luk@gmail.com>2021-04-17 10:48:09 +0200
commitae90578af957720f005fbc1a96b1c8574b859e9b (patch)
treeb6bfccc44352f57c1bef397c9bbde9047f58516e
parent3ead21d64879d465f5f1aed6ff1983e99fa0e3a5 (diff)
Make sure prebuilt modules are exported before attempting to use them
Fixes an issue where prebuilt module under unexported soong namespace overrides source modules when flag `prefer` was set. Test: Create two modules under the same name, use cc_library_shared for first one and cc_prebuilt_library_shared with `prefer` set to true. Then put the prebuilt module under `soong_namespace {}` and attempt to compile it without appending the namespace path to product namespaces. Without this change it should fail to resolve the cc_library_shared module even if it should be available. Change-Id: I506641218e6af94a0b5f048e09e06d83602e50f5
-rw-r--r--android/prebuilt.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/android/prebuilt.go b/android/prebuilt.go
index dfab13b92..340d286d8 100644
--- a/android/prebuilt.go
+++ b/android/prebuilt.go
@@ -230,12 +230,12 @@ func PrebuiltSelectModuleMutator(ctx TopDownMutatorContext) {
panic(fmt.Errorf("prebuilt module did not have InitPrebuiltModule called on it"))
}
if !p.properties.SourceExists {
- p.properties.UsePrebuilt = p.usePrebuilt(ctx, nil)
+ p.properties.UsePrebuilt = p.usePrebuilt(ctx, nil, m)
}
} else if s, ok := ctx.Module().(Module); ok {
ctx.VisitDirectDepsWithTag(PrebuiltDepTag, func(m Module) {
p := m.(PrebuiltInterface).Prebuilt()
- if p.usePrebuilt(ctx, s) {
+ if p.usePrebuilt(ctx, s, m) {
p.properties.UsePrebuilt = true
s.SkipInstall()
}
@@ -270,11 +270,18 @@ func PrebuiltPostDepsMutator(ctx BottomUpMutatorContext) {
// usePrebuilt returns true if a prebuilt should be used instead of the source module. The prebuilt
// will be used if it is marked "prefer" or if the source module is disabled.
-func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module) bool {
+func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module, prebuilt Module) bool {
if p.srcsSupplier != nil && len(p.srcsSupplier()) == 0 {
return false
}
+ // Skip prebuilt modules under unexported namespaces so that we won't
+ // end up shadowing non-prebuilt module when prebuilt module under same
+ // name happens to have a `Prefer` property set to true.
+ if !prebuilt.ExportedToMake() {
+ return false
+ }
+
// TODO: use p.Properties.Name and ctx.ModuleDir to override preference
if Bool(p.properties.Prefer) {
return true