Generate the ART boot image for host as well (used by ART tests).

This will allow us to remove the core.art image compiled in make.

Test: lunch aosp_x86_64 && m test-art-host-gtest
Bug: 147817558
Bug: 147819342
Change-Id: I864f72198d875dc1421c9c029a683bafbe7b71ac
This commit is contained in:
David Srbecky 2020-02-13 16:00:45 +00:00
parent 8f20563514
commit 7f8dac1254
3 changed files with 48 additions and 37 deletions

View File

@ -176,11 +176,6 @@ func skipDexpreoptBootJars(ctx android.PathContext) bool {
return true return true
} }
if len(ctx.Config().Targets[android.Android]) == 0 {
// Host-only build
return true
}
return false return false
} }
@ -199,8 +194,11 @@ func DexpreoptedArtApexJars(ctx android.BuilderContext) map[android.ArchType]and
// Include dexpreopt files for the primary boot image. // Include dexpreopt files for the primary boot image.
files := map[android.ArchType]android.OutputPaths{} files := map[android.ArchType]android.OutputPaths{}
for _, variant := range artBootImageConfig(ctx).variants { for _, variant := range artBootImageConfig(ctx).variants {
// We also generate boot images for host (for testing), but we don't need those in the apex.
if variant.target.Os == android.Android {
files[variant.target.Arch.ArchType] = variant.imagesDeps files[variant.target.Arch.ArchType] = variant.imagesDeps
} }
}
return files return files
} }
@ -305,9 +303,10 @@ func buildBootImageVariant(ctx android.SingletonContext, image *bootImageVariant
global := dexpreopt.GetGlobalConfig(ctx) global := dexpreopt.GetGlobalConfig(ctx)
arch := image.target.Arch.ArchType arch := image.target.Arch.ArchType
symbolsDir := image.symbolsDir.Join(ctx, image.installSubdir, arch.String()) os := image.target.Os.String() // We need to distinguish host-x86 and device-x86.
symbolsDir := image.symbolsDir.Join(ctx, os, image.installSubdir, arch.String())
symbolsFile := symbolsDir.Join(ctx, image.stem+".oat") symbolsFile := symbolsDir.Join(ctx, image.stem+".oat")
outputDir := image.dir.Join(ctx, image.installSubdir, arch.String()) outputDir := image.dir.Join(ctx, os, image.installSubdir, arch.String())
outputPath := outputDir.Join(ctx, image.stem+".oat") outputPath := outputDir.Join(ctx, image.stem+".oat")
oatLocation := dexpreopt.PathToLocation(outputPath, arch) oatLocation := dexpreopt.PathToLocation(outputPath, arch)
imagePath := outputPath.ReplaceExtension(ctx, "art") imagePath := outputPath.ReplaceExtension(ctx, "art")
@ -375,12 +374,17 @@ func buildBootImageVariant(ctx android.SingletonContext, image *bootImageVariant
FlagWithArg("--oat-location=", oatLocation). FlagWithArg("--oat-location=", oatLocation).
FlagWithArg("--image=", imagePath.String()). FlagWithArg("--image=", imagePath.String()).
FlagWithArg("--instruction-set=", arch.String()). FlagWithArg("--instruction-set=", arch.String()).
FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch]).
FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch]).
FlagWithArg("--android-root=", global.EmptyDirectory). FlagWithArg("--android-root=", global.EmptyDirectory).
FlagWithArg("--no-inline-from=", "core-oj.jar"). FlagWithArg("--no-inline-from=", "core-oj.jar").
Flag("--abort-on-hard-verifier-error") Flag("--abort-on-hard-verifier-error")
// Use the default variant/features for host builds.
// The map below contains only device CPU info (which might be x86 on some devices).
if image.target.Os == android.Android {
cmd.FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch])
cmd.FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch])
}
if global.BootFlags != "" { if global.BootFlags != "" {
cmd.Flag(global.BootFlags) cmd.Flag(global.BootFlags)
} }
@ -392,7 +396,6 @@ func buildBootImageVariant(ctx android.SingletonContext, image *bootImageVariant
cmd.Textf(`|| ( echo %s ; false )`, proptools.ShellEscape(failureMessage)) cmd.Textf(`|| ( echo %s ; false )`, proptools.ShellEscape(failureMessage))
installDir := filepath.Join("/", image.installSubdir, arch.String()) installDir := filepath.Join("/", image.installSubdir, arch.String())
vdexInstallDir := filepath.Join("/", image.installSubdir)
var vdexInstalls android.RuleBuilderInstalls var vdexInstalls android.RuleBuilderInstalls
var unstrippedInstalls android.RuleBuilderInstalls var unstrippedInstalls android.RuleBuilderInstalls
@ -411,11 +414,10 @@ func buildBootImageVariant(ctx android.SingletonContext, image *bootImageVariant
cmd.ImplicitOutput(vdex) cmd.ImplicitOutput(vdex)
zipFiles = append(zipFiles, vdex) zipFiles = append(zipFiles, vdex)
// The vdex files are identical between architectures, install them to a shared location. The Make rules will // Note that the vdex files are identical between architectures.
// only use the install rules for one architecture, and will create symlinks into the architecture-specific // Make rules will create symlinks to share them between architectures.
// directories.
vdexInstalls = append(vdexInstalls, vdexInstalls = append(vdexInstalls,
android.RuleBuilderInstall{vdex, filepath.Join(vdexInstallDir, vdex.Base())}) android.RuleBuilderInstall{vdex, filepath.Join(installDir, vdex.Base())})
} }
for _, unstrippedOat := range image.moduleFiles(ctx, symbolsDir, ".oat") { for _, unstrippedOat := range image.moduleFiles(ctx, symbolsDir, ".oat") {
@ -426,7 +428,7 @@ func buildBootImageVariant(ctx android.SingletonContext, image *bootImageVariant
android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())}) android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())})
} }
rule.Build(pctx, ctx, image.name+"JarsDexpreopt_"+arch.String(), "dexpreopt "+image.name+" jars "+arch.String()) rule.Build(pctx, ctx, image.name+"JarsDexpreopt_"+image.target.String(), "dexpreopt "+image.name+" jars "+arch.String())
// save output and installed files for makevars // save output and installed files for makevars
image.installs = rule.Installs() image.installs = rule.Installs()
@ -544,8 +546,9 @@ func dumpOatRules(ctx android.SingletonContext, image *bootImageConfig) {
var allPhonies android.Paths var allPhonies android.Paths
for _, image := range image.variants { for _, image := range image.variants {
arch := image.target.Arch.ArchType arch := image.target.Arch.ArchType
suffix := image.target.String()
// Create a rule to call oatdump. // Create a rule to call oatdump.
output := android.PathForOutput(ctx, "boot."+arch.String()+".oatdump.txt") output := android.PathForOutput(ctx, "boot."+suffix+".oatdump.txt")
rule := android.NewRuleBuilder() rule := android.NewRuleBuilder()
rule.Command(). rule.Command().
// TODO: for now, use the debug version for better error reporting // TODO: for now, use the debug version for better error reporting
@ -555,16 +558,16 @@ func dumpOatRules(ctx android.SingletonContext, image *bootImageConfig) {
FlagWithArg("--image=", strings.Join(image.imageLocations, ":")).Implicits(image.imagesDeps.Paths()). FlagWithArg("--image=", strings.Join(image.imageLocations, ":")).Implicits(image.imagesDeps.Paths()).
FlagWithOutput("--output=", output). FlagWithOutput("--output=", output).
FlagWithArg("--instruction-set=", arch.String()) FlagWithArg("--instruction-set=", arch.String())
rule.Build(pctx, ctx, "dump-oat-boot-"+arch.String(), "dump oat boot "+arch.String()) rule.Build(pctx, ctx, "dump-oat-boot-"+suffix, "dump oat boot "+arch.String())
// Create a phony rule that depends on the output file and prints the path. // Create a phony rule that depends on the output file and prints the path.
phony := android.PathForPhony(ctx, "dump-oat-boot-"+arch.String()) phony := android.PathForPhony(ctx, "dump-oat-boot-"+suffix)
rule = android.NewRuleBuilder() rule = android.NewRuleBuilder()
rule.Command(). rule.Command().
Implicit(output). Implicit(output).
ImplicitOutput(phony). ImplicitOutput(phony).
Text("echo").FlagWithArg("Output in ", output.String()) Text("echo").FlagWithArg("Output in ", output.String())
rule.Build(pctx, ctx, "phony-dump-oat-boot-"+arch.String(), "dump oat boot "+arch.String()) rule.Build(pctx, ctx, "phony-dump-oat-boot-"+suffix, "dump oat boot "+arch.String())
allPhonies = append(allPhonies, phony) allPhonies = append(allPhonies, phony)
} }
@ -608,7 +611,11 @@ func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) {
for _, current := range append(d.otherImages, image) { for _, current := range append(d.otherImages, image) {
imageNames = append(imageNames, current.name) imageNames = append(imageNames, current.name)
for _, current := range current.variants { for _, current := range current.variants {
sfx := current.name + "_" + current.target.Arch.ArchType.String() suffix := ""
if current.target.Os.Class == android.Host {
suffix = "_host"
}
sfx := current.name + suffix + "_" + current.target.Arch.ArchType.String()
ctx.Strict("DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_"+sfx, current.vdexInstalls.String()) ctx.Strict("DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_"+sfx, current.vdexInstalls.String())
ctx.Strict("DEXPREOPT_IMAGE_"+sfx, current.images.String()) ctx.Strict("DEXPREOPT_IMAGE_"+sfx, current.images.String())
ctx.Strict("DEXPREOPT_IMAGE_DEPS_"+sfx, strings.Join(current.imagesDeps.Strings(), " ")) ctx.Strict("DEXPREOPT_IMAGE_DEPS_"+sfx, strings.Join(current.imagesDeps.Strings(), " "))

View File

@ -62,7 +62,7 @@ func TestDexpreoptBootJars(t *testing.T) {
bootArt := dexpreoptBootJars.Output("boot-foo.art") bootArt := dexpreoptBootJars.Output("boot-foo.art")
expectedInputs := []string{ expectedInputs := []string{
"dex_artjars/apex/com.android.art/javalib/arm64/boot.art", "dex_artjars/android/apex/com.android.art/javalib/arm64/boot.art",
"dex_bootjars_input/foo.jar", "dex_bootjars_input/foo.jar",
"dex_bootjars_input/bar.jar", "dex_bootjars_input/bar.jar",
"dex_bootjars_input/baz.jar", "dex_bootjars_input/baz.jar",
@ -81,23 +81,23 @@ func TestDexpreoptBootJars(t *testing.T) {
} }
expectedOutputs := []string{ expectedOutputs := []string{
"dex_bootjars/system/framework/arm64/boot.invocation", "dex_bootjars/android/system/framework/arm64/boot.invocation",
"dex_bootjars/system/framework/arm64/boot-foo.art", "dex_bootjars/android/system/framework/arm64/boot-foo.art",
"dex_bootjars/system/framework/arm64/boot-bar.art", "dex_bootjars/android/system/framework/arm64/boot-bar.art",
"dex_bootjars/system/framework/arm64/boot-baz.art", "dex_bootjars/android/system/framework/arm64/boot-baz.art",
"dex_bootjars/system/framework/arm64/boot-foo.oat", "dex_bootjars/android/system/framework/arm64/boot-foo.oat",
"dex_bootjars/system/framework/arm64/boot-bar.oat", "dex_bootjars/android/system/framework/arm64/boot-bar.oat",
"dex_bootjars/system/framework/arm64/boot-baz.oat", "dex_bootjars/android/system/framework/arm64/boot-baz.oat",
"dex_bootjars/system/framework/arm64/boot-foo.vdex", "dex_bootjars/android/system/framework/arm64/boot-foo.vdex",
"dex_bootjars/system/framework/arm64/boot-bar.vdex", "dex_bootjars/android/system/framework/arm64/boot-bar.vdex",
"dex_bootjars/system/framework/arm64/boot-baz.vdex", "dex_bootjars/android/system/framework/arm64/boot-baz.vdex",
"dex_bootjars_unstripped/system/framework/arm64/boot-foo.oat", "dex_bootjars_unstripped/android/system/framework/arm64/boot-foo.oat",
"dex_bootjars_unstripped/system/framework/arm64/boot-bar.oat", "dex_bootjars_unstripped/android/system/framework/arm64/boot-bar.oat",
"dex_bootjars_unstripped/system/framework/arm64/boot-baz.oat", "dex_bootjars_unstripped/android/system/framework/arm64/boot-baz.oat",
} }
for i := range expectedOutputs { for i := range expectedOutputs {

View File

@ -68,6 +68,10 @@ func dexpreoptTargets(ctx android.PathContext) []android.Target {
targets = append(targets, target) targets = append(targets, target)
} }
} }
// We may also need the images on host in order to run host-based tests.
for _, target := range ctx.Config().Targets[android.BuildOs] {
targets = append(targets, target)
}
return targets return targets
} }
@ -152,7 +156,7 @@ func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig {
// expands to <stem>.art for primary image and <stem>-<1st module>.art for extension // expands to <stem>.art for primary image and <stem>-<1st module>.art for extension
imageName := c.firstModuleNameOrStem() + ".art" imageName := c.firstModuleNameOrStem() + ".art"
c.imageLocations = []string{c.dir.Join(ctx, c.installSubdir, imageName).String()} c.imageLocations = []string{c.dir.Join(ctx, "android", c.installSubdir, imageName).String()}
// The path to bootclasspath dex files needs to be known at module // The path to bootclasspath dex files needs to be known at module
// GenerateAndroidBuildAction time, before the bootclasspath modules have been compiled. // GenerateAndroidBuildAction time, before the bootclasspath modules have been compiled.
@ -167,7 +171,7 @@ func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig {
// Create target-specific variants. // Create target-specific variants.
for _, target := range targets { for _, target := range targets {
arch := target.Arch.ArchType arch := target.Arch.ArchType
imageDir := c.dir.Join(ctx, c.installSubdir, arch.String()) imageDir := c.dir.Join(ctx, target.Os.String(), c.installSubdir, arch.String())
variant := &bootImageVariant{ variant := &bootImageVariant{
bootImageConfig: c, bootImageConfig: c,
target: target, target: target,