Extract default image specific logic from buildBootImage

Previously, buildBootImage had to be called for the default boot image
config before the art boot image config as it created some rules which
were specific to default boot image. The creation of these rules was
encapsulated in Config().Once(..) to ensure that they were only ever
created once.

This change extracts that functionality out of buildBootImage to the
calling method which means that they are only called once and so no
longer need protecting against being called again.

Bug: 177892522
Test: m droid
Change-Id: I464477de1a08df15e577873a9accf7db2bc088d1
This commit is contained in:
Paul Duffin
2021-04-26 12:51:07 +01:00
parent 57e2e7d199
commit 5861242a78

View File

@@ -434,10 +434,21 @@ func (d *dexpreoptBootJars) GenerateSingletonBuildActions(ctx android.SingletonC
return
}
// Always create the default boot image first, to get a unique profile rule for all images.
d.defaultBootImage = buildBootImage(ctx, defaultBootImageConfig(ctx))
// Generate the profile rule from the default boot image.
defaultImageConfig := defaultBootImageConfig(ctx)
profile := bootImageProfileRule(ctx, defaultImageConfig)
// Generate the framework profile rule
bootFrameworkProfileRule(ctx, defaultImageConfig)
// Generate the updatable bootclasspath packages rule.
updatableBcpPackagesRule(ctx, defaultImageConfig)
// Create the default boot image.
d.defaultBootImage = buildBootImage(ctx, defaultImageConfig, profile)
// Create boot image for the ART apex (build artifacts are accessed via the global boot image config).
d.otherImages = append(d.otherImages, buildBootImage(ctx, artBootImageConfig(ctx)))
d.otherImages = append(d.otherImages, buildBootImage(ctx, artBootImageConfig(ctx), profile))
copyUpdatableBootJars(ctx)
@@ -605,16 +616,12 @@ func findAndCopyBootJars(ctx android.SingletonContext, bootjars android.Configur
}
// buildBootImage takes a bootImageConfig, creates rules to build it, and returns the image.
func buildBootImage(ctx android.SingletonContext, image *bootImageConfig) *bootImageConfig {
func buildBootImage(ctx android.SingletonContext, image *bootImageConfig, profile android.WritablePath) *bootImageConfig {
getBootJarFunc := func(module android.Module) (int, android.Path) {
return getBootImageJar(ctx, image, module)
}
findAndCopyBootJars(ctx, image.modules, image.dexPaths, getBootJarFunc)
profile := bootImageProfileRule(ctx, image)
bootFrameworkProfileRule(ctx, image)
updatableBcpPackagesRule(ctx, image)
var zipFiles android.Paths
for _, variant := range image.variants {
files := buildBootImageVariant(ctx, variant, profile)
@@ -805,7 +812,7 @@ func bootImageProfileRule(ctx android.SingletonContext, image *bootImageConfig)
if global.DisableGenerateProfile {
return nil
}
profile := ctx.Config().Once(bootImageProfileRuleKey, func() interface{} {
defaultProfile := "frameworks/base/config/boot-image-profile.txt"
rule := android.NewRuleBuilder(pctx, ctx)
@@ -844,15 +851,8 @@ func bootImageProfileRule(ctx android.SingletonContext, image *bootImageConfig)
image.profileInstalls = rule.Installs()
return profile
})
if profile == nil {
return nil // wrap nil into a typed pointer with value nil
}
return profile.(android.WritablePath)
}
var bootImageProfileRuleKey = android.NewOnceKey("bootImageProfileRule")
func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImageConfig) android.WritablePath {
globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
global := dexpreopt.GetGlobalConfig(ctx)
@@ -860,7 +860,6 @@ func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImageConf
if global.DisableGenerateProfile || ctx.Config().UnbundledBuild() {
return nil
}
return ctx.Config().Once(bootFrameworkProfileRuleKey, func() interface{} {
// Some branches like master-art-host don't have frameworks/base, so manually
// handle the case that the default is missing. Those branches won't attempt to build the profile rule,
@@ -894,17 +893,13 @@ func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImageConf
image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
return profile
}).(android.WritablePath)
}
var bootFrameworkProfileRuleKey = android.NewOnceKey("bootFrameworkProfileRule")
func updatableBcpPackagesRule(ctx android.SingletonContext, image *bootImageConfig) android.WritablePath {
if ctx.Config().UnbundledBuild() {
return nil
}
return ctx.Config().Once(updatableBcpPackagesRuleKey, func() interface{} {
global := dexpreopt.GetGlobalConfig(ctx)
updatableModules := global.UpdatableBootJars.CopyOfJars()
@@ -945,11 +940,8 @@ func updatableBcpPackagesRule(ctx android.SingletonContext, image *bootImageConf
image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
return updatableBcpPackages
}).(android.WritablePath)
}
var updatableBcpPackagesRuleKey = android.NewOnceKey("updatableBcpPackagesRule")
func dumpOatRules(ctx android.SingletonContext, image *bootImageConfig) {
var allPhonies android.Paths
for _, image := range image.variants {