Merge "Never allow java_library_host with no_standard_libs: true" am: 393590d8a8
am: 3321670746

Change-Id: Iebd7f4cd4979860ea1b2f9433373546c114d2160
diff --git a/android/neverallow.go b/android/neverallow.go
index 9cfa0eb..8d2f778 100644
--- a/android/neverallow.go
+++ b/android/neverallow.go
@@ -53,6 +53,7 @@
 	rules = append(rules, createLibcoreRules()...)
 	rules = append(rules, createMediaRules()...)
 	rules = append(rules, createJavaDeviceForHostRules()...)
+	rules = append(rules, createJavaLibraryHostRules()...)
 	return rules
 }
 
@@ -136,6 +137,15 @@
 	}
 }
 
+func createJavaLibraryHostRules() []*rule {
+	return []*rule{
+		neverallow().
+			moduleType("java_library_host").
+			with("no_standard_libs", "true").
+			because("no_standard_libs makes no sense with java_library_host"),
+	}
+}
+
 func neverallowMutator(ctx BottomUpMutatorContext) {
 	m, ok := ctx.Module().(Module)
 	if !ok {
diff --git a/android/neverallow_test.go b/android/neverallow_test.go
index 53436c2..eea7a39 100644
--- a/android/neverallow_test.go
+++ b/android/neverallow_test.go
@@ -189,6 +189,18 @@
 				}`),
 		},
 	},
+	// java_library_host rule tests
+	{
+		name: "java_library_host with no_standard_libs: true",
+		fs: map[string][]byte{
+			"libcore/Blueprints": []byte(`
+				java_library_host {
+					name: "inside_core_libraries",
+					no_standard_libs: true,
+				}`),
+		},
+		expectedError: "module \"inside_core_libraries\": violates neverallow",
+	},
 }
 
 func TestNeverallow(t *testing.T) {
@@ -211,6 +223,7 @@
 	ctx := NewTestContext()
 	ctx.RegisterModuleType("cc_library", ModuleFactoryAdaptor(newMockCcLibraryModule))
 	ctx.RegisterModuleType("java_library", ModuleFactoryAdaptor(newMockJavaLibraryModule))
+	ctx.RegisterModuleType("java_library_host", ModuleFactoryAdaptor(newMockJavaLibraryModule))
 	ctx.RegisterModuleType("java_device_for_host", ModuleFactoryAdaptor(newMockJavaLibraryModule))
 	ctx.PostDepsMutators(registerNeverallowMutator)
 	ctx.Register()
diff --git a/java/sdk_test.go b/java/sdk_test.go
index 142d6f5..23d7a98 100644
--- a/java/sdk_test.go
+++ b/java/sdk_test.go
@@ -137,13 +137,6 @@
 			classpath:     []string{},
 		},
 		{
-			name:       "host nostdlib",
-			moduleType: "java_library_host",
-			host:       android.Host,
-			properties: `no_standard_libs: true`,
-			classpath:  []string{},
-		},
-		{
 
 			name:          "host supported default",
 			host:          android.Host,