Merge "Cleanup createVndkSourceAbiDump()"
diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go
index 7b06035..9aa25f0 100644
--- a/cmd/pom2bp/pom2bp.go
+++ b/cmd/pom2bp/pom2bp.go
@@ -281,8 +281,8 @@
 {{if .IsAar}}android_library{{else}}java_library_static{{end}} {
     name: "{{.BpName}}",
     sdk_version: "{{.SdkVersion}}",{{if .IsAar}}
-    min_sdk_version: "{{.MinSdkVersion}}",{{end}}
-    manifest: "manifests/{{.BpName}}/AndroidManifest.xml",
+    min_sdk_version: "{{.MinSdkVersion}}",
+    manifest: "manifests/{{.BpName}}/AndroidManifest.xml",{{end}}
     static_libs: [
         "{{.BpName}}-nodeps",{{range .BpJarDeps}}
         "{{.}}",{{end}}{{range .BpAarDeps}}
diff --git a/genrule/genrule.go b/genrule/genrule.go
index d03d4ee..03d4ea6 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -223,13 +223,18 @@
 	task := g.taskGenerator(ctx, String(g.properties.Cmd), srcFiles)
 
 	rawCommand, err := android.Expand(task.cmd, func(name string) (string, error) {
+		// report the error directly without returning an error to android.Expand to catch multiple errors in a
+		// single run
+		reportError := func(fmt string, args ...interface{}) (string, error) {
+			ctx.PropertyErrorf("cmd", fmt, args...)
+			return "SOONG_ERROR", nil
+		}
+
 		switch name {
 		case "location":
 			if len(g.properties.Tools) == 0 && len(toolFiles) == 0 {
-				return "", fmt.Errorf("at least one `tools` or `tool_files` is required if $(location) is used")
-			}
-
-			if len(g.properties.Tools) > 0 {
+				return reportError("at least one `tools` or `tool_files` is required if $(location) is used")
+			} else if len(g.properties.Tools) > 0 {
 				return tools[g.properties.Tools[0]].String(), nil
 			} else {
 				return tools[toolFiles[0].Rel()].String(), nil
@@ -241,7 +246,7 @@
 		case "depfile":
 			referencedDepfile = true
 			if !Bool(g.properties.Depfile) {
-				return "", fmt.Errorf("$(depfile) used without depfile property")
+				return reportError("$(depfile) used without depfile property")
 			}
 			return "__SBOX_DEPFILE__", nil
 		case "genDir":
@@ -252,22 +257,22 @@
 				if tool, ok := tools[label]; ok {
 					return tool.String(), nil
 				} else {
-					return "", fmt.Errorf("unknown location label %q", label)
+					return reportError("unknown location label %q", label)
 				}
 			}
-			return "", fmt.Errorf("unknown variable '$(%s)'", name)
+			return reportError("unknown variable '$(%s)'", name)
 		}
 	})
 
-	if Bool(g.properties.Depfile) && !referencedDepfile {
-		ctx.PropertyErrorf("cmd", "specified depfile=true but did not include a reference to '${depfile}' in cmd")
-	}
-
 	if err != nil {
 		ctx.PropertyErrorf("cmd", "%s", err.Error())
 		return
 	}
 
+	if Bool(g.properties.Depfile) && !referencedDepfile {
+		ctx.PropertyErrorf("cmd", "specified depfile=true but did not include a reference to '${depfile}' in cmd")
+	}
+
 	// tell the sbox command which directory to use as its sandbox root
 	buildDir := android.PathForOutput(ctx).String()
 	sandboxPath := shared.TempDirForOutDir(buildDir)
diff --git a/java/aar.go b/java/aar.go
index 506f39f..a4069bb 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -323,6 +323,7 @@
 		&module.androidLibraryProperties)
 
 	module.androidLibraryProperties.BuildAAR = true
+	module.properties.Installable = proptools.BoolPtr(false)
 
 	android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon)
 	return module
