summaryrefslogtreecommitdiff
path: root/android/deapexer.go
diff options
context:
space:
mode:
author Paul Duffin <paulduffin@google.com> 2022-06-09 17:32:21 +0000
committer Paul Duffin <paulduffin@google.com> 2022-06-10 11:05:53 +0000
commit1aa50564c783e4134e2fb4a7cdd0abca5b7b1403 (patch)
tree7d4e2624ba361c2b47982a6e47adb8f4808d637a /android/deapexer.go
parentb706b4efef8242aadcb756b345a70459fb94ea86 (diff)
Treat <x> and <x>_compressed prebuilt APEXes as being equivalent
When extracting dex files from prebuilt APEXes the build fails if it finds two or more prebuilt APEXes that could provide the dex files. This change treats <x> and <x>_compressed APEXes as being the same and always selects the uncompressed APEX. Bug: 235284603 Test: m nothing # Added TestDuplicateButEquivalentDeapexersFromPrebuiltApexes # Failed without this change, works with it. Change-Id: I805cb9dfa9f590c91585d75c4f4586b212b73d41
Diffstat (limited to 'android/deapexer.go')
-rw-r--r--android/deapexer.go43
1 files changed, 41 insertions, 2 deletions
diff --git a/android/deapexer.go b/android/deapexer.go
index 265f5312b..6a93f6087 100644
--- a/android/deapexer.go
+++ b/android/deapexer.go
@@ -15,6 +15,8 @@
package android
import (
+ "strings"
+
"github.com/google/blueprint"
)
@@ -148,12 +150,19 @@ type RequiresFilesFromPrebuiltApexTag interface {
func FindDeapexerProviderForModule(ctx ModuleContext) *DeapexerInfo {
var di *DeapexerInfo
ctx.VisitDirectDepsWithTag(DeapexerTag, func(m Module) {
- p := ctx.OtherModuleProvider(m, DeapexerProvider).(DeapexerInfo)
+ c := ctx.OtherModuleProvider(m, DeapexerProvider).(DeapexerInfo)
+ p := &c
if di != nil {
+ // If two DeapexerInfo providers have been found then check if they are
+ // equivalent. If they are then use the selected one, otherwise fail.
+ if selected := equivalentDeapexerInfoProviders(di, p); selected != nil {
+ di = selected
+ return
+ }
ctx.ModuleErrorf("Multiple installable prebuilt APEXes provide ambiguous deapexers: %s and %s",
di.ApexModuleName(), p.ApexModuleName())
}
- di = &p
+ di = p
})
if di != nil {
return di
@@ -162,3 +171,33 @@ func FindDeapexerProviderForModule(ctx ModuleContext) *DeapexerInfo {
ctx.ModuleErrorf("No prebuilt APEX provides a deapexer module for APEX variant %s", ai.ApexVariationName)
return nil
}
+
+// removeCompressedApexSuffix removes the _compressed suffix from the name if present.
+func removeCompressedApexSuffix(name string) string {
+ return strings.TrimSuffix(name, "_compressed")
+}
+
+// equivalentDeapexerInfoProviders checks to make sure that the two DeapexerInfo structures are
+// equivalent.
+//
+// At the moment <x> and <x>_compressed APEXes are treated as being equivalent.
+//
+// If they are not equivalent then this returns nil, otherwise, this returns the DeapexerInfo that
+// should be used by the build, which is always the uncompressed one. That ensures that the behavior
+// of the build is not dependent on which prebuilt APEX is visited first.
+func equivalentDeapexerInfoProviders(p1 *DeapexerInfo, p2 *DeapexerInfo) *DeapexerInfo {
+ n1 := removeCompressedApexSuffix(p1.ApexModuleName())
+ n2 := removeCompressedApexSuffix(p2.ApexModuleName())
+
+ // If the names don't match then they are not equivalent.
+ if n1 != n2 {
+ return nil
+ }
+
+ // Select the uncompressed APEX.
+ if n1 == removeCompressedApexSuffix(n1) {
+ return p1
+ } else {
+ return p2
+ }
+}