Support for install multiple boot images.

Bug: 119800099
Test: m && /system/framework/arm/apex*.art files exist
Change-Id: I8b708a0c495193e5455e03eaa575ce55a482a95d
diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go
index 3d4042b..31a3e26 100644
--- a/java/dexpreopt_config.go
+++ b/java/dexpreopt_config.go
@@ -131,6 +131,52 @@
 
 var defaultBootImageConfigKey = android.NewOnceKey("defaultBootImageConfig")
 
+func apexBootImageConfig(ctx android.PathContext) bootImageConfig {
+	return ctx.Config().Once(apexBootImageConfigKey, func() interface{} {
+		global := dexpreoptGlobalConfig(ctx)
+
+		runtimeModules := global.RuntimeApexJars
+
+		var runtimeBootLocations []string
+
+		for _, m := range runtimeModules {
+			runtimeBootLocations = append(runtimeBootLocations,
+				filepath.Join("/apex/com.android.runtime/javalib", m+".jar"))
+		}
+
+		// The path to bootclasspath dex files needs to be known at module GenerateAndroidBuildAction time, before
+		// the bootclasspath modules have been compiled.  Set up known paths for them, the singleton rules will copy
+		// them there.
+		// TODO: use module dependencies instead
+		var runtimeBootDexPaths android.WritablePaths
+		for _, m := range runtimeModules {
+			runtimeBootDexPaths = append(runtimeBootDexPaths,
+				android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_apexjars_input", m+".jar"))
+		}
+
+		dir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_apexjars")
+		symbolsDir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_apexjars_unstripped")
+		images := make(map[android.ArchType]android.OutputPath)
+
+		for _, target := range ctx.Config().Targets[android.Android] {
+			images[target.Arch.ArchType] = dir.Join(ctx,
+				"system/framework", target.Arch.ArchType.String(), "apex.art")
+		}
+
+		return bootImageConfig{
+			name:         "apex",
+			modules:      runtimeModules,
+			dexLocations: runtimeBootLocations,
+			dexPaths:     runtimeBootDexPaths,
+			dir:          dir,
+			symbolsDir:   symbolsDir,
+			images:       images,
+		}
+	}).(bootImageConfig)
+}
+
+var apexBootImageConfigKey = android.NewOnceKey("apexBootImageConfig")
+
 func defaultBootclasspath(ctx android.PathContext) []string {
 	return ctx.Config().OnceStringSlice(defaultBootclasspathKey, func() []string {
 		global := dexpreoptGlobalConfig(ctx)