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

Commit cc1bd836 authored by Paul Duffin's avatar Paul Duffin Committed by Gerrit Code Review
Browse files

Merge "Make copyBootJarsToPredefinedLocations simpler and less fragile"

parents a11b8707 5f148ca7
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1690,6 +1690,16 @@ func (l *ConfiguredJarList) BuildPaths(ctx PathContext, dir OutputPath) Writable
	return paths
}

// BuildPathsByModule returns a map from module name to build paths based on the given directory
// prefix.
func (l *ConfiguredJarList) BuildPathsByModule(ctx PathContext, dir OutputPath) map[string]WritablePath {
	paths := map[string]WritablePath{}
	for _, jar := range l.jars {
		paths[jar] = dir.Join(ctx, ModuleStem(jar)+".jar")
	}
	return paths
}

// UnmarshalJSON converts JSON configuration from raw bytes into a
// ConfiguredJarList structure.
func (l *ConfiguredJarList) UnmarshalJSON(b []byte) error {
+1 −1
Original line number Diff line number Diff line
@@ -4769,7 +4769,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
		// prebuilt_apex module always depends on the prebuilt, and so it doesn't
		// find the dex boot jar in it. We either need to disable the source libfoo
		// or make the prebuilt libfoo preferred.
		testDexpreoptWithApexes(t, bp, "failed to find a dex jar path for module 'libfoo'", preparer)
		testDexpreoptWithApexes(t, bp, "module libfoo does not provide a dex boot jar", preparer)
	})

	t.Run("prebuilt library preferred with source", func(t *testing.T) {
+2 −1
Original line number Diff line number Diff line
@@ -648,7 +648,8 @@ func (b *BootclasspathFragmentModule) generateBootImageBuildActions(ctx android.
	}

	// Copy the dex jars of this fragment's content modules to their predefined locations.
	copyBootJarsToPredefinedLocations(ctx, contents, imageConfig.modules, imageConfig.dexPaths)
	bootDexJarByModule := extractEncodedDexJarsFromModules(ctx, contents)
	copyBootJarsToPredefinedLocations(ctx, bootDexJarByModule, imageConfig.dexPathsByModule)

	// Build a profile for the image config and then use that to build the boot image.
	profile := bootImageProfileRule(ctx, imageConfig)
+21 −45
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@
package java

import (
	"fmt"
	"path/filepath"
	"sort"
	"strings"
@@ -254,6 +253,9 @@ type bootImageConfig struct {
	dexPaths     android.WritablePaths // for this image
	dexPathsDeps android.WritablePaths // for the dependency images and in this image

	// Map from module name (without prebuilt_ prefix) to the predefined build path.
	dexPathsByModule map[string]android.WritablePath

	// File path to a zip archive with all image files (or nil, if not needed).
	zip android.WritablePath

@@ -461,53 +463,27 @@ func shouldBuildBootImages(config android.Config, global *dexpreopt.GlobalConfig
	return true
}

// copyBootJarsToPredefinedLocations generates commands that will copy boot jars to
// predefined paths in the global config.
func copyBootJarsToPredefinedLocations(ctx android.ModuleContext, bootModules []android.Module, bootjars android.ConfiguredJarList, jarPathsPredefined android.WritablePaths) {
	jarPaths := make(android.Paths, bootjars.Len())
	for i, module := range bootModules {
		if module != nil {
			bootDexJar := module.(interface{ DexJarBuildPath() android.Path }).DexJarBuildPath()
			jarPaths[i] = bootDexJar

			name := android.RemoveOptionalPrebuiltPrefix(ctx.OtherModuleName(module))
			if bootjars.Jar(i) != name {
				ctx.ModuleErrorf("expected module %s at position %d but found %s", bootjars.Jar(i), i, name)
			}
		}
	}

	// The paths to bootclasspath DEX files need to be known at module GenerateAndroidBuildAction
	// time, before the boot images are built (these paths are used in dexpreopt rule generation for
	// Java libraries and apps). Generate rules that copy bootclasspath DEX jars to the predefined
	// paths.
	for i := range jarPaths {
		input := jarPaths[i]
		output := jarPathsPredefined[i]
		module := bootjars.Jar(i)
		if input == nil {
			if ctx.Config().AllowMissingDependencies() {
				apex := bootjars.Apex(i)

				// Create an error rule that pretends to create the output file but will actually fail if it
				// is run.
				ctx.Build(pctx, android.BuildParams{
					Rule:   android.ErrorRule,
					Output: output,
					Args: map[string]string{
						"error": fmt.Sprintf("missing dependencies: dex jar for %s:%s", module, apex),
					},
				})
			} else {
				ctx.ModuleErrorf("failed to find a dex jar path for module '%s'"+
					", note that some jars may be filtered out by module constraints", module)
			}

// copyBootJarsToPredefinedLocations generates commands that will copy boot jars to predefined
// paths in the global config.
func copyBootJarsToPredefinedLocations(ctx android.ModuleContext, srcBootDexJarsByModule bootDexJarByModule, dstBootJarsByModule map[string]android.WritablePath) {
	// Create the super set of module names.
	names := []string{}
	names = append(names, android.SortedStringKeys(srcBootDexJarsByModule)...)
	names = append(names, android.SortedStringKeys(dstBootJarsByModule)...)
	names = android.SortedUniqueStrings(names)
	for _, name := range names {
		src := srcBootDexJarsByModule[name]
		dst := dstBootJarsByModule[name]

		if src == nil {
			ctx.ModuleErrorf("module %s does not provide a dex boot jar", name)
		} else if dst == nil {
			ctx.ModuleErrorf("module %s is not part of the boot configuration", name)
		} else {
			ctx.Build(pctx, android.BuildParams{
				Rule:   android.Cp,
				Input:  input,
				Output: output,
				Input:  src,
				Output: dst,
			})
		}
	}
+6 −1
Original line number Diff line number Diff line
@@ -100,6 +100,7 @@ func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig {
			// TODO(b/143682396): use module dependencies instead
			inputDir := deviceDir.Join(ctx, "dex_"+c.name+"jars_input")
			c.dexPaths = c.modules.BuildPaths(ctx, inputDir)
			c.dexPathsByModule = c.modules.BuildPathsByModule(ctx, inputDir)
			c.dexPathsDeps = c.dexPaths

			// Create target-specific variants.
@@ -153,6 +154,9 @@ type updatableBootConfig struct {
	// later on a singleton adds commands to copy actual jars to the predefined paths.
	dexPaths android.WritablePaths

	// Map from module name (without prebuilt_ prefix) to the predefined build path.
	dexPathsByModule map[string]android.WritablePath

	// A list of dex locations (a.k.a. on-device paths) to the boot jars.
	dexLocations []string
}
@@ -166,10 +170,11 @@ func GetUpdatableBootConfig(ctx android.PathContext) updatableBootConfig {

		dir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "updatable_bootjars")
		dexPaths := updatableBootJars.BuildPaths(ctx, dir)
		dexPathsByModuleName := updatableBootJars.BuildPathsByModule(ctx, dir)

		dexLocations := updatableBootJars.DevicePaths(ctx.Config(), android.Android)

		return updatableBootConfig{updatableBootJars, dexPaths, dexLocations}
		return updatableBootConfig{updatableBootJars, dexPaths, dexPathsByModuleName, dexLocations}
	}).(updatableBootConfig)
}

Loading