Ignore test apexes from bp2build generated tags
The core problem I am trying to solve is making sure that stub libraries in Bazel have a single apex available. In Soong, this will be enforced using some graph walk which is not easy to port to Bazel. However, we might need to revisit this when we build the enforcement mechanism in Bazel. We likely need a `test_for` on the top level apex_test Bazel rule so that the test apex is _allowed_ to link against impl of the library it is trying to test. (This CL retricts this to cc_library, I can expand this to other modules if this is the right approach.) Bug: 277651159 Change-Id: Iaeec22c5626df79a33785c766ed29102b1da403e
This commit is contained in:
@@ -758,6 +758,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,
|
||||
|
Reference in New Issue
Block a user