Ignore test apexes from bp2build generated tags am: f57a966b66

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2533722

Change-Id: Ib92fe92f3f088cff422c6dabd606cbedb1d97adc
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Spandan Das 2023-05-01 16:39:23 +00:00 committed by Automerger Merge Worker
commit b2b9494db1
4 changed files with 50 additions and 3 deletions

View file

@ -462,6 +462,14 @@ const (
AvailableToGkiApex = "com.android.gki.*"
)
var (
AvailableToRecognziedWildcards = []string{
AvailableToPlatform,
AvailableToAnyApex,
AvailableToGkiApex,
}
)
// CheckAvailableForApex provides the default algorithm for checking the apex availability. When the
// availability is empty, it defaults to ["//apex_available:platform"] which means "available to the
// platform but not available to any APEX". When the list is not empty, `what` is matched against
@ -925,3 +933,9 @@ func CheckMinSdkVersion(ctx ModuleContext, minSdkVersion ApiLevel, walk WalkPayl
return true
})
}
// Implemented by apexBundle.
type ApexTestInterface interface {
// Return true if the apex bundle is an apex_test
IsTestApex() bool
}

View file

@ -781,6 +781,35 @@ func ApexAvailableTags(mod Module) bazel.StringListAttribute {
return attr
}
func ApexAvailableTagsWithoutTestApexes(ctx BaseModuleContext, mod Module) bazel.StringListAttribute {
attr := bazel.StringListAttribute{}
if am, ok := mod.(ApexModule); ok {
apexAvailableWithoutTestApexes := removeTestApexes(ctx, am.apexModuleBase().ApexAvailable())
// If a user does not specify apex_available in Android.bp, then soong provides a default.
// To avoid verbosity of BUILD files, remove this default from user-facing BUILD files.
if len(am.apexModuleBase().ApexProperties.Apex_available) == 0 {
apexAvailableWithoutTestApexes = []string{}
}
attr.Value = ConvertApexAvailableToTags(apexAvailableWithoutTestApexes)
}
return attr
}
func removeTestApexes(ctx BaseModuleContext, apex_available []string) []string {
testApexes := []string{}
for _, aa := range apex_available {
// ignore the wildcards
if InList(aa, AvailableToRecognziedWildcards) {
continue
}
mod, _ := ctx.ModuleFromName(aa)
if apex, ok := mod.(ApexTestInterface); ok && apex.IsTestApex() {
testApexes = append(testApexes, aa)
}
}
return RemoveListFromList(CopyOf(apex_available), testApexes)
}
func ConvertApexAvailableToTags(apexAvailable []string) []string {
if len(apexAvailable) == 0 {
// We need nil specifically to make bp2build not add the tags property at all,

View file

@ -3811,3 +3811,7 @@ func makeSharedLibsAttributes(config string, libsLabelList bazel.LabelList,
func invalidCompileMultilib(ctx android.TopDownMutatorContext, value string) {
ctx.PropertyErrorf("compile_multilib", "Invalid value: %s", value)
}
func (a *apexBundle) IsTestApex() bool {
return a.testApex
}

View file

@ -433,11 +433,11 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
var tagsForStaticVariant bazel.StringListAttribute
if compilerAttrs.stubsSymbolFile == nil && len(compilerAttrs.stubsVersions.Value) == 0 {
tagsForStaticVariant = android.ApexAvailableTags(m)
tagsForStaticVariant = android.ApexAvailableTagsWithoutTestApexes(ctx, m)
}
tagsForStaticVariant.Append(bazel.StringListAttribute{Value: staticAttrs.Apex_available})
tagsForSharedVariant := android.ApexAvailableTags(m)
tagsForSharedVariant := android.ApexAvailableTagsWithoutTestApexes(ctx, m)
tagsForSharedVariant.Append(bazel.StringListAttribute{Value: sharedAttrs.Apex_available})
ctx.CreateBazelTargetModuleWithRestrictions(staticProps,
@ -3002,7 +3002,7 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo
Bzl_load_location: fmt.Sprintf("//build/bazel/rules/cc:%s.bzl", modType),
}
tags := android.ApexAvailableTags(module)
tags := android.ApexAvailableTagsWithoutTestApexes(ctx, module)
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name(), Tags: tags}, attrs)
}