Merge "Generate boot zip file from prebuilt_bootclasspath_fragment" am: 452decbd88 am: 019e278025

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1753271

Change-Id: I969dde3851899374bd466c9a0e5263f0fe6d12c8
This commit is contained in:
Paul Duffin
2021-07-05 12:27:08 +00:00
committed by Automerger Merge Worker
3 changed files with 61 additions and 50 deletions

View File

@@ -162,11 +162,12 @@ type commonBootclasspathFragment interface {
// versioned sdk.
produceHiddenAPIOutput(ctx android.ModuleContext, contents []android.Module, input HiddenAPIFlagInput) *HiddenAPIOutput
// produceBootImageFiles produces the boot image (i.e. .art, .oat and .vdex) files for each of the
// required android.ArchType values in the returned map.
// produceBootImageFiles will attempt to produce rules to create the boot image files at the paths
// predefined in the bootImageConfig.
//
// It must return nil if the boot image files cannot be produced for whatever reason.
produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig, contents []android.Module) bootImageFilesByArch
// If it could not create the files then it will return nil. Otherwise, it will return a map from
// android.ArchType to the predefined paths of the boot image files.
produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageFilesByArch
}
var _ commonBootclasspathFragment = (*BootclasspathFragmentModule)(nil)
@@ -454,9 +455,13 @@ func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.Mo
if imageConfig != nil {
// Delegate the production of the boot image files to a module type specific method.
common := ctx.Module().(commonBootclasspathFragment)
bootImageFilesByArch = common.produceBootImageFiles(ctx, imageConfig, contents)
bootImageFilesByArch = common.produceBootImageFiles(ctx, imageConfig)
if shouldCopyBootFilesToPredefinedLocations(ctx, imageConfig) {
// Zip the boot image files up, if available. This will generate the zip file in a
// predefined location.
buildBootImageZipInPredefinedLocation(ctx, imageConfig, bootImageFilesByArch)
// Copy the dex jars of this fragment's content modules to their predefined locations.
copyBootJarsToPredefinedLocations(ctx, hiddenAPIOutput.EncodedBootDexFilesByModule, imageConfig.dexPathsByModule)
}
@@ -648,7 +653,7 @@ func (b *BootclasspathFragmentModule) produceHiddenAPIOutput(ctx android.ModuleC
}
// produceBootImageFiles builds the boot image files from the source if it is required.
func (b *BootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig, contents []android.Module) bootImageFilesByArch {
func (b *BootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageFilesByArch {
if SkipDexpreoptBootJars(ctx) {
return nil
}
@@ -658,45 +663,34 @@ func (b *BootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleCo
dexpreopt.GetGlobalSoongConfig(ctx)
// Only generate the boot image if the configuration does not skip it.
if !b.generateBootImageBuildActions(ctx, contents, imageConfig) {
return nil
}
// Only make the files available to an apex if they were actually generated.
files := bootImageFilesByArch{}
for _, variant := range imageConfig.apexVariants() {
files[variant.target.Arch.ArchType] = variant.imagesDeps.Paths()
}
return files
return b.generateBootImageBuildActions(ctx, imageConfig)
}
// generateBootImageBuildActions generates ninja rules to create the boot image if required for this
// module.
//
// Returns true if the boot image is created, false otherwise.
func (b *BootclasspathFragmentModule) generateBootImageBuildActions(ctx android.ModuleContext, contents []android.Module, imageConfig *bootImageConfig) bool {
// If it could not create the files then it will return nil. Otherwise, it will return a map from
// android.ArchType to the predefined paths of the boot image files.
func (b *BootclasspathFragmentModule) generateBootImageBuildActions(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageFilesByArch {
global := dexpreopt.GetGlobalConfig(ctx)
if !shouldBuildBootImages(ctx.Config(), global) {
return false
return nil
}
// Bootclasspath fragment modules that are for the platform do not produce a boot image.
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if apexInfo.IsForPlatform() {
return false
return nil
}
// Bootclasspath fragment modules that are versioned do not produce a boot image.
if android.IsModuleInVersionedSdk(ctx.Module()) {
return false
return nil
}
// Build a profile for the image config and then use that to build the boot image.
profile := bootImageProfileRule(ctx, imageConfig)
buildBootImage(ctx, imageConfig, profile)
return true
return buildBootImage(ctx, imageConfig, profile)
}
// Collect information for opening IDE project files in java/jdeps.go.
@@ -924,7 +918,7 @@ func (module *prebuiltBootclasspathFragmentModule) produceHiddenAPIOutput(ctx an
}
// produceBootImageFiles extracts the boot image files from the APEX if available.
func (module *prebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig, contents []android.Module) bootImageFilesByArch {
func (module *prebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx android.ModuleContext, imageConfig *bootImageConfig) bootImageFilesByArch {
if !shouldCopyBootFilesToPredefinedLocations(ctx, imageConfig) {
return nil
}
@@ -946,6 +940,7 @@ func (module *prebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx and
}
di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo)
files := bootImageFilesByArch{}
for _, variant := range imageConfig.apexVariants() {
arch := variant.target.Arch.ArchType
for _, toPath := range variant.imagesDeps {
@@ -953,6 +948,10 @@ func (module *prebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx and
// Get the path to the file that the deapexer extracted from the prebuilt apex file.
fromPath := di.PrebuiltExportPath(apexRelativePath)
// Return the toPath as the calling code expects the paths in the returned map to be the
// paths predefined in the bootImageConfig.
files[arch] = append(files[arch], toPath)
// Copy the file to the predefined location.
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
@@ -962,10 +961,7 @@ func (module *prebuiltBootclasspathFragmentModule) produceBootImageFiles(ctx and
}
}
// The returned files will be made available to APEXes that include a bootclasspath_fragment.
// However, as a prebuilt_bootclasspath_fragment can never contribute to an APEX there is no point
// in returning any files.
return nil
return files
}
var _ commonBootclasspathFragment = (*prebuiltBootclasspathFragmentModule)(nil)