@@ -335,7 +336,8 @@
 type AARImportProperties struct {
 	Aars []string
 
-	Sdk_version *string
+	Sdk_version     *string
+	Min_sdk_version *string
 
 	Static_libs []string
 	Libs        []string
@@ -361,6 +363,9 @@
 }
 
 func (a *AARImport) minSdkVersion() string {
+	if a.properties.Min_sdk_version != nil {
+		return *a.properties.Min_sdk_version
+	}
 	return a.sdkVersion()
 }
 
diff --git a/java/droiddoc.go b/java/droiddoc.go
index dbceed8..6cb8d3c 100644
--- a/java/droiddoc.go
+++ b/java/droiddoc.go
@@ -226,6 +226,10 @@
 	// the generated removed Dex API filename by Doclava.
 	Removed_dex_api_filename *string
 
+	// mapping of dex signatures to source file and line number. This is a temporary property and
+	// will be deleted; you probably shouldn't be using it.
+	Dex_mapping_filename *string
+
 	// the generated exact API filename by Doclava.
 	Exact_api_filename *string
 
@@ -283,6 +287,7 @@
 	removedApiFile    android.WritablePath
 	removedDexApiFile android.WritablePath
 	exactApiFile      android.WritablePath
+	apiMappingFile    android.WritablePath
 
 	checkCurrentApiTimestamp      android.WritablePath
 	updateCurrentApiTimestamp     android.WritablePath
@@ -831,6 +836,13 @@
 		implicitOutputs = append(implicitOutputs, d.exactApiFile)
 	}
 
+	if String(d.properties.Dex_mapping_filename) != "" {
+		d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename))
+		args = args + " -apiMapping " + d.apiMappingFile.String()
+		// Omitted: metalava support
+		implicitOutputs = append(implicitOutputs, d.apiMappingFile)
+	}
+
 	implicits = append(implicits, d.Javadoc.srcJars...)
 
 	implicitOutputs = append(implicitOutputs, d.Javadoc.docZip)
diff --git a/java/system_modules.go b/java/system_modules.go
index 943eaeb..73a5131 100644
--- a/java/system_modules.go
+++ b/java/system_modules.go
@@ -119,9 +119,7 @@
 
 	jars = append(jars, android.PathsForModuleSrc(ctx, system.properties.Jars)...)
 
-	if ctx.Config().TargetOpenJDK9() {
-		system.outputFile = TransformJarsToSystemModules(ctx, "java.base", jars)
-	}
+	system.outputFile = TransformJarsToSystemModules(ctx, "java.base", jars)
 }
 
 func (system *SystemModules) DepsMutator(ctx android.BottomUpMutatorContext) {
@@ -131,17 +129,15 @@
 func (system *SystemModules) AndroidMk() android.AndroidMkData {
 	return android.AndroidMkData{
 		Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
-			if system.outputFile != nil {
-				makevar := "SOONG_SYSTEM_MODULES_" + name
-				fmt.Fprintln(w)
-				fmt.Fprintln(w, makevar, ":=", system.outputFile.String())
-				fmt.Fprintln(w, ".KATI_READONLY", ":=", makevar)
-				fmt.Fprintln(w, name+":", "$("+makevar+")")
-				fmt.Fprintln(w)
-				makevar = "SOONG_SYSTEM_MODULES_LIBS_" + name
-				fmt.Fprintln(w, makevar, ":=", strings.Join(system.properties.Libs, " "))
-				fmt.Fprintln(w, ".KATI_READONLY :=", makevar)
-			}
+			makevar := "SOONG_SYSTEM_MODULES_" + name
+			fmt.Fprintln(w)
+			fmt.Fprintln(w, makevar, ":=", system.outputFile.String())
+			fmt.Fprintln(w, ".KATI_READONLY", ":=", makevar)
+			fmt.Fprintln(w, name+":", "$("+makevar+")")
+			fmt.Fprintln(w)
+			makevar = "SOONG_SYSTEM_MODULES_LIBS_" + name
+			fmt.Fprintln(w, makevar, ":=", strings.Join(system.properties.Libs, " "))
+			fmt.Fprintln(w, ".KATI_READONLY :=", makevar)
 		},
 	}
 }