Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0caabb6e authored by Ulyana Trafimovich's avatar Ulyana Trafimovich Committed by Gerrit Code Review
Browse files

Merge "Support building boot images with disabled dexpreopt."

parents 1c8e5e81 a4a1c4ee
Loading
Loading
Loading
Loading
+21 −6
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import (
	"android/soong/android"
	"android/soong/bpf"
	"android/soong/cc"
	"android/soong/dexpreopt"
	prebuilt_etc "android/soong/etc"
	"android/soong/filesystem"
	"android/soong/java"
@@ -720,10 +721,16 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
	ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.properties.Bpfs...)
	ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...)

	if a.artApex {
		// With EMMA_INSTRUMENT_FRAMEWORK=true the ART boot image includes jacoco library.
	if a.artApex && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
		if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
			ctx.AddFarVariationDependencies(commonVariation, javaLibTag, "jacocoagent")
		}
		// The ART boot image depends on dex2oat to compile it.
		if !java.SkipDexpreoptBootJars(ctx) {
			dexpreopt.RegisterToolDeps(ctx)
		}
	}

	// Dependencies for signing
	if String(a.properties.Key) == "" {
@@ -1521,6 +1528,9 @@ func (a *apexBundle) WalkPayloadDeps(ctx android.ModuleContext, do android.Paylo
		if dt, ok := depTag.(dependencyTag); ok && !dt.payload {
			return false
		}
		if depTag == dexpreopt.Dex2oatDepTag {
			return false
		}

		ai := ctx.OtherModuleProvider(child, android.ApexInfoProvider).(android.ApexInfo)
		externalDep := !android.InList(ctx.ModuleName(), ai.InApexes)
@@ -1842,10 +1852,10 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
		return
	}

	if a.artApex {
		// Specific to the ART apex: dexpreopt artifacts for libcore Java libraries. Build rules are
		// generated by the dexpreopt singleton, and here we access build artifacts via the global
		// boot image config.
	if a.artApex {
		for arch, files := range java.DexpreoptedArtApexJars(ctx) {
			dirInApex := filepath.Join("javalib", arch.String())
			for _, f := range files {
@@ -1854,6 +1864,11 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
				filesInfo = append(filesInfo, af)
			}
		}
		// Call GetGlobalSoongConfig to initialize it, which may be necessary if dexpreopt is
		// disabled for libraries/apps, but boot images are still needed.
		if !java.SkipDexpreoptBootJars(ctx) {
			dexpreopt.GetGlobalSoongConfig(ctx)
		}
	}

	// Remove duplicates in filesInfo
+11 −9
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@ import (
// GlobalConfig stores the configuration for dex preopting. The fields are set
// from product variables via dex_preopt_config.mk.
type GlobalConfig struct {
	DisablePreopt        bool     // disable preopt for all modules
	DisablePreopt           bool     // disable preopt for all modules (excluding boot images)
	DisablePreoptBootImages bool     // disable prepot for boot images
	DisablePreoptModules    []string // modules with preopt disabled by product-specific config

	OnlyPreoptBootImageAndSystemServer bool // only preopt jars in the boot image or system server
@@ -235,6 +236,7 @@ func getGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw {
			// Nope, return a config with preopting disabled
			return globalConfigAndRaw{&GlobalConfig{
				DisablePreopt:           true,
				DisablePreoptBootImages: true,
				DisableGenerateProfile:  true,
			}, nil}
		})
@@ -305,7 +307,7 @@ func dex2oatModuleName(config android.Config) string {
	}
}

var dex2oatDepTag = struct {
var Dex2oatDepTag = struct {
	blueprint.BaseDependencyTag
}{}

@@ -316,7 +318,7 @@ var dex2oatDepTag = struct {
func RegisterToolDeps(ctx android.BottomUpMutatorContext) {
	dex2oatBin := dex2oatModuleName(ctx.Config())
	v := ctx.Config().BuildOSTarget.Variations()
	ctx.AddFarVariationDependencies(v, dex2oatDepTag, dex2oatBin)
	ctx.AddFarVariationDependencies(v, Dex2oatDepTag, dex2oatBin)
}

func dex2oatPathFromDep(ctx android.ModuleContext) android.Path {
@@ -332,7 +334,7 @@ func dex2oatPathFromDep(ctx android.ModuleContext) android.Path {
	// prebuilt explicitly here instead.
	var dex2oatModule android.Module
	ctx.WalkDeps(func(child, parent android.Module) bool {
		if parent == ctx.Module() && ctx.OtherModuleDependencyTag(child) == dex2oatDepTag {
		if parent == ctx.Module() && ctx.OtherModuleDependencyTag(child) == Dex2oatDepTag {
			// Found the source module, or prebuilt module that has replaced the source.
			dex2oatModule = child
			if p, ok := child.(android.PrebuiltInterface); ok && p.Prebuilt() != nil {
@@ -385,10 +387,10 @@ func createGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig {

// The main reason for this Once cache for GlobalSoongConfig is to make the
// dex2oat path available to singletons. In ordinary modules we get it through a
// dex2oatDepTag dependency, but in singletons there's no simple way to do the
// Dex2oatDepTag dependency, but in singletons there's no simple way to do the
// same thing and ensure the right variant is selected, hence this cache to make
// the resolved path available to singletons. This means we depend on there
// being at least one ordinary module with a dex2oatDepTag dependency.
// being at least one ordinary module with a Dex2oatDepTag dependency.
//
// TODO(b/147613152): Implement a way to deal with dependencies from singletons,
// and then possibly remove this cache altogether (but the use in
+5 −5
Original line number Diff line number Diff line
@@ -347,8 +347,8 @@ func RegisterDexpreoptBootJarsComponents(ctx android.RegistrationContext) {
	ctx.RegisterSingletonType("dex_bootjars", dexpreoptBootJarsFactory)
}

func skipDexpreoptBootJars(ctx android.PathContext) bool {
	return dexpreopt.GetGlobalConfig(ctx).DisablePreopt
func SkipDexpreoptBootJars(ctx android.PathContext) bool {
	return dexpreopt.GetGlobalConfig(ctx).DisablePreoptBootImages
}

// Singleton for generating boot image build rules.
@@ -371,7 +371,7 @@ type dexpreoptBootJars struct {

// Accessor function for the apex package. Returns nil if dexpreopt is disabled.
func DexpreoptedArtApexJars(ctx android.BuilderContext) map[android.ArchType]android.OutputPaths {
	if skipDexpreoptBootJars(ctx) {
	if SkipDexpreoptBootJars(ctx) {
		return nil
	}
	// Include dexpreopt files for the primary boot image.
@@ -387,7 +387,7 @@ func DexpreoptedArtApexJars(ctx android.BuilderContext) map[android.ArchType]and

// Generate build rules for boot images.
func (d *dexpreoptBootJars) GenerateBuildActions(ctx android.SingletonContext) {
	if skipDexpreoptBootJars(ctx) {
	if SkipDexpreoptBootJars(ctx) {
		return
	}
	if dexpreopt.GetCachedGlobalSoongConfig(ctx) == nil {
@@ -727,7 +727,7 @@ func bootImageProfileRule(ctx android.SingletonContext, image *bootImageConfig,
	globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
	global := dexpreopt.GetGlobalConfig(ctx)

	if global.DisableGenerateProfile || ctx.Config().UnbundledBuild() {
	if global.DisableGenerateProfile {
		return nil
	}
	profile := ctx.Config().Once(bootImageProfileRuleKey, func() interface{} {