Move bootFrameworkProfileRule to platform_bootclasspath

Changes bootFrameworkProfileRule to use ModuleContext instead of
SingletonContext and moves the call from dexpreoptBootJar's
GenerateSingletonBuildActions method to platform_bootclasspath's
GenerateAndroidBuildActions.

Changing the context also allows the code to switch from
bootFrameworkProfileRule to GetGlobalSoongConfig.

Also extracts the shouldBuildBootImages function so it can be used by
platform_bootclasspath to preserve the existing behavior.

Bug: 177892522
Test: m droid
Change-Id: I30d3ca10be7f84348ad3aa9cc984dd15b8f6f4e9
This commit is contained in:
Paul Duffin 2021-04-26 16:44:00 +01:00
parent 59dc69c2c7
commit ad19d3858e
2 changed files with 38 additions and 16 deletions

View File

@ -423,14 +423,7 @@ func (d *dexpreoptBootJars) GenerateSingletonBuildActions(ctx android.SingletonC
writeGlobalConfigForMake(ctx, d.dexpreoptConfigForMake)
global := dexpreopt.GetGlobalConfig(ctx)
// Skip recompiling the boot image for the second sanitization phase. We'll get separate paths
// and invalidate first-stage artifacts which are crucial to SANITIZE_LITE builds.
// Note: this is technically incorrect. Compiled code contains stack checks which may depend
// on ASAN settings.
if len(ctx.Config().SanitizeDevice()) == 1 &&
ctx.Config().SanitizeDevice()[0] == "address" &&
global.SanitizeLite {
if !shouldBuildBootImages(ctx.Config(), global) {
return
}
@ -438,9 +431,6 @@ func (d *dexpreoptBootJars) GenerateSingletonBuildActions(ctx android.SingletonC
defaultImageConfig := defaultBootImageConfig(ctx)
profile := bootImageProfileRule(ctx, defaultImageConfig)
// Generate the framework profile rule
bootFrameworkProfileRule(ctx, defaultImageConfig)
// Generate the updatable bootclasspath packages rule.
updatableBcpPackagesRule(ctx, defaultImageConfig)
@ -455,6 +445,18 @@ func (d *dexpreoptBootJars) GenerateSingletonBuildActions(ctx android.SingletonC
dumpOatRules(ctx, d.defaultBootImage)
}
// shouldBuildBootImages determines whether boot images should be built.
func shouldBuildBootImages(config android.Config, global *dexpreopt.GlobalConfig) bool {
// Skip recompiling the boot image for the second sanitization phase. We'll get separate paths
// and invalidate first-stage artifacts which are crucial to SANITIZE_LITE builds.
// Note: this is technically incorrect. Compiled code contains stack checks which may depend
// on ASAN settings.
if len(config.SanitizeDevice()) == 1 && config.SanitizeDevice()[0] == "address" && global.SanitizeLite {
return false
}
return true
}
// Inspect this module to see if it contains a bootclasspath dex jar.
// Note that the same jar may occur in multiple modules.
// This logic is tested in the apex package to avoid import cycle apex <-> java.
@ -853,8 +855,10 @@ func bootImageProfileRule(ctx android.SingletonContext, image *bootImageConfig)
return profile
}
func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImageConfig) android.WritablePath {
globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
// bootFrameworkProfileRule generates the rule to create the boot framework profile and
// returns a path to the generated file.
func bootFrameworkProfileRule(ctx android.ModuleContext, image *bootImageConfig) android.WritablePath {
globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
global := dexpreopt.GetGlobalConfig(ctx)
if global.DisableGenerateProfile || ctx.Config().UnbundledBuild() {

View File

@ -168,9 +168,7 @@ func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.Mo
return
}
// Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
// GenerateSingletonBuildActions method as it cannot create it for itself.
dexpreopt.GetGlobalSoongConfig(ctx)
b.generateBootImageBuildActions(ctx)
}
func (b *platformBootclasspathModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
@ -297,3 +295,23 @@ func (b *platformBootclasspathModule) generatedHiddenAPIMetadataRules(ctx androi
rule.Build("platform-bootclasspath-monolithic-hiddenapi-metadata", "monolithic hidden API metadata")
}
// generateBootImageBuildActions generates ninja rules related to the boot image creation.
func (b *platformBootclasspathModule) generateBootImageBuildActions(ctx android.ModuleContext) {
// Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
// GenerateSingletonBuildActions method as it cannot create it for itself.
dexpreopt.GetGlobalSoongConfig(ctx)
imageConfig := b.getImageConfig(ctx)
if imageConfig == nil {
return
}
global := dexpreopt.GetGlobalConfig(ctx)
if !shouldBuildBootImages(ctx.Config(), global) {
return
}
// Generate the framework profile rule
bootFrameworkProfileRule(ctx, imageConfig)
}