Loading bazel/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ bootstrap_go_package { ], testSrcs: [ "aquery_test.go", "properties_test.go", ], pluginFor: [ "soong_build", Loading bazel/properties.go +26 −1 Original line number Diff line number Diff line Loading @@ -14,7 +14,10 @@ package bazel import "fmt" import ( "fmt" "sort" ) type bazelModuleProperties struct { // The label of the Bazel target replacing this Soong module. Loading Loading @@ -66,6 +69,28 @@ func (ll *LabelList) Append(other LabelList) { } } func UniqueBazelLabels(originalLabels []Label) []Label { uniqueLabelsSet := make(map[Label]bool) for _, l := range originalLabels { uniqueLabelsSet[l] = true } var uniqueLabels []Label for l, _ := range uniqueLabelsSet { uniqueLabels = append(uniqueLabels, l) } sort.SliceStable(uniqueLabels, func(i, j int) bool { return uniqueLabels[i].Label < uniqueLabels[j].Label }) return uniqueLabels } func UniqueBazelLabelList(originalLabelList LabelList) LabelList { var uniqueLabelList LabelList uniqueLabelList.Includes = UniqueBazelLabels(originalLabelList.Includes) uniqueLabelList.Excludes = UniqueBazelLabels(originalLabelList.Excludes) return uniqueLabelList } // StringListAttribute corresponds to the string_list Bazel attribute type with // support for additional metadata, like configurations. type StringListAttribute struct { Loading bazel/properties_test.go 0 → 100644 +89 −0 Original line number Diff line number Diff line // Copyright 2021 Google Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package bazel import ( "reflect" "testing" ) func TestUniqueBazelLabels(t *testing.T) { testCases := []struct { originalLabels []Label expectedUniqueLabels []Label }{ { originalLabels: []Label{ {Label: "a"}, {Label: "b"}, {Label: "a"}, {Label: "c"}, }, expectedUniqueLabels: []Label{ {Label: "a"}, {Label: "b"}, {Label: "c"}, }, }, } for _, tc := range testCases { actualUniqueLabels := UniqueBazelLabels(tc.originalLabels) if !reflect.DeepEqual(tc.expectedUniqueLabels, actualUniqueLabels) { t.Fatalf("Expected %v, got %v", tc.expectedUniqueLabels, actualUniqueLabels) } } } func TestUniqueBazelLabelList(t *testing.T) { testCases := []struct { originalLabelList LabelList expectedUniqueLabelList LabelList }{ { originalLabelList: LabelList{ Includes: []Label{ {Label: "a"}, {Label: "b"}, {Label: "a"}, {Label: "c"}, }, Excludes: []Label{ {Label: "x"}, {Label: "x"}, {Label: "y"}, {Label: "z"}, }, }, expectedUniqueLabelList: LabelList{ Includes: []Label{ {Label: "a"}, {Label: "b"}, {Label: "c"}, }, Excludes: []Label{ {Label: "x"}, {Label: "y"}, {Label: "z"}, }, }, }, } for _, tc := range testCases { actualUniqueLabelList := UniqueBazelLabelList(tc.originalLabelList) if !reflect.DeepEqual(tc.expectedUniqueLabelList, actualUniqueLabelList) { t.Fatalf("Expected %v, got %v", tc.expectedUniqueLabelList, actualUniqueLabelList) } } } Loading
bazel/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ bootstrap_go_package { ], testSrcs: [ "aquery_test.go", "properties_test.go", ], pluginFor: [ "soong_build", Loading
bazel/properties.go +26 −1 Original line number Diff line number Diff line Loading @@ -14,7 +14,10 @@ package bazel import "fmt" import ( "fmt" "sort" ) type bazelModuleProperties struct { // The label of the Bazel target replacing this Soong module. Loading Loading @@ -66,6 +69,28 @@ func (ll *LabelList) Append(other LabelList) { } } func UniqueBazelLabels(originalLabels []Label) []Label { uniqueLabelsSet := make(map[Label]bool) for _, l := range originalLabels { uniqueLabelsSet[l] = true } var uniqueLabels []Label for l, _ := range uniqueLabelsSet { uniqueLabels = append(uniqueLabels, l) } sort.SliceStable(uniqueLabels, func(i, j int) bool { return uniqueLabels[i].Label < uniqueLabels[j].Label }) return uniqueLabels } func UniqueBazelLabelList(originalLabelList LabelList) LabelList { var uniqueLabelList LabelList uniqueLabelList.Includes = UniqueBazelLabels(originalLabelList.Includes) uniqueLabelList.Excludes = UniqueBazelLabels(originalLabelList.Excludes) return uniqueLabelList } // StringListAttribute corresponds to the string_list Bazel attribute type with // support for additional metadata, like configurations. type StringListAttribute struct { Loading
bazel/properties_test.go 0 → 100644 +89 −0 Original line number Diff line number Diff line // Copyright 2021 Google Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package bazel import ( "reflect" "testing" ) func TestUniqueBazelLabels(t *testing.T) { testCases := []struct { originalLabels []Label expectedUniqueLabels []Label }{ { originalLabels: []Label{ {Label: "a"}, {Label: "b"}, {Label: "a"}, {Label: "c"}, }, expectedUniqueLabels: []Label{ {Label: "a"}, {Label: "b"}, {Label: "c"}, }, }, } for _, tc := range testCases { actualUniqueLabels := UniqueBazelLabels(tc.originalLabels) if !reflect.DeepEqual(tc.expectedUniqueLabels, actualUniqueLabels) { t.Fatalf("Expected %v, got %v", tc.expectedUniqueLabels, actualUniqueLabels) } } } func TestUniqueBazelLabelList(t *testing.T) { testCases := []struct { originalLabelList LabelList expectedUniqueLabelList LabelList }{ { originalLabelList: LabelList{ Includes: []Label{ {Label: "a"}, {Label: "b"}, {Label: "a"}, {Label: "c"}, }, Excludes: []Label{ {Label: "x"}, {Label: "x"}, {Label: "y"}, {Label: "z"}, }, }, expectedUniqueLabelList: LabelList{ Includes: []Label{ {Label: "a"}, {Label: "b"}, {Label: "c"}, }, Excludes: []Label{ {Label: "x"}, {Label: "y"}, {Label: "z"}, }, }, }, } for _, tc := range testCases { actualUniqueLabelList := UniqueBazelLabelList(tc.originalLabelList) if !reflect.DeepEqual(tc.expectedUniqueLabelList, actualUniqueLabelList) { t.Fatalf("Expected %v, got %v", tc.expectedUniqueLabelList, actualUniqueLabelList) } } }