diff options
| author | 2023-02-10 11:27:46 -0800 | |
|---|---|---|
| committer | 2023-02-13 10:23:36 -0800 | |
| commit | fb11c1ce81f52ab67ccccacb4ce314ae29bbeeb7 (patch) | |
| tree | 87896a71cea308249520ec24883c50e7e7f0e023 | |
| parent | 871109e91d8ca892af72b061829f15f493813d63 (diff) | |
Add ConvertApexAvailableToTags
This is a more flexible version of ApexAvailableTags
that can be used for the aidl modules.
Bug: 260694842
Test: go test
Change-Id: Iddb15e737c19e95977f74e8c627d6044d8875746
| -rw-r--r-- | android/mutator.go | 23 | ||||
| -rw-r--r-- | android/mutator_test.go | 20 |
2 files changed, 34 insertions, 9 deletions
diff --git a/android/mutator.go b/android/mutator.go index 4e55609ae..4dacb8df8 100644 --- a/android/mutator.go +++ b/android/mutator.go @@ -709,24 +709,29 @@ func (t *topDownMutatorContext) CreateBazelTargetModuleWithRestrictions( // 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 + attr.Value = ConvertApexAvailableToTags(am.apexModuleBase().ApexAvailable()) } return attr } +func ConvertApexAvailableToTags(apexAvailable []string) []string { + if len(apexAvailable) == 0 { + // We need nil specifically to make bp2build not add the tags property at all, + // instead of adding it with an empty list + return nil + } + result := make([]string, 0, len(apexAvailable)) + for _, a := range apexAvailable { + result = append(result, "apex_available="+a) + } + return result +} + func (t *topDownMutatorContext) createBazelTargetModule( bazelProps bazel.BazelTargetModuleProperties, commonAttrs CommonAttributes, diff --git a/android/mutator_test.go b/android/mutator_test.go index 21eebd2c8..dbdfa3362 100644 --- a/android/mutator_test.go +++ b/android/mutator_test.go @@ -16,6 +16,7 @@ package android import ( "fmt" + "reflect" "strings" "testing" @@ -267,3 +268,22 @@ func TestNoCreateVariationsInFinalDeps(t *testing.T) { FixtureWithRootAndroidBp(`test {name: "foo"}`), ).RunTest(t) } + +func TestConvertApexAvailableToTags(t *testing.T) { + input := []string{ + "com.android.adbd", + "//apex_available:platform", + } + actual := ConvertApexAvailableToTags(input) + expected := []string{ + "apex_available=com.android.adbd", + "apex_available=//apex_available:platform", + } + if !reflect.DeepEqual(actual, expected) { + t.Errorf("Expected: %v, actual: %v", expected, actual) + } + + if ConvertApexAvailableToTags(nil) != nil { + t.Errorf("Expected providing nil to return nil") + } +} |