From e1d3837645846596d3db0e0e5bc559e8d2876e0b Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 2 Apr 2021 10:35:24 +0100 Subject: [PATCH] Add IsModulePreferred Bug: 177892522 Test: m nothing Change-Id: I47268b81359d6fceb60e899a730b3b6034e09814 --- android/prebuilt.go | 20 ++++++++++++++++++++ java/boot_jars.go | 11 +---------- java/platform_compat_config.go | 10 +--------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/android/prebuilt.go b/android/prebuilt.go index ebccaa765..b43d23881 100644 --- a/android/prebuilt.go +++ b/android/prebuilt.go @@ -213,6 +213,26 @@ type PrebuiltInterface interface { Prebuilt() *Prebuilt } +// IsModulePreferred returns true if the given module is preferred. +// +// A source module is preferred if there is no corresponding prebuilt module or the prebuilt module +// does not have "prefer: true". +// +// A prebuilt module is preferred if there is no corresponding source module or the prebuilt module +// has "prefer: true". +func IsModulePreferred(module Module) bool { + if module.IsReplacedByPrebuilt() { + // A source module that has been replaced by a prebuilt counterpart. + return false + } + if prebuilt, ok := module.(PrebuiltInterface); ok { + if p := prebuilt.Prebuilt(); p != nil { + return p.UsePrebuilt() + } + } + return true +} + func RegisterPrebuiltsPreArchMutators(ctx RegisterMutatorsContext) { ctx.BottomUp("prebuilt_rename", PrebuiltRenameMutator).Parallel() } diff --git a/java/boot_jars.go b/java/boot_jars.go index ac8107b7c..1fb3deb0a 100644 --- a/java/boot_jars.go +++ b/java/boot_jars.go @@ -56,16 +56,7 @@ func isActiveModule(module android.Module) bool { if !module.Enabled() { return false } - if module.IsReplacedByPrebuilt() { - // A source module that has been replaced by a prebuilt counterpart. - return false - } - if prebuilt, ok := module.(android.PrebuiltInterface); ok { - if p := prebuilt.Prebuilt(); p != nil { - return p.UsePrebuilt() - } - } - return true + return android.IsModulePreferred(module) } func (b *bootJarsSingleton) GenerateBuildActions(ctx android.SingletonContext) { diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index c3d13ae65..edfa146f9 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -232,15 +232,7 @@ func isModulePreferredByCompatConfig(module android.Module) bool { } } - // A prebuilt module should only be used when it is preferred. - if pi, ok := module.(android.PrebuiltInterface); ok { - if p := pi.Prebuilt(); p != nil { - return p.UsePrebuilt() - } - } - - // Otherwise, a module should only be used if it has not been replaced by a prebuilt. - return !module.IsReplacedByPrebuilt() + return android.IsModulePreferred(module) } func (p *platformCompatConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) {