diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go index e3b548722..704164e08 100644 --- a/java/dexpreopt_bootjars.go +++ b/java/dexpreopt_bootjars.go @@ -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() { diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go index 05b8e2fa2..6503eca87 100644 --- a/java/platform_bootclasspath.go +++ b/java/platform_bootclasspath.go @@ -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) +}