From b6c6bdd1c2822e03228a46cf4420f3253e0b5280 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 7 Jun 2019 11:43:55 +0100 Subject: [PATCH] Add tests for core library neverallow rules Bug: 134566750 Test: m Change-Id: I65e2afdf726937c29fc4f62a317024dc133254bf --- android/neverallow.go | 5 ++++- android/neverallow_test.go | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/android/neverallow.go b/android/neverallow.go index 93144830e..ee3bf4a5e 100644 --- a/android/neverallow.go +++ b/android/neverallow.go @@ -95,6 +95,9 @@ func createLibcoreRules() []*rule { "external/icu", "external/okhttp", "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 @@ -102,7 +105,7 @@ func createLibcoreRules() []*rule { // visibility rules. rules := []*rule{ neverallow(). - notIn(append(coreLibraryProjects, "development")...). + notIn(coreLibraryProjects...). with("no_standard_libs", "true"), } diff --git a/android/neverallow_test.go b/android/neverallow_test.go index 00c51eaab..c60de217c 100644 --- a/android/neverallow_test.go +++ b/android/neverallow_test.go @@ -148,6 +148,38 @@ var neverallowTests = []struct { }, 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) { @@ -227,7 +259,8 @@ func (p *mockCcLibraryModule) GenerateAndroidBuildActions(ModuleContext) { } type mockJavaLibraryProperties struct { - Libs []string + Libs []string + No_standard_libs *bool } type mockJavaLibraryModule struct {