Add tests for core library neverallow rules am: b6c6bdd1c2

am: 28630e0c47

Change-Id: If9ac14fe90a21e80d8c7748cb505f53c3983d3c5
This commit is contained in:
Paul Duffin 2019-06-12 03:11:54 -07:00 committed by android-build-merger
commit a4973e8fec
2 changed files with 38 additions and 2 deletions

View File

@ -96,6 +96,9 @@ func createLibcoreRules() []*rule {
"external/icu", "external/icu",
"external/okhttp", "external/okhttp",
"external/wycheproof", "external/wycheproof",
// Not really a core library but still needs access to same capabilities.
"development",
} }
// Core library constraints. The no_standard_libs can only be used in core // Core library constraints. The no_standard_libs can only be used in core
@ -103,7 +106,7 @@ func createLibcoreRules() []*rule {
// visibility rules. // visibility rules.
rules := []*rule{ rules := []*rule{
neverallow(). neverallow().
notIn(append(coreLibraryProjects, "development")...). notIn(coreLibraryProjects...).
with("no_standard_libs", "true"), with("no_standard_libs", "true"),
} }

View File

@ -159,6 +159,38 @@ var neverallowTests = []struct {
}, },
expectedError: "java_device_for_host can only be used in whitelisted projects", expectedError: "java_device_for_host can only be used in whitelisted projects",
}, },
// Libcore rule tests
{
name: "no_standard_libs: true inside core libraries",
fs: map[string][]byte{
"libcore/Blueprints": []byte(`
java_library {
name: "inside_core_libraries",
no_standard_libs: true,
}`),
},
},
{
name: "no_standard_libs: true outside core libraries",
fs: map[string][]byte{
"Blueprints": []byte(`
java_library {
name: "outside_core_libraries",
no_standard_libs: true,
}`),
},
expectedError: "module \"outside_core_libraries\": violates neverallow",
},
{
name: "no_standard_libs: false",
fs: map[string][]byte{
"Blueprints": []byte(`
java_library {
name: "outside_core_libraries",
no_standard_libs: false,
}`),
},
},
} }
func TestNeverallow(t *testing.T) { func TestNeverallow(t *testing.T) {
@ -239,6 +271,7 @@ func (p *mockCcLibraryModule) GenerateAndroidBuildActions(ModuleContext) {
type mockJavaLibraryProperties struct { type mockJavaLibraryProperties struct {
Libs []string Libs []string
No_standard_libs *bool
} }
type mockJavaLibraryModule struct { type mockJavaLibraryModule struct {