From 18263381ed859a3c53643a7eab0103f21dc75960 Mon Sep 17 00:00:00 2001 From: Ulya Trafimovich Date: Wed, 23 Oct 2019 15:56:32 +0100 Subject: [PATCH] Deduplicate config generation for boot images. Both default and apex configs are used for dexpreopting bootclasspath jars. The difference between the two configs is in the naming (default paths contain "boot", and apex paths contain "apex"). Another difference is that apex config does not have a zip archive. Test: m Test: `find $ANDROID_BUILD_TOP/out -name '*.art' | sort` returns the same list of files before and after the patch Change-Id: I5b2e8d83ab94fd0b1b3d4dc3f0db243ef70bfb08 --- java/dexpreopt_config.go | 102 +++++++++------------------------------ 1 file changed, 23 insertions(+), 79 deletions(-) diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go index 043f9daed..429bbdba6 100644 --- a/java/dexpreopt_config.go +++ b/java/dexpreopt_config.go @@ -96,80 +96,9 @@ func dexpreoptTargets(ctx android.PathContext) []android.Target { return targets } -// defaultBootImageConfig returns the bootImageConfig that will be used to dexpreopt modules. It is computed once the -// first time it is called for any ctx.Config(), and returns the same slice for all future calls with the same -// ctx.Config(). -func defaultBootImageConfig(ctx android.PathContext) bootImageConfig { - return ctx.Config().Once(defaultBootImageConfigKey, func() interface{} { - global := dexpreoptGlobalConfig(ctx) - - artModules := global.ArtApexJars - nonFrameworkModules := concat(artModules, global.ProductUpdatableBootModules) - frameworkModules := android.RemoveListFromList(global.BootJars, nonFrameworkModules) - - var nonUpdatableBootModules []string - var nonUpdatableBootLocations []string - - for _, m := range artModules { - nonUpdatableBootModules = append(nonUpdatableBootModules, m) - nonUpdatableBootLocations = append(nonUpdatableBootLocations, - filepath.Join("/apex/com.android.art/javalib", m+".jar")) - } - - for _, m := range frameworkModules { - nonUpdatableBootModules = append(nonUpdatableBootModules, m) - nonUpdatableBootLocations = append(nonUpdatableBootLocations, - filepath.Join("/system/framework", 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 nonUpdatableBootDexPaths android.WritablePaths - for _, m := range nonUpdatableBootModules { - nonUpdatableBootDexPaths = append(nonUpdatableBootDexPaths, - android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_bootjars_input", m+".jar")) - } - - dir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_bootjars") - symbolsDir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_bootjars_unstripped") - zip := dir.Join(ctx, "boot.zip") - - targets := dexpreoptTargets(ctx) - - imageConfig := bootImageConfig{ - name: "boot", - modules: nonUpdatableBootModules, - dexLocations: nonUpdatableBootLocations, - dexPaths: nonUpdatableBootDexPaths, - dir: dir, - symbolsDir: symbolsDir, - images: make(map[android.ArchType]android.OutputPath), - imagesDeps: make(map[android.ArchType]android.Paths), - targets: targets, - zip: zip, - } - - for _, target := range targets { - imageDir := dir.Join(ctx, "system/framework", target.Arch.ArchType.String()) - imageConfig.images[target.Arch.ArchType] = imageDir.Join(ctx, "boot.art") - - imagesDeps := make([]android.Path, 0, len(imageConfig.modules)*3) - for _, dep := range imageConfig.moduleFiles(ctx, imageDir, ".art", ".oat", ".vdex") { - imagesDeps = append(imagesDeps, dep) - } - imageConfig.imagesDeps[target.Arch.ArchType] = imagesDeps - } - - return imageConfig - }).(bootImageConfig) -} - -var defaultBootImageConfigKey = android.NewOnceKey("defaultBootImageConfig") - -func apexBootImageConfig(ctx android.PathContext) bootImageConfig { - return ctx.Config().Once(apexBootImageConfigKey, func() interface{} { +func getBootImageConfig(ctx android.PathContext, key android.OnceKey, name string, + needZip bool) bootImageConfig { + return ctx.Config().Once(key, func() interface{} { global := dexpreoptGlobalConfig(ctx) artModules := global.ArtApexJars @@ -196,16 +125,21 @@ func apexBootImageConfig(ctx android.PathContext) bootImageConfig { var bootDexPaths android.WritablePaths for _, m := range imageModules { bootDexPaths = append(bootDexPaths, - android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_apexjars_input", m+".jar")) + android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_"+name+"jars_input", m+".jar")) } - dir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_apexjars") - symbolsDir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_apexjars_unstripped") + dir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_"+name+"jars") + symbolsDir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_"+name+"jars_unstripped") + + var zip android.WritablePath + if needZip { + zip = dir.Join(ctx, name+".zip") + } targets := dexpreoptTargets(ctx) imageConfig := bootImageConfig{ - name: "apex", + name: name, modules: imageModules, dexLocations: bootLocations, dexPaths: bootDexPaths, @@ -214,11 +148,12 @@ func apexBootImageConfig(ctx android.PathContext) bootImageConfig { targets: targets, images: make(map[android.ArchType]android.OutputPath), imagesDeps: make(map[android.ArchType]android.Paths), + zip: zip, } for _, target := range targets { imageDir := dir.Join(ctx, "system/framework", target.Arch.ArchType.String()) - imageConfig.images[target.Arch.ArchType] = imageDir.Join(ctx, "apex.art") + imageConfig.images[target.Arch.ArchType] = imageDir.Join(ctx, name+".art") imagesDeps := make([]android.Path, 0, len(imageConfig.modules)*3) for _, dep := range imageConfig.moduleFiles(ctx, imageDir, ".art", ".oat", ".vdex") { @@ -231,8 +166,17 @@ func apexBootImageConfig(ctx android.PathContext) bootImageConfig { }).(bootImageConfig) } +var defaultBootImageConfigKey = android.NewOnceKey("defaultBootImageConfig") var apexBootImageConfigKey = android.NewOnceKey("apexBootImageConfig") +func defaultBootImageConfig(ctx android.PathContext) bootImageConfig { + return getBootImageConfig(ctx, defaultBootImageConfigKey, "boot", true) +} + +func apexBootImageConfig(ctx android.PathContext) bootImageConfig { + return getBootImageConfig(ctx, apexBootImageConfigKey, "apex", false) +} + func defaultBootclasspath(ctx android.PathContext) []string { return ctx.Config().OnceStringSlice(defaultBootclasspathKey, func() []string { global := dexpreoptGlobalConfig(ctx)