diff --git a/android/prebuilt.go b/android/prebuilt.go index bb98ed438..8114a65a5 100644 --- a/android/prebuilt.go +++ b/android/prebuilt.go @@ -17,6 +17,7 @@ package android import ( "fmt" "reflect" + "strings" "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -74,6 +75,12 @@ type Prebuilt struct { srcsPropertyName string } +// RemoveOptionalPrebuiltPrefix returns the result of removing the "prebuilt_" prefix from the +// supplied name if it has one, or returns the name unmodified if it does not. +func RemoveOptionalPrebuiltPrefix(name string) string { + return strings.TrimPrefix(name, "prebuilt_") +} + func (p *Prebuilt) Name(name string) string { return "prebuilt_" + name } diff --git a/apex/apex.go b/apex/apex.go index 2a81b9b99..261284c72 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -728,7 +728,9 @@ type ApexBundleInfo struct { var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info") -// apexInfoMutator is responsible for collecting modules that need to have apex variants. They are +var _ ApexInfoMutator = (*apexBundle)(nil) + +// ApexInfoMutator is responsible for collecting modules that need to have apex variants. They are // identified by doing a graph walk starting from an apexBundle. Basically, all the (direct and // indirect) dependencies are collected. But a few types of modules that shouldn't be included in // the apexBundle (e.g. stub libraries) are not collected. Note that a single module can be depended @@ -739,15 +741,7 @@ var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "ape // The apexMutator uses that list to create module variants for the apexes to which it belongs. // The relationship between module variants and apexes is not one-to-one as variants will be // shared between compatible apexes. -func apexInfoMutator(mctx android.TopDownMutatorContext) { - if !mctx.Module().Enabled() { - return - } - - a, ok := mctx.Module().(*apexBundle) - if !ok { - return - } +func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) { // The VNDK APEX is special. For the APEX, the membership is described in a very different // way. There is no dependency from the VNDK APEX to the VNDK libraries. Instead, VNDK @@ -826,6 +820,25 @@ func apexInfoMutator(mctx android.TopDownMutatorContext) { }) } +type ApexInfoMutator interface { + // ApexInfoMutator implementations must call BuildForApex(ApexInfo) on any modules that are + // depended upon by an apex and which require an apex specific variant. + ApexInfoMutator(android.TopDownMutatorContext) +} + +// apexInfoMutator delegates the work of identifying which modules need an ApexInfo and apex +// specific variant to modules that support the ApexInfoMutator. +func apexInfoMutator(mctx android.TopDownMutatorContext) { + if !mctx.Module().Enabled() { + return + } + + if a, ok := mctx.Module().(ApexInfoMutator); ok { + a.ApexInfoMutator(mctx) + return + } +} + // apexUniqueVariationsMutator checks if any dependencies use unique apex variations. If so, use // unique apex variations for this module. See android/apex.go for more about unique apex variant. // TODO(jiyong): move this to android/apex.go? @@ -2165,7 +2178,7 @@ func baselineApexAvailable(apex, moduleName string) bool { func normalizeModuleName(moduleName string) string { // Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build // system. Trim the prefix for the check since they are confusing - moduleName = strings.TrimPrefix(moduleName, "prebuilt_") + moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName) if strings.HasPrefix(moduleName, "libclang_rt.") { // This module has many arch variants that depend on the product being built. // We don't want to list them all diff --git a/cc/cc.go b/cc/cc.go index 9383e390b..d1f5c47e3 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -2749,7 +2749,7 @@ func orderStaticModuleDeps(staticDeps []StaticLibraryInfo, sharedDeps []SharedLi func baseLibName(depName string) string { libName := strings.TrimSuffix(depName, llndkLibrarySuffix) libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix) - libName = strings.TrimPrefix(libName, "prebuilt_") + libName = android.RemoveOptionalPrebuiltPrefix(libName) return libName }