Merge "Add apex stub lib to LOCAL_SHARED_LIBRARIES"
diff --git a/OWNERS b/OWNERS
index 892beb7..7983c19 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,4 +1,4 @@
-per-file * = ccross@android.com,dwillemsen@google.com,jungjw@google.com
+per-file * = asmundak@google.com,ccross@android.com,dwillemsen@google.com,jungjw@google.com
 per-file ndk_*.go, *gen_stub_libs.py = danalbert@google.com
 per-file clang.go,global.go = srhines@google.com, chh@google.com, pirama@google.com, yikong@google.com
 per-file tidy.go = srhines@google.com, chh@google.com
diff --git a/README.md b/README.md
index 16d3cce..74d49bb 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,10 @@
 replaces Android.mk files with Android.bp files, which are JSON-like simple
 declarative descriptions of modules to build.
 
+See [Simple Build
+Configuration](https://source.android.com/compatibility/tests/development/blueprints)
+on source.android.com to read how Soong is configured for testing.
+
 ## Android.bp file format
 
 By design, Android.bp files are very simple.  There are no conditionals or
diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go
index a28cf49..71eb19b 100644
--- a/androidmk/cmd/androidmk/android.go
+++ b/androidmk/cmd/androidmk/android.go
@@ -803,6 +803,11 @@
 	"BUILD_HOST_JAVA_LIBRARY":        "java_library_host",
 	"BUILD_HOST_DALVIK_JAVA_LIBRARY": "java_library_host_dalvik",
 	"BUILD_PACKAGE":                  "android_app",
+
+	"BUILD_CTS_SUPPORT_PACKAGE":     "cts_support_package",     // will be rewritten to android_test by bpfix
+	"BUILD_CTS_PACKAGE":             "cts_package",             // will be rewritten to android_test by bpfix
+	"BUILD_CTS_TARGET_JAVA_LIBRARY": "cts_target_java_library", // will be rewritten to java_library by bpfix
+	"BUILD_CTS_HOST_JAVA_LIBRARY":   "cts_host_java_library",   // will be rewritten to java_library_host by bpfix
 }
 
 var prebuiltTypes = map[string]string{
diff --git a/androidmk/cmd/androidmk/androidmk_test.go b/androidmk/cmd/androidmk/androidmk_test.go
index c750f22..9874cb2 100644
--- a/androidmk/cmd/androidmk/androidmk_test.go
+++ b/androidmk/cmd/androidmk/androidmk_test.go
@@ -752,6 +752,61 @@
 }
 `,
 	},
+	{
+		desc: "BUILD_CTS_SUPPORT_PACKAGE",
+		in: `
+include $(CLEAR_VARS)
+LOCAL_PACKAGE_NAME := FooTest
+LOCAL_COMPATIBILITY_SUITE := cts
+include $(BUILD_CTS_SUPPORT_PACKAGE)
+`,
+		expected: `
+android_test {
+    name: "FooTest",
+    defaults: ["cts_support_defaults"],
+    test_suites: ["cts"],
+}
+`,
+	},
+	{
+		desc: "BUILD_CTS_PACKAGE",
+		in: `
+include $(CLEAR_VARS)
+LOCAL_PACKAGE_NAME := FooTest
+LOCAL_COMPATIBILITY_SUITE := cts
+include $(BUILD_CTS_PACKAGE)
+`,
+		expected: `
+android_test {
+    name: "FooTest",
+    defaults: ["cts_defaults"],
+    test_suites: ["cts"],
+}
+`,
+	},
+	{
+		desc: "BUILD_CTS_*_JAVA_LIBRARY",
+		in: `
+include $(CLEAR_VARS)
+LOCAL_MODULE := foolib
+include $(BUILD_CTS_TARGET_JAVA_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := foolib-host
+include $(BUILD_CTS_HOST_JAVA_LIBRARY)
+`,
+		expected: `
+java_library {
+    name: "foolib",
+    defaults: ["cts_defaults"],
+}
+
+java_library_host {
+    name: "foolib-host",
+    defaults: ["cts_defaults"],
+}
+`,
+	},
 }
 
 func TestEndToEnd(t *testing.T) {
diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go
index a4723fb..6a75517 100644
--- a/bpfix/bpfix/bpfix.go
+++ b/bpfix/bpfix/bpfix.go
@@ -63,6 +63,10 @@
 		fix:  rewriteIncorrectAndroidmkPrebuilts,
 	},
 	{
+		name: "rewriteCtsModuleTypes",
+		fix:  rewriteCtsModuleTypes,
+	},
+	{
 		name: "rewriteIncorrectAndroidmkAndroidLibraries",
 		fix:  rewriteIncorrectAndroidmkAndroidLibraries,
 	},
@@ -237,6 +241,52 @@
 	return nil
 }
 
+func rewriteCtsModuleTypes(f *Fixer) error {
+	for _, def := range f.tree.Defs {
+		mod, ok := def.(*parser.Module)
+		if !ok {
+			continue
+		}
+
+		if mod.Type != "cts_support_package" && mod.Type != "cts_package" &&
+			mod.Type != "cts_target_java_library" &&
+			mod.Type != "cts_host_java_library" {
+
+			continue
+		}
+
+		var defStr string
+		switch mod.Type {
+		case "cts_support_package":
+			mod.Type = "android_test"
+			defStr = "cts_support_defaults"
+		case "cts_package":
+			mod.Type = "android_test"
+			defStr = "cts_defaults"
+		case "cts_target_java_library":
+			mod.Type = "java_library"
+			defStr = "cts_defaults"
+		case "cts_host_java_library":
+			mod.Type = "java_library_host"
+			defStr = "cts_defaults"
+		}
+
+		defaults := &parser.Property{
+			Name: "defaults",
+			Value: &parser.List{
+				Values: []parser.Expression{
+					&parser.String{
+						Value: defStr,
+					},
+				},
+			},
+		}
+		mod.Properties = append(mod.Properties, defaults)
+	}
+
+	return nil
+}
+
 func rewriteIncorrectAndroidmkAndroidLibraries(f *Fixer) error {
 	for _, def := range f.tree.Defs {
 		mod, ok := def.(*parser.Module)
diff --git a/bpfix/bpfix/bpfix_test.go b/bpfix/bpfix/bpfix_test.go
index 0469faf..5224ee3 100644
--- a/bpfix/bpfix/bpfix_test.go
+++ b/bpfix/bpfix/bpfix_test.go
@@ -621,3 +621,74 @@
 		})
 	}
 }
+
+func TestRewriteCtsModuleTypes(t *testing.T) {
+	tests := []struct {
+		name string
+		in   string
+		out  string
+	}{
+		{
+			name: "cts_support_package",
+			in: `
+				cts_support_package {
+					name: "foo",
+				}
+			`,
+			out: `
+				android_test {
+					name: "foo",
+					defaults: ["cts_support_defaults"],
+				}
+			`,
+		},
+		{
+			name: "cts_package",
+			in: `
+				cts_package {
+					name: "foo",
+				}
+			`,
+			out: `
+				android_test {
+					name: "foo",
+					defaults: ["cts_defaults"],
+				}
+			`,
+		},
+		{
+			name: "cts_target_java_library",
+			in: `
+				cts_target_java_library {
+					name: "foo",
+				}
+			`,
+			out: `
+				java_library {
+					name: "foo",
+					defaults: ["cts_defaults"],
+				}
+			`,
+		},
+		{
+			name: "cts_host_java_library",
+			in: `
+				cts_host_java_library {
+					name: "foo",
+				}
+			`,
+			out: `
+				java_library_host {
+					name: "foo",
+					defaults: ["cts_defaults"],
+				}
+			`,
+		},
+	}
+
+	for _, test := range tests {
+		t.Run(test.name, func(t *testing.T) {
+			runPass(t, test.in, test.out, rewriteCtsModuleTypes)
+		})
+	}
+}
diff --git a/cc/linker.go b/cc/linker.go
index eb71268..cda392d 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -240,11 +240,11 @@
 			deps.LateStaticLibs = append(deps.LateStaticLibs, "libgcc")
 		}
 
-		var systemSharedLibs []string
-		if !ctx.useSdk() && !ctx.useVndk() {
-			systemSharedLibs = linker.Properties.System_shared_libs
-		}
+		systemSharedLibs := linker.Properties.System_shared_libs
 		if systemSharedLibs == nil {
+			// Provide a default system_shared_libs if it is unspecified. Note: If an
+			// empty list [] is specified, it implies that the module declines the
+			// default system_shared_libs.
 			systemSharedLibs = []string{"libc", "libm", "libdl"}
 		}
 
diff --git a/java/hiddenapi.go b/java/hiddenapi.go
index 7378b64..de72e7c 100644
--- a/java/hiddenapi.go
+++ b/java/hiddenapi.go
@@ -78,11 +78,6 @@
 }, "flags", "tmpDir")
 
 func hiddenAPIEncodeDex(ctx android.ModuleContext, output android.WritablePath, dexInput android.WritablePath) {
-	if ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
-		output = dexInput
-		return
-	}
-
 	flags := &bootImagePath{ctx.Config().HiddenAPIFlags()}
 
 	ctx.Build(pctx, android.BuildParams{
diff --git a/java/java.go b/java/java.go
index 49095ca..209d0a7 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1180,15 +1180,17 @@
 		}
 
 		// Hidden API CSV generation and dex encoding
-		isBootJar := inList(ctx.ModuleName(), ctx.Config().BootJars())
-		if isBootJar || inList(ctx.ModuleName(), ctx.Config().HiddenAPIExtraAppUsageJars()) {
-			// Derive the greylist from classes jar.
-			hiddenAPIGenerateCSV(ctx, j.implementationJarFile)
-		}
-		if isBootJar {
-			hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", jarName)
-			hiddenAPIEncodeDex(ctx, hiddenAPIJar, dexOutputFile)
-			dexOutputFile = hiddenAPIJar
+		if !ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
+			isBootJar := inList(ctx.ModuleName(), ctx.Config().BootJars())
+			if isBootJar || inList(ctx.ModuleName(), ctx.Config().HiddenAPIExtraAppUsageJars()) {
+				// Derive the greylist from classes jar.
+				hiddenAPIGenerateCSV(ctx, j.implementationJarFile)
+			}
+			if isBootJar {
+				hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", jarName)
+				hiddenAPIEncodeDex(ctx, hiddenAPIJar, dexOutputFile)
+				dexOutputFile = hiddenAPIJar
+			}
 		}
 
 		// merge dex jar with resources if necessary
diff --git a/ui/build/paths/config.go b/ui/build/paths/config.go
index b2d7a8a..1c0ee34 100644
--- a/ui/build/paths/config.go
+++ b/ui/build/paths/config.go
@@ -113,7 +113,6 @@
 	"timeout":   Allowed,
 	"tr":        Allowed,
 	"unzip":     Allowed,
-	"wc":        Allowed,
 	"which":     Allowed,
 	"xz":        Allowed,
 	"zip":       Allowed,
@@ -174,6 +173,7 @@
 	"uname":     Toybox,
 	"uniq":      Toybox,
 	"unix2dos":  Toybox,
+	"wc":        Toybox,
 	"whoami":    Toybox,
 	"xargs":     Toybox,
 	"xxd":       Toybox,