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

Commit 0f41678d authored by Dan Willemsen's avatar Dan Willemsen
Browse files

Expand the dexpreopt image dependencies to entire image

Instead of just depending on the main .art file (boot.art, etc), also
expose the dependencies to the .oat/.vdex files (boot.oat/boot.vdex),
and all of the module files that get implicitly loading (boot-ext.*,
boot-framework.*, etc)

This is necessary for RBE, where the rule only gets the files that it
depends upon.

Test: treehugger
Test: build a system image with RBE
Change-Id: I0c7051f18582f1891d3398b46763b1521e4326c8
parent ff60a73d
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ type ModuleConfig struct {

	Archs               []android.ArchType
	DexPreoptImages     []android.Path
	DexPreoptImagesDeps []android.Paths

	PreoptBootClassPathDexFiles     android.Paths // file paths of boot class path files
	PreoptBootClassPathDexLocations []string      // virtual locations of boot class path files
@@ -257,6 +258,9 @@ func LoadModuleConfig(ctx android.PathContext, path string) (ModuleConfig, error
	config.ModuleConfig.StripInputPath = constructPath(ctx, config.StripInputPath)
	config.ModuleConfig.StripOutputPath = constructWritablePath(ctx, config.StripOutputPath)

	// This needs to exist, but dependencies are already handled in Make, so we don't need to pass them through JSON.
	config.ModuleConfig.DexPreoptImagesDeps = make([]android.Paths, len(config.ModuleConfig.DexPreoptImages))

	return config.ModuleConfig, nil
}

+4 −3
Original line number Diff line number Diff line
@@ -125,7 +125,8 @@ func GenerateDexpreoptRule(ctx android.PathContext,

			for i, arch := range module.Archs {
				image := module.DexPreoptImages[i]
				dexpreoptCommand(ctx, global, module, rule, arch, profile, image, appImage, generateDM)
				imageDeps := module.DexPreoptImagesDeps[i]
				dexpreoptCommand(ctx, global, module, rule, arch, profile, image, imageDeps, appImage, generateDM)
			}
		}
	}
@@ -190,7 +191,7 @@ func profileCommand(ctx android.PathContext, global GlobalConfig, module ModuleC
}

