Convert apex_available (for supported modules) to bazel tags.

The tags will then be read by an aspect applied from apex attributes to
validate that the deps are explicitly opt-in to the appropriate apex.

The semantics of this is the same as the Soong apex_available property.

This also adds the "base_apex_name" attr to override_apex conversion so
that apex_available checks continue to work on the non-Google and non-Go
apex names.

Test: presubmits
Fixes: 218841706
Change-Id: I19b3637da9aa47573b252d74f62b601fbdc3784d
This commit is contained in:
Jingwen Chen
2022-11-29 12:07:45 +00:00
parent cdea74d96c
commit c4c34e1eab
8 changed files with 134 additions and 34 deletions

View File

@@ -705,6 +705,28 @@ func (t *topDownMutatorContext) CreateBazelTargetModuleWithRestrictions(
t.createBazelTargetModule(bazelProps, commonAttrs, attrs, enabledProperty)
}
// ApexAvailableTags converts the apex_available property value of an ApexModule
// module and returns it as a list of keyed tags.
func ApexAvailableTags(mod Module) bazel.StringListAttribute {
attr := bazel.StringListAttribute{}
tags := []string{}
// Transform specific attributes into tags.
if am, ok := mod.(ApexModule); ok {
// TODO(b/218841706): hidl_interface has the apex_available prop, but it's
// defined directly as a prop and not via ApexModule, so this doesn't
// pick those props up.
// TODO(b/260694842): This does not pick up aidl_interface.backend.ndk.apex_available.
for _, a := range am.apexModuleBase().ApexAvailable() {
tags = append(tags, "apex_available="+a)
}
}
if len(tags) > 0 {
// This avoids creating a tags attr with an empty list if there are no tags.
attr.Value = tags
}
return attr
}
func (t *topDownMutatorContext) createBazelTargetModule(
bazelProps bazel.BazelTargetModuleProperties,
commonAttrs CommonAttributes,