Copy white listed apex available settings into snapshot

Makes sure that the module snapshots do not rely on the white list
of apex available settings so that when those lists are removed it is
not necessary to update any snapshots.

Bug: 142935992
Test: m nothing
Change-Id: Iedcff7dfc2646a4da77258d16e06657dd2f411f9
This commit is contained in:
Paul Duffin 2020-03-06 12:30:13 +00:00
parent 0cb37b9ce1
commit 7d74e7bea3
3 changed files with 47 additions and 15 deletions

View File

@ -168,7 +168,7 @@ func (m *ApexModuleBase) IsInstallableToApex() bool {
const ( const (
AvailableToPlatform = "//apex_available:platform" AvailableToPlatform = "//apex_available:platform"
availableToAnyApex = "//apex_available:anyapex" AvailableToAnyApex = "//apex_available:anyapex"
) )
func CheckAvailableForApex(what string, apex_available []string) bool { func CheckAvailableForApex(what string, apex_available []string) bool {
@ -178,7 +178,7 @@ func CheckAvailableForApex(what string, apex_available []string) bool {
return what == AvailableToPlatform return what == AvailableToPlatform
} }
return InList(what, apex_available) || return InList(what, apex_available) ||
(what != AvailableToPlatform && InList(availableToAnyApex, apex_available)) (what != AvailableToPlatform && InList(AvailableToAnyApex, apex_available))
} }
func (m *ApexModuleBase) AvailableFor(what string) bool { func (m *ApexModuleBase) AvailableFor(what string) bool {
@ -212,7 +212,7 @@ func (m *ApexModuleBase) ShouldSupportAndroid10() bool {
func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) { func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) {
for _, n := range m.ApexProperties.Apex_available { for _, n := range m.ApexProperties.Apex_available {
if n == AvailableToPlatform || n == availableToAnyApex { if n == AvailableToPlatform || n == AvailableToAnyApex {
continue continue
} }
if !mctx.OtherModuleExists(n) && !mctx.Config().AllowMissingDependencies() { if !mctx.OtherModuleExists(n) && !mctx.Config().AllowMissingDependencies() {

View File

@ -63,8 +63,26 @@ var (
usesTag = dependencyTag{name: "uses"} usesTag = dependencyTag{name: "uses"}
androidAppTag = dependencyTag{name: "androidApp", payload: true} androidAppTag = dependencyTag{name: "androidApp", payload: true}
apexAvailWl = makeApexAvailableWhitelist() apexAvailWl = makeApexAvailableWhitelist()
inverseApexAvailWl = invertApexWhiteList(apexAvailWl)
) )
// Transform the map of apex -> modules to module -> apexes.
func invertApexWhiteList(m map[string][]string) map[string][]string {
r := make(map[string][]string)
for apex, modules := range m {
for _, module := range modules {
r[module] = append(r[module], apex)
}
}
return r
}
// Retrieve the while list of apexes to which the supplied module belongs.
func WhitelistedApexAvailable(moduleName string) []string {
return inverseApexAvailWl[normalizeModuleName(moduleName)]
}
// This is a map from apex to modules, which overrides the // This is a map from apex to modules, which overrides the
// apex_available setting for that particular module to make // apex_available setting for that particular module to make
// it available for the apex regardless of its setting. // it available for the apex regardless of its setting.
@ -964,7 +982,7 @@ func makeApexAvailableWhitelist() map[string][]string {
// //
// Module separator // Module separator
// //
m["//any"] = []string{ m[android.AvailableToAnyApex] = []string{
"crtbegin_dynamic", "crtbegin_dynamic",
"crtbegin_dynamic1", "crtbegin_dynamic1",
"crtbegin_so", "crtbegin_so",
@ -2395,6 +2413,21 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
func whitelistedApexAvailable(apex, moduleName string) bool { func whitelistedApexAvailable(apex, moduleName string) bool {
key := apex key := apex
moduleName = normalizeModuleName(moduleName)
if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
return true
}
key = android.AvailableToAnyApex
if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
return true
}
return false
}
func normalizeModuleName(moduleName string) string {
// Prebuilt modules (e.g. java_import, etc.) have "prebuilt_" prefix added by the build // 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 // system. Trim the prefix for the check since they are confusing
moduleName = strings.TrimPrefix(moduleName, "prebuilt_") moduleName = strings.TrimPrefix(moduleName, "prebuilt_")
@ -2403,17 +2436,7 @@ func whitelistedApexAvailable(apex, moduleName string) bool {
// We don't want to list them all // We don't want to list them all
moduleName = "libclang_rt" moduleName = "libclang_rt"
} }
return moduleName
if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
return true
}
key = "//any"
if val, ok := apexAvailWl[key]; ok && android.InList(moduleName, val) {
return true
}
return false
} }
func newApexBundle() *apexBundle { func newApexBundle() *apexBundle {

View File

@ -20,6 +20,7 @@ import (
"sort" "sort"
"strings" "strings"
"android/soong/apex"
"github.com/google/blueprint" "github.com/google/blueprint"
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
@ -640,7 +641,15 @@ func (s *snapshotBuilder) AddPrebuiltModule(member android.SdkMember, moduleType
// Where available copy apex_available properties from the member. // Where available copy apex_available properties from the member.
if apexAware, ok := variant.(interface{ ApexAvailable() []string }); ok { if apexAware, ok := variant.(interface{ ApexAvailable() []string }); ok {
apexAvailable := apexAware.ApexAvailable() apexAvailable := apexAware.ApexAvailable()
// Add in any white listed apex available settings.
apexAvailable = append(apexAvailable, apex.WhitelistedApexAvailable(member.Name())...)
if len(apexAvailable) > 0 { if len(apexAvailable) > 0 {
// Remove duplicates and sort.
apexAvailable = android.FirstUniqueStrings(apexAvailable)
sort.Strings(apexAvailable)
m.AddProperty("apex_available", apexAvailable) m.AddProperty("apex_available", apexAvailable)
} }
} }