func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module ModuleConfig, rule *android.RuleBuilder,
	arch android.ArchType, profile, bootImage android.Path, appImage, generateDM bool) {
	arch android.ArchType, profile, bootImage android.Path, bootImageDeps android.Paths, appImage, generateDM bool) {

	// HACK: make soname in Soong-generated .odex files match Make.
	base := filepath.Base(module.DexLocation)
@@ -353,7 +354,7 @@ func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module Modul
		Flag("--runtime-arg").FlagWithList("-Xbootclasspath-locations:", module.PreoptBootClassPathDexLocations, ":").
		Flag("${class_loader_context_arg}").
		Flag("${stored_class_loader_context_arg}").
		FlagWithArg("--boot-image=", bootImageLocation).Implicit(bootImage).
		FlagWithArg("--boot-image=", bootImageLocation).Implicits(bootImageDeps).
		FlagWithInput("--dex-file=", module.DexPath).
		FlagWithArg("--dex-location=", dexLocationArg).
		FlagWithOutput("--oat-file=", odexPath).ImplicitOutput(vdexPath).
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ func testModuleConfig(ctx android.PathContext) ModuleConfig {
		LibraryPaths:                    nil,
		Archs:                           []android.ArchType{android.Arm},
		DexPreoptImages:                 android.Paths{android.PathForTesting("system/framework/arm/boot.art")},
		DexPreoptImagesDeps:             []android.Paths{android.Paths{}},
		PreoptBootClassPathDexFiles:     nil,
		PreoptBootClassPathDexLocations: nil,
		PreoptExtractedApk:              false,
+5 −2
Original line number Diff line number Diff line
@@ -132,8 +132,10 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo
	}

	var images android.Paths
	var imagesDeps []android.Paths
	for _, arch := range archs {
		images = append(images, bootImage.images[arch])
		imagesDeps = append(imagesDeps, bootImage.imagesDeps[arch])
	}

	dexLocation := android.InstallPathToOnDevicePath(ctx, d.installPath)
@@ -175,6 +177,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo

		Archs:               archs,
		DexPreoptImages:     images,
		DexPreoptImagesDeps: imagesDeps,

		// We use the dex paths and dex locations of the default boot image, as it
		// contains the full dexpreopt boot classpath. Other images may just contain a subset of
+37 −24
Original line number Diff line number Diff line
@@ -58,9 +58,32 @@ type bootImageConfig struct {
	symbolsDir   android.OutputPath
	targets      []android.Target
	images       map[android.ArchType]android.OutputPath
	imagesDeps   map[android.ArchType]android.Paths
	zip          android.WritablePath
}

func (image bootImageConfig) moduleFiles(ctx android.PathContext, dir android.OutputPath, exts ...string) []android.OutputPath {
	ret := make([]android.OutputPath, 0, len(image.modules)*len(exts))

	// dex preopt on the bootclasspath produces multiple files.  The first dex file
	// is converted into to 'name'.art (to match the legacy assumption that 'name'.art
	// exists), and the rest are converted to 'name'-<jar>.art.
	// In addition, each .art file has an associated .oat and .vdex file, and an
	// unstripped .oat file
	for i, m := range image.modules {
		name := image.name
		if i != 0 {
			name += "-" + m
		}

		for _, ext := range exts {
			ret = append(ret, dir.Join(ctx, name+ext))
		}
	}

	return ret
}

type bootImage struct {
	bootImageConfig

@@ -302,49 +325,38 @@ func buildBootImageRuleForArch(ctx android.SingletonContext, image *bootImage,
	installDir := filepath.Join("/system/framework", arch.String())
	vdexInstallDir := filepath.Join("/system/framework")

	var extraFiles android.WritablePaths
	var vdexInstalls android.RuleBuilderInstalls
	var unstrippedInstalls android.RuleBuilderInstalls

	var zipFiles android.WritablePaths

	// dex preopt on the bootclasspath produces multiple files.  The first dex file
	// is converted into to 'name'.art (to match the legacy assumption that 'name'.art
	// exists), and the rest are converted to 'name'-<jar>.art.
	// In addition, each .art file has an associated .oat and .vdex file, and an
	// unstripped .oat file
	for i, m := range image.modules {
		name := image.name
		if i != 0 {
			name += "-" + m
		}

		art := outputDir.Join(ctx, name+".art")
		oat := outputDir.Join(ctx, name+".oat")
		vdex := outputDir.Join(ctx, name+".vdex")
		unstrippedOat := symbolsDir.Join(ctx, name+".oat")

		extraFiles = append(extraFiles, art, oat, vdex, unstrippedOat)
	for _, artOrOat := range image.moduleFiles(ctx, outputDir, ".art", ".oat") {
		cmd.ImplicitOutput(artOrOat)
		zipFiles = append(zipFiles, artOrOat)

		zipFiles = append(zipFiles, art, oat, vdex)
		// Install the .oat and .art files
		rule.Install(artOrOat, filepath.Join(installDir, artOrOat.Base()))
	}

		// Install the .oat and .art files.
		rule.Install(art, filepath.Join(installDir, art.Base()))
		rule.Install(oat, filepath.Join(installDir, oat.Base()))
	for _, vdex := range image.moduleFiles(ctx, outputDir, ".vdex") {
		cmd.ImplicitOutput(vdex)
		zipFiles = append(zipFiles, vdex)

		// The vdex files are identical between architectures, install them to a shared location.  The Make rules will
		// only use the install rules for one architecture, and will create symlinks into the architecture-specific
		// directories.
		vdexInstalls = append(vdexInstalls,
			android.RuleBuilderInstall{vdex, filepath.Join(vdexInstallDir, vdex.Base())})
	}

	for _, unstrippedOat := range image.moduleFiles(ctx, symbolsDir, ".oat") {
		cmd.ImplicitOutput(unstrippedOat)

		// Install the unstripped oat files.  The Make rules will put these in $(TARGET_OUT_UNSTRIPPED)
		unstrippedInstalls = append(unstrippedInstalls,
			android.RuleBuilderInstall{unstrippedOat, filepath.Join(installDir, unstrippedOat.Base())})
	}

	cmd.ImplicitOutputs(extraFiles)

	rule.Build(pctx, ctx, image.name+"JarsDexpreopt_"+arch.String(), "dexpreopt "+image.name+" jars "+arch.String())

	// save output and installed files for makevars
@@ -496,6 +508,7 @@ func (d *dexpreoptBootJars) MakeVars(ctx android.MakeVarsContext) {
			for _, arch := range arches {
				ctx.Strict("DEXPREOPT_IMAGE_VDEX_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.vdexInstalls[arch].String())
				ctx.Strict("DEXPREOPT_IMAGE_"+current.name+"_"+arch.String(), current.images[arch].String())
				ctx.Strict("DEXPREOPT_IMAGE_DEPS_"+current.name+"_"+arch.String(), strings.Join(current.imagesDeps[arch].Strings(), " "))
				ctx.Strict("DEXPREOPT_IMAGE_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.installs[arch].String())
				ctx.Strict("DEXPREOPT_IMAGE_UNSTRIPPED_BUILT_INSTALLED_"+current.name+"_"+arch.String(), current.unstrippedInstalls[arch].String())
				if current.zip != nil {
Loading