Move boot image oatdump phony rules into Soong

The boot image oatdump rules depend on the details of dexpreopting
the boot image.  Instead of exporting all of the necessary values
to make, move the rules into Soong instead.  Also removes the
ART_DUMP_OAT_PATH variable, and moves the output to
out/soong/boot.*.oatdump.txt.

Test: m dump-oat-boot
Change-Id: I055b1c39918ba3425c8393b3e1b5359df055472a
diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go
index a35e011..ca68832 100644
--- a/java/dexpreopt_bootjars.go
+++ b/java/dexpreopt_bootjars.go
@@ -16,6 +16,7 @@
 
 import (
 	"path/filepath"
+	"sort"
 	"strings"
 
 	"android/soong/android"
@@ -137,6 +138,8 @@
 	if global.GenerateApexImage {
 		d.otherImages = append(d.otherImages, buildBootImage(ctx, apexBootImageConfig(ctx)))
 	}
+
+	dumpOatRules(ctx, d.defaultBootImage)
 }
 
 // buildBootImage takes a bootImageConfig, creates rules to build it, and returns a *bootImage.
@@ -389,6 +392,50 @@
 
 var bootImageProfileRuleKey = android.NewOnceKey("bootImageProfileRule")
 
+func dumpOatRules(ctx android.SingletonContext, image *bootImage) {
+	var archs []android.ArchType
+	for arch := range image.images {
+		archs = append(archs, arch)
+	}
+	sort.Slice(archs, func(i, j int) bool { return archs[i].String() < archs[j].String() })
+
+	var allPhonies android.Paths
+	for _, arch := range archs {
+		// Create a rule to call oatdump.
+		output := android.PathForOutput(ctx, "boot."+arch.String()+".oatdump.txt")
+		rule := android.NewRuleBuilder()
+		rule.Command().
+			// TODO: for now, use the debug version for better error reporting
+			Tool(ctx.Config().HostToolPath(ctx, "oatdumpd")).
+			FlagWithInputList("--runtime-arg -Xbootclasspath:", image.dexPaths.Paths(), ":").
+			FlagWithList("--runtime-arg -Xbootclasspath-locations:", image.dexLocations, ":").
+			FlagWithArg("--image=", dexpreopt.PathToLocation(image.images[arch], arch)).Implicit(image.images[arch]).
+			FlagWithOutput("--output=", output).
+			FlagWithArg("--instruction-set=", arch.String())
+		rule.Build(pctx, ctx, "dump-oat-boot-"+arch.String(), "dump oat boot "+arch.String())
+
+		// Create a phony rule that depends on the output file and prints the path.
+		phony := android.PathForPhony(ctx, "dump-oat-boot-"+arch.String())
+		rule = android.NewRuleBuilder()
+		rule.Command().
+			Implicit(output).
+			ImplicitOutput(phony).
+			Text("echo").FlagWithArg("Output in ", output.String())
+		rule.Build(pctx, ctx, "phony-dump-oat-boot-"+arch.String(), "dump oat boot "+arch.String())
+
+		allPhonies = append(allPhonies, phony)
+	}
+
+	phony := android.PathForPhony(ctx, "dump-oat-boot")
+	ctx.Build(pctx, android.BuildParams{
+		Rule:        android.Phony,
+		Output:      phony,
+		Inputs:      allPhonies,
+		Description: "dump-oat-boot",
+	})
+
+}
+
 // Export paths for default boot image to Make
 func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) {
 	image := d.defaultBootImage