Merge "Add LOCAL_OVERRIDES_PACKAGES support to androidmk."
diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go
index 24a38c9..a4723fb 100644
--- a/bpfix/bpfix/bpfix.go
+++ b/bpfix/bpfix/bpfix.go
@@ -205,6 +205,11 @@
 		if mod.Type != "java_import" {
 			continue
 		}
+		host, _ := getLiteralBoolPropertyValue(mod, "host")
+		if host {
+			mod.Type = "java_import_host"
+			removeProperty(mod, "host")
+		}
 		srcs, ok := getLiteralListProperty(mod, "srcs")
 		if !ok {
 			continue
@@ -705,6 +710,24 @@
 	return stringValue.Value, true
 }
 
+func getLiteralBoolProperty(mod *parser.Module, name string) (b *parser.Bool, found bool) {
+	prop, ok := mod.GetProperty(name)
+	if !ok {
+		return nil, false
+	}
+	b, ok = prop.Value.(*parser.Bool)
+	return b, ok
+}
+
+func getLiteralBoolPropertyValue(mod *parser.Module, name string) (s bool, found bool) {
+	boolValue, ok := getLiteralBoolProperty(mod, name)
+	if !ok {
+		return false, false
+	}
+
+	return boolValue.Value, true
+}
+
 func propertyIndex(props []*parser.Property, propertyName string) int {
 	for i, prop := range props {
 		if prop.Name == propertyName {
diff --git a/bpfix/bpfix/bpfix_test.go b/bpfix/bpfix/bpfix_test.go
index 16dfce0..0469faf 100644
--- a/bpfix/bpfix/bpfix_test.go
+++ b/bpfix/bpfix/bpfix_test.go
@@ -555,3 +555,69 @@
 		})
 	}
 }
+
+func TestRewritePrebuilts(t *testing.T) {
+	tests := []struct {
+		name string
+		in   string
+		out  string
+	}{
+		{
+			name: "jar srcs",
+			in: `
+				java_import {
+					name: "foo",
+					srcs: ["foo.jar"],
+				}
+			`,
+			out: `
+				java_import {
+					name: "foo",
+					jars: ["foo.jar"],
+				}
+			`,
+		},
+		{
+			name: "aar srcs",
+			in: `
+				java_import {
+					name: "foo",
+					srcs: ["foo.aar"],
+					installable: true,
+				}
+			`,
+			out: `
+				android_library_import {
+					name: "foo",
+					aars: ["foo.aar"],
+
+				}
+			`,
+		},
+		{
+			name: "host prebuilt",
+			in: `
+				java_import {
+					name: "foo",
+					srcs: ["foo.jar"],
+					host: true,
+				}
+			`,
+			out: `
+				java_import_host {
+					name: "foo",
+					jars: ["foo.jar"],
+
+				}
+			`,
+		},
+	}
+
+	for _, test := range tests {
+		t.Run(test.name, func(t *testing.T) {
+			runPass(t, test.in, test.out, func(fixer *Fixer) error {
+				return rewriteIncorrectAndroidmkPrebuilts(fixer)
+			})
+		})
+	}
+}
diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go
index 2bd0cf4..0380368 100644
--- a/cmd/soong_ui/main.go
+++ b/cmd/soong_ui/main.go
@@ -104,9 +104,6 @@
 
 	build.SetupOutDir(buildCtx, config)
 
-	metricsPath := filepath.Join(config.OutDir(), "build_metrics")
-	defer met.Dump(metricsPath)
-
 	logsDir := config.OutDir()
 	if config.Dist() {
 		logsDir = filepath.Join(config.DistDir(), "logs")
@@ -118,6 +115,8 @@
 	stat.AddOutput(status.NewVerboseLog(log, filepath.Join(logsDir, "verbose.log")))
 	stat.AddOutput(status.NewErrorLog(log, filepath.Join(logsDir, "error.log")))
 
+	defer met.Dump(filepath.Join(logsDir, "build_metrics"))
+
 	if start, ok := os.LookupEnv("TRACE_BEGIN_SOONG"); ok {
 		if !strings.HasSuffix(start, "N") {
 			if start_time, err := strconv.ParseUint(start, 10, 64); err == nil {