Prevent duplicated license_kinds am: 2ced8c8a57 am: 655af89517

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2313938

Change-Id: Ica42441b87d5d977797c6aadeb248ce6a619b4a8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Cole Faust
2022-11-23 08:57:31 +00:00
committed by Automerger Merge Worker
2 changed files with 42 additions and 2 deletions

View File

@@ -15,10 +15,12 @@
package android package android
import ( import (
"android/soong/bazel"
"fmt" "fmt"
"github.com/google/blueprint"
"os" "os"
"github.com/google/blueprint"
"android/soong/bazel"
) )
type licenseKindDependencyTag struct { type licenseKindDependencyTag struct {
@@ -101,6 +103,14 @@ func (m *licenseModule) ConvertWithBp2build(ctx TopDownMutatorContext) {
} }
func (m *licenseModule) DepsMutator(ctx BottomUpMutatorContext) { 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...) ctx.AddVariationDependencies(nil, licenseKindTag, m.properties.License_kinds...)
} }

View File

@@ -89,6 +89,36 @@ var licenseTests = []struct {
`"top_by_exception_only" is not a license_kind module`, `"top_by_exception_only" is not a license_kind module`,
}, },
}, },
{
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", name: "license_kind module must exist",
fs: map[string][]byte{ fs: map[string][]byte{