Merge changes Ifbf9fe27,I41a6cd42,Ieae59efb

* changes:
  Allow some duplicates in merged jars
  Add support for java annotation processors
  Update java androidmk conversions
diff --git a/android/androidmk.go b/android/androidmk.go
index a403d8c..319f711 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -42,6 +42,7 @@
 	SubName    string
 	OutputFile OptionalPath
 	Disabled   bool
+	Include    string
 
 	Custom func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData)
 
@@ -163,6 +164,10 @@
 
 	data := provider.AndroidMk()
 
+	if data.Include == "" {
+		data.Include = "$(BUILD_PREBUILT)"
+	}
+
 	// Make does not understand LinuxBionic
 	if amod.Os() == LinuxBionic {
 		return nil
@@ -268,5 +273,5 @@
 		extra(w, data.OutputFile.Path())
 	}
 
-	fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
+	fmt.Fprintln(w, "include "+data.Include)
 }
diff --git a/cc/linker.go b/cc/linker.go
index 678b992..59c979d 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -213,6 +213,18 @@
 			CheckBadHostLdlibs(ctx, "host_ldlibs", linker.Properties.Host_ldlibs)
 
 			flags.LdFlags = append(flags.LdFlags, linker.Properties.Host_ldlibs...)
+
+			if !ctx.Windows() {
+				// Add -ldl, -lpthread and -lrt to host builds to match the default behavior of device
+				// builds
+				flags.LdFlags = append(flags.LdFlags,
+					"-ldl",
+					"-lpthread",
+				)
+				if !ctx.Darwin() {
+					flags.LdFlags = append(flags.LdFlags, "-lrt")
+				}
+			}
 		}
 	}
 
diff --git a/cc/test.go b/cc/test.go
index a52e94a..1501a26 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -337,8 +337,8 @@
 
 func (benchmark *benchmarkDecorator) install(ctx ModuleContext, file android.Path) {
 	benchmark.data = ctx.ExpandSources(benchmark.Properties.Data, nil)
-	benchmark.binaryDecorator.baseInstaller.dir = filepath.Join("nativetest", ctx.ModuleName())
-	benchmark.binaryDecorator.baseInstaller.dir64 = filepath.Join("nativetest64", ctx.ModuleName())
+	benchmark.binaryDecorator.baseInstaller.dir = filepath.Join("benchmarktest", ctx.ModuleName())
+	benchmark.binaryDecorator.baseInstaller.dir64 = filepath.Join("benchmarktest64", ctx.ModuleName())
 	benchmark.binaryDecorator.baseInstaller.install(ctx, file)
 }
 
@@ -355,7 +355,7 @@
 
 	module, binary := NewBinary(hod)
 	module.multilib = android.MultilibBoth
-	binary.baseInstaller = NewTestInstaller()
+	binary.baseInstaller = NewBaseInstaller("benchmarktest", "benchmarktest64", InstallInData)
 
 	benchmark := &benchmarkDecorator{
 		binaryDecorator: binary,
diff --git a/java/androidmk.go b/java/androidmk.go
index c383a0e..680d864 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -26,9 +26,9 @@
 	return android.AndroidMkData{
 		Class:      "JAVA_LIBRARIES",
 		OutputFile: android.OptionalPathForPath(library.outputFile),
+		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
 		Extra: []android.AndroidMkExtraFunc{
 			func(w io.Writer, outputFile android.Path) {
-				fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := .jar")
 				if library.properties.Installable != nil && *library.properties.Installable == false {
 					fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
 				}
@@ -41,9 +41,9 @@
 	return android.AndroidMkData{
 		Class:      "JAVA_LIBRARIES",
 		OutputFile: android.OptionalPathForPath(prebuilt.combinedClasspathFile),
+		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
 		Extra: []android.AndroidMkExtraFunc{
 			func(w io.Writer, outputFile android.Path) {
-				fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := .jar")
 				fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
 			},
 		},
@@ -54,10 +54,11 @@
 	return android.AndroidMkData{
 		Class:      "JAVA_LIBRARIES",
 		OutputFile: android.OptionalPathForPath(binary.outputFile),
-		SubName:    ".jar",
+		Include:    "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
 		Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
 			android.WriteAndroidMkData(w, data)
 
+			fmt.Fprintln(w, "jar_installed_module := $(LOCAL_INSTALLED_MODULE)")
 			fmt.Fprintln(w, "include $(CLEAR_VARS)")
 			fmt.Fprintln(w, "LOCAL_MODULE := "+name)
 			fmt.Fprintln(w, "LOCAL_MODULE_CLASS := EXECUTABLES")
@@ -65,9 +66,12 @@
 				fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
 			}
 			fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
-			fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+name+".jar")
-			fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE := "+binary.wrapperFile.String())
+			fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", binary.wrapperFile.String())
 			fmt.Fprintln(w, "include $(BUILD_PREBUILT)")
+
+			// Ensure that the wrapper script timestamp is always updated when the jar is updated
+			fmt.Fprintln(w, "$(LOCAL_INSTALLED_MODULE): $(jar_installed_module)")
+			fmt.Fprintln(w, "jar_installed_module :=")
 		},
 	}
 }
diff --git a/root.bp b/root.bp
index d91da64..f27d28b 100644
--- a/root.bp
+++ b/root.bp
@@ -37,5 +37,6 @@
     "test/vts",
     "test/vts-testcase/*",
     "tools/*",
+    "toolchain/*",
     "vendor/*/*",
 ]
diff --git a/ui/build/config.go b/ui/build/config.go
index 1c2f73b..2b0da4d 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -403,11 +403,7 @@
 }
 
 func (c *configImpl) ProductOut() string {
-	if buildType, ok := c.environ.Get("TARGET_BUILD_TYPE"); ok && buildType == "debug" {
-		return filepath.Join(c.OutDir(), "debug", "target", "product", c.TargetDevice())
-	} else {
-		return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice())
-	}
+	return filepath.Join(c.OutDir(), "target", "product", c.TargetDevice())
 }
 
 func (c *configImpl) DevicePreviousProductConfig() string {
@@ -415,11 +411,7 @@
 }
 
 func (c *configImpl) hostOutRoot() string {
-	if buildType, ok := c.environ.Get("HOST_BUILD_TYPE"); ok && buildType == "debug" {
-		return filepath.Join(c.OutDir(), "debug", "host")
-	} else {
-		return filepath.Join(c.OutDir(), "host")
-	}
+	return filepath.Join(c.OutDir(), "host")
 }
 
 func (c *configImpl) HostOut() string {