diff options
-rw-r--r-- | Android.bp | 5 | ||||
-rw-r--r-- | java/dexpreopt_bootjars.go | 98 |
2 files changed, 103 insertions, 0 deletions
diff --git a/Android.bp b/Android.bp index 535246e65..f2d0d94ca 100644 --- a/Android.bp +++ b/Android.bp @@ -116,6 +116,11 @@ dex_bootjars { visibility: ["//visibility:public"], } +art_boot_images { + name: "art_boot_images", + visibility: ["//art:__subpackages__"], +} + // Pseudo-test that's run on checkbuilds to ensure that get_clang_version can // parse cc/config/global.go. genrule { diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index a2e473469..ad0e0a7e3 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -463,6 +463,7 @@ func dexpreoptBootJarsFactory() android.SingletonModule { func RegisterDexpreoptBootJarsComponents(ctx android.RegistrationContext) { ctx.RegisterParallelSingletonModuleType("dex_bootjars", dexpreoptBootJarsFactory) + ctx.RegisterModuleType("art_boot_images", artBootImagesFactory) ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.BottomUp("dex_bootjars_deps", DexpreoptBootJarsMutator).Parallel() }) @@ -601,6 +602,7 @@ func (d *dexpreoptBootJars) GenerateAndroidBuildActions(ctx android.ModuleContex d.defaultBootImage = defaultBootImageConfig(ctx) d.otherImages = make([]*bootImageConfig, 0, len(imageConfigs)-1) var profileInstalls android.RuleBuilderInstalls + var artBootImageHostInstalls android.RuleBuilderInstalls for _, name := range getImageNames() { config := imageConfigs[name] if config != d.defaultBootImage { @@ -616,6 +618,18 @@ func (d *dexpreoptBootJars) GenerateAndroidBuildActions(ctx android.ModuleContex d.bootFrameworkProfile = bootProfile profileInstalls = append(profileInstalls, installs...) } + // Gather the install files of the host variant of the ART boot image. + // These installed files will be used in ART tests. + if config.name == "art" { + for _, variant := range config.variants { + if variant.target.Os != ctx.Config().BuildOS { + // not a host variant + continue + } + artBootImageHostInstalls = append(artBootImageHostInstalls, variant.installs...) + artBootImageHostInstalls = append(artBootImageHostInstalls, variant.vdexInstalls...) + } + } } if len(profileInstalls) > 0 { android.SetProvider(ctx, profileInstallInfoProvider, profileInstallInfo{ @@ -626,6 +640,15 @@ func (d *dexpreoptBootJars) GenerateAndroidBuildActions(ctx android.ModuleContex installFile(ctx, install) } } + // Set a provider containing the install files of the host variant of the ART boot image. + // The actual install rules will be created by `art_boot_images` + android.SetProvider( + ctx, + artBootImageHostInfoProvider, + artBootImageHostInfo{ + installs: artBootImageHostInstalls, + }, + ) } // GenerateSingletonBuildActions generates build rules for the dexpreopt config for Make. @@ -968,6 +991,14 @@ func packageFileForTargetImage(ctx android.ModuleContext, image *bootImageVarian } } +var artBootImageHostInfoProvider = blueprint.NewProvider[artBootImageHostInfo]() + +// artBootImageHostInfo contains the install locations of the host variant of ART boot image +// this contains both the primary and secondary arch locations +type artBootImageHostInfo struct { + installs android.RuleBuilderInstalls +} + // Generate boot image build rules for a specific target. func buildBootImageVariant(ctx android.ModuleContext, image *bootImageVariant, profile android.Path) bootImageVariantOutputs { @@ -1396,3 +1427,70 @@ func (d *dexpreoptBootJars) AndroidMkEntries() []android.AndroidMkEntries { OutputFile: android.OptionalPathForPath(d.bootFrameworkProfile), }} } + +// artBootImages is a thin wrapper around `dex_bootjars`. +// it creates the installation rules for the host variant of the ART boot image. +type artBootImages struct { + android.ModuleBase + + // A non-empty file that will be written as `LOCAL_SOONG_INSTALLED_MODULE` in out/soong/Android-*.mk + outputFile android.OptionalPath +} + +func artBootImagesFactory() android.Module { + m := &artBootImages{} + android.InitAndroidMultiTargetsArchModule(m, android.HostSupported, android.MultilibCommon) + return m +} + +func (dbj *artBootImages) DepsMutator(ctx android.BottomUpMutatorContext) { + // Create a dependency on `dex_bootjars` to access the intermediate locations of host art boot image. + ctx.AddDependency(ctx.Module(), dexpreoptBootJarDepTag, "dex_bootjars") +} + +func (d *artBootImages) GenerateAndroidBuildActions(ctx android.ModuleContext) { + ctx.VisitDirectDepsWithTag(dexpreoptBootJarDepTag, func(m android.Module) { + hostInstallsInfo, ok := android.OtherModuleProvider(ctx, m, artBootImageHostInfoProvider) + if !ok { + ctx.ModuleErrorf("Could not find information about the host variant of ART boot image") + } + installs := d.installFile(ctx, hostInstallsInfo.installs) + if len(installs) > 0 { + d.outputFile = android.OptionalPathForPath(installs[0]) + // Create a phony target that can ART run-tests can depend on. + ctx.Phony(d.Name(), installs...) + } else { + // this might be true e.g. when building with `WITH_DEXPREOPT=false` + // create an empty file so that the `art_boot_images` is known to the packaging system. + d.outputFile = android.OptionalPathForPath(android.PathForModuleOut(ctx, "undefined_art_boot_images")) + } + }) +} + +// Creates an installation rule for host variant of ART boot image files. +// Returns the list of install locations (out/host/linux-x86/...) +func (d *artBootImages) installFile(ctx android.ModuleContext, ruleBuilderInstalls android.RuleBuilderInstalls) android.Paths { + var ret android.Paths + for _, ruleBuilderInstall := range ruleBuilderInstalls { + installDir := android.PathForModuleInstall( + ctx, + strings.TrimPrefix(filepath.Dir(ruleBuilderInstall.To), "/"), + ) + filename := filepath.Base(ruleBuilderInstall.To) + ctx.InstallFile( + installDir, + filename, + ruleBuilderInstall.From, + ) + ret = append(ret, installDir.Join(ctx, filename)) + } + return ret +} + +// Set `OutputFile` expclitly so that this module does not get elided when generating out/soong/Android-*.mk +func (d *artBootImages) AndroidMkEntries() []android.AndroidMkEntries { + return []android.AndroidMkEntries{{ + Class: "ETC", + OutputFile: d.outputFile, + }} +} |