2021-01-07 04:34:31 +01:00
|
|
|
package android
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2021-03-03 01:42:36 +01:00
|
|
|
// Common test set up for license tests.
|
2021-03-20 01:36:14 +01:00
|
|
|
var prepareForLicenseTest = GroupFixturePreparers(
|
2021-03-03 01:42:36 +01:00
|
|
|
// General preparers in alphabetical order.
|
|
|
|
PrepareForTestWithDefaults,
|
2021-05-06 17:39:27 +02:00
|
|
|
PrepareForTestWithLicenses,
|
2021-03-03 01:42:36 +01:00
|
|
|
PrepareForTestWithOverrides,
|
|
|
|
PrepareForTestWithPackageModule,
|
|
|
|
PrepareForTestWithPrebuilts,
|
|
|
|
PrepareForTestWithVisibility,
|
|
|
|
|
|
|
|
// Additional test specific stuff
|
|
|
|
prepareForTestWithFakePrebuiltModules,
|
|
|
|
FixtureMergeEnv(map[string]string{"ANDROID_REQUIRE_LICENSES": "1"}),
|
|
|
|
)
|
|
|
|
|
2021-01-07 04:34:31 +01:00
|
|
|
var licenseTests = []struct {
|
|
|
|
name string
|
2021-03-03 01:42:36 +01:00
|
|
|
fs MockFS
|
2021-01-07 04:34:31 +01:00
|
|
|
expectedErrors []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "license must not accept licenses property",
|
|
|
|
fs: map[string][]byte{
|
2021-09-02 11:46:24 +02:00
|
|
|
"top/Android.bp": []byte(`
|
2021-01-07 04:34:31 +01:00
|
|
|
license {
|
|
|
|
name: "top_license",
|
|
|
|
visibility: ["//visibility:private"],
|
|
|
|
licenses: ["other_license"],
|
|
|
|
}`),
|
|
|
|
},
|
|
|
|
expectedErrors: []string{
|
2021-09-02 11:46:24 +02:00
|
|
|
`top/Android.bp:5:14: unrecognized property "licenses"`,
|
2021-01-07 04:34:31 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "private license",
|
|
|
|
fs: map[string][]byte{
|
2021-09-02 11:46:24 +02:00
|
|
|
"top/Android.bp": []byte(`
|
2021-01-07 04:34:31 +01:00
|
|
|
license_kind {
|
|
|
|
name: "top_notice",
|
|
|
|
conditions: ["notice"],
|
|
|
|
visibility: ["//visibility:private"],
|
|
|
|
}
|
|
|
|
|
|
|
|
license {
|
|
|
|
name: "top_allowed_as_notice",
|
|
|
|
license_kinds: ["top_notice"],
|
|
|
|
visibility: ["//visibility:private"],
|
|
|
|
}`),
|
2021-09-02 11:46:24 +02:00
|
|
|
"other/Android.bp": []byte(`
|
2021-01-07 04:34:31 +01:00
|
|
|
rule {
|
|
|
|
name: "arule",
|
|
|
|
licenses: ["top_allowed_as_notice"],
|
|
|
|
}`),
|
2021-09-02 11:46:24 +02:00
|
|
|
"yetmore/Android.bp": []byte(`
|
2021-01-07 04:34:31 +01:00
|
|
|
package {
|
|
|
|
default_applicable_licenses: ["top_allowed_as_notice"],
|
|
|
|
}`),
|
|
|
|
},
|
|
|
|
expectedErrors: []string{
|
2021-09-02 11:46:24 +02:00
|
|
|
`other/Android.bp:2:5: module "arule": depends on //top:top_allowed_as_notice ` +
|
2021-01-07 04:34:31 +01:00
|
|
|
`which is not visible to this module`,
|
2021-09-02 11:46:24 +02:00
|
|
|
`yetmore/Android.bp:2:5: module "//yetmore": depends on //top:top_allowed_as_notice ` +
|
2021-01-07 04:34:31 +01:00
|
|
|
`which is not visible to this module`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "must reference license_kind module",
|
|
|
|
fs: map[string][]byte{
|
2021-09-02 11:46:24 +02:00
|
|
|
"top/Android.bp": []byte(`
|
2021-01-07 04:34:31 +01:00
|
|
|
rule {
|
|
|
|
name: "top_by_exception_only",
|
|
|
|
}
|
|
|
|
|
|
|
|
license {
|
|
|
|
name: "top_proprietary",
|
|
|
|
license_kinds: ["top_by_exception_only"],
|
|
|
|
visibility: ["//visibility:public"],
|
|
|
|
}`),
|
|
|
|
},
|
|
|
|
expectedErrors: []string{
|
2021-09-02 11:46:24 +02:00
|
|
|
`top/Android.bp:6:5: module "top_proprietary": license_kinds property ` +
|
2021-01-07 04:34:31 +01:00
|
|
|
`"top_by_exception_only" is not a license_kind module`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "license_kind module must exist",
|
|
|
|
fs: map[string][]byte{
|
2021-09-02 11:46:24 +02:00
|
|
|
"top/Android.bp": []byte(`
|
2021-01-07 04:34:31 +01:00
|
|
|
license {
|
|
|
|
name: "top_notice_allowed",
|
|
|
|
license_kinds: ["top_notice"],
|
|
|
|
visibility: ["//visibility:public"],
|
|
|
|
}`),
|
|
|
|
},
|
|
|
|
expectedErrors: []string{
|
2021-09-02 11:46:24 +02:00
|
|
|
`top/Android.bp:2:5: "top_notice_allowed" depends on undefined module "top_notice"`,
|
2021-01-07 04:34:31 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "public license",
|
|
|
|
fs: map[string][]byte{
|
2021-09-02 11:46:24 +02:00
|
|
|
"top/Android.bp": []byte(`
|
2021-01-07 04:34:31 +01:00
|
|
|
license_kind {
|
|
|
|
name: "top_by_exception_only",
|
|
|
|
conditions: ["by_exception_only"],
|
|
|
|
visibility: ["//visibility:private"],
|
|
|
|
}
|
|
|
|
|
|
|
|
license {
|
|
|
|
name: "top_proprietary",
|
|
|
|
license_kinds: ["top_by_exception_only"],
|
|
|
|
visibility: ["//visibility:public"],
|
|
|
|
}`),
|
2021-09-02 11:46:24 +02:00
|
|
|
"other/Android.bp": []byte(`
|
2021-01-07 04:34:31 +01:00
|
|
|
rule {
|
|
|
|
name: "arule",
|
|
|
|
licenses: ["top_proprietary"],
|
|
|
|
}`),
|
2021-09-02 11:46:24 +02:00
|
|
|
"yetmore/Android.bp": []byte(`
|
2021-01-07 04:34:31 +01:00
|
|
|
package {
|
|
|
|
default_applicable_licenses: ["top_proprietary"],
|
|
|
|
}`),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple licenses",
|
|
|
|
fs: map[string][]byte{
|
2021-09-02 11:46:24 +02:00
|
|
|
"top/Android.bp": []byte(`
|
2021-01-07 04:34:31 +01:00
|
|
|
package {
|
|
|
|
default_applicable_licenses: ["top_proprietary"],
|
|
|
|
}
|
|
|
|
|
|
|
|
license_kind {
|
|
|
|
name: "top_notice",
|
|
|
|
conditions: ["notice"],
|
|
|
|
}
|
|
|
|
|
|
|
|
license_kind {
|
|
|
|
name: "top_by_exception_only",
|
|
|
|
conditions: ["by_exception_only"],
|
|
|
|
visibility: ["//visibility:public"],
|
|
|
|
}
|
|
|
|
|
|
|
|
license {
|
|
|
|
name: "top_allowed_as_notice",
|
|
|
|
license_kinds: ["top_notice"],
|
|
|
|
}
|
|
|
|
|
|
|
|
license {
|
|
|
|
name: "top_proprietary",
|
|
|
|
license_kinds: ["top_by_exception_only"],
|
|
|
|
visibility: ["//visibility:public"],
|
|
|
|
}
|
|
|
|
rule {
|
|
|
|
name: "myrule",
|
|
|
|
licenses: ["top_allowed_as_notice", "top_proprietary"]
|
|
|
|
}`),
|
2021-09-02 11:46:24 +02:00
|
|
|
"other/Android.bp": []byte(`
|
2021-01-07 04:34:31 +01:00
|
|
|
rule {
|
|
|
|
name: "arule",
|
|
|
|
licenses: ["top_proprietary"],
|
|
|
|
}`),
|
2021-09-02 11:46:24 +02:00
|
|
|
"yetmore/Android.bp": []byte(`
|
2021-01-07 04:34:31 +01:00
|
|
|
package {
|
|
|
|
default_applicable_licenses: ["top_proprietary"],
|
|
|
|
}`),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLicense(t *testing.T) {
|
|
|
|
for _, test := range licenseTests {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
2021-03-03 01:42:36 +01:00
|
|
|
// Customize the common license text fixture factory.
|
2021-03-20 01:36:14 +01:00
|
|
|
GroupFixturePreparers(
|
|
|
|
prepareForLicenseTest,
|
2021-03-03 01:42:36 +01:00
|
|
|
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
|
|
|
ctx.RegisterModuleType("rule", newMockRuleModule)
|
|
|
|
}),
|
|
|
|
test.fs.AddToFixture(),
|
|
|
|
).
|
|
|
|
ExtendWithErrorHandler(FixtureExpectsAllErrorsToMatchAPattern(test.expectedErrors)).
|
|
|
|
RunTest(t)
|
2021-01-07 04:34:31 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 01:42:36 +01:00
|
|
|
func testLicense(t *testing.T, fs MockFS, expectedErrors []string) {
|
2021-01-07 04:34:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type mockRuleModule struct {
|
|
|
|
ModuleBase
|
|
|
|
DefaultableModuleBase
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMockRuleModule() Module {
|
|
|
|
m := &mockRuleModule{}
|
|
|
|
InitAndroidModule(m)
|
|
|
|
InitDefaultableModule(m)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *mockRuleModule) GenerateAndroidBuildActions(ModuleContext) {
|
|
|
|
}
|