diff options
author | 2022-11-22 16:51:21 -0800 | |
---|---|---|
committer | 2022-11-22 17:43:40 -0800 | |
commit | 2ced8c8a57010a57eb7136e585eec63aec48e91e (patch) | |
tree | 3c05cd5550c9889acb7bfda469364ae15421a461 | |
parent | ad8c092c08f5ef674758dd10e25e4356747bcfa5 (diff) |
Prevent duplicated license_kinds
Bazel fails when there are duplicate license_kinds.
Bug: 260148018
Test: go test
Change-Id: I47a27d37d66be947e4a744cd04a3cdcc0b000de4
-rw-r--r-- | android/license.go | 14 | ||||
-rw-r--r-- | android/license_test.go | 30 |
2 files changed, 42 insertions, 2 deletions
diff --git a/android/license.go b/android/license.go index cde5e6e6e..ab8431a89 100644 --- a/android/license.go +++ b/android/license.go @@ -15,10 +15,12 @@ package android import ( - "android/soong/bazel" "fmt" - "github.com/google/blueprint" "os" + + "github.com/google/blueprint" + + "android/soong/bazel" ) type licenseKindDependencyTag struct { @@ -101,6 +103,14 @@ func (m *licenseModule) ConvertWithBp2build(ctx TopDownMutatorContext) { } func (m *licenseModule) DepsMutator(ctx BottomUpMutatorContext) { + for i, license := range m.properties.License_kinds { + for j := i + 1; j < len(m.properties.License_kinds); j++ { + if license == m.properties.License_kinds[j] { + ctx.ModuleErrorf("Duplicated license kind: %q", license) + break + } + } + } ctx.AddVariationDependencies(nil, licenseKindTag, m.properties.License_kinds...) } diff --git a/android/license_test.go b/android/license_test.go index 7222cd741..89e7f06e8 100644 --- a/android/license_test.go +++ b/android/license_test.go @@ -90,6 +90,36 @@ var licenseTests = []struct { }, }, { + name: "must not duplicate license_kind", + fs: map[string][]byte{ + "top/Android.bp": []byte(` + license_kind { + name: "top_by_exception_only", + conditions: ["by_exception_only"], + visibility: ["//visibility:private"], + } + + license_kind { + name: "top_by_exception_only_2", + conditions: ["by_exception_only"], + visibility: ["//visibility:private"], + } + + license { + name: "top_proprietary", + license_kinds: [ + "top_by_exception_only", + "top_by_exception_only_2", + "top_by_exception_only" + ], + visibility: ["//visibility:public"], + }`), + }, + expectedErrors: []string{ + `top/Android.bp:14:5: module "top_proprietary": Duplicated license kind: "top_by_exception_only"`, + }, + }, + { name: "license_kind module must exist", fs: map[string][]byte{ "top/Android.bp": []byte(` |