Add structured representation for colon-separated jar lists.
With the addition of apexes and /system_ext some of the bootclasspath and system server jars have moved from /system to the new locations. This has been implemented by using lists of colon-separated strings called "apex-jar pairs" (although "apex" was misleading as it could refer to "platform" or "system_ext", not necessarily a real apex). Using the colon-separated string representation is inconvenient, as it requires splitting and reassembling the list components many times, which harms performance and makes error handling difficult. Therefore this patch refactors the colon-separated lists into a struct that hides the implementation details. Test: lunch aosp_cf_x86_phone-userdebug && m Change-Id: Id248ce639a267076294f4d4d73971da2f2f77208
This commit is contained in:
@@ -49,8 +49,8 @@ type bootImageConfig struct {
|
||||
// Subdirectory where the image files are installed.
|
||||
installSubdir string
|
||||
|
||||
// The names of jars that constitute this image.
|
||||
modules []string
|
||||
// A list of (location, jar) pairs for the Java modules in this image.
|
||||
modules android.ConfiguredJarList
|
||||
|
||||
// File paths to jars.
|
||||
dexPaths android.WritablePaths // for this image
|
||||
@@ -113,16 +113,16 @@ func (image bootImageConfig) moduleName(ctx android.PathContext, idx int) string
|
||||
// Dexpreopt on the boot class path produces multiple files. The first dex file
|
||||
// is converted into 'name'.art (to match the legacy assumption that 'name'.art
|
||||
// exists), and the rest are converted to 'name'-<jar>.art.
|
||||
_, m := android.SplitApexJarPair(ctx, image.modules[idx])
|
||||
m := image.modules.Jar(idx)
|
||||
name := image.stem
|
||||
if idx != 0 || image.extends != nil {
|
||||
name += "-" + stemOf(m)
|
||||
name += "-" + android.ModuleStem(m)
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func (image bootImageConfig) firstModuleNameOrStem(ctx android.PathContext) string {
|
||||
if len(image.modules) > 0 {
|
||||
if image.modules.Len() > 0 {
|
||||
return image.moduleName(ctx, 0)
|
||||
} else {
|
||||
return image.stem
|
||||
@@ -130,8 +130,8 @@ func (image bootImageConfig) firstModuleNameOrStem(ctx android.PathContext) stri
|
||||
}
|
||||
|
||||
func (image bootImageConfig) moduleFiles(ctx android.PathContext, dir android.OutputPath, exts ...string) android.OutputPaths {
|
||||
ret := make(android.OutputPaths, 0, len(image.modules)*len(exts))
|
||||
for i := range image.modules {
|
||||
ret := make(android.OutputPaths, 0, image.modules.Len()*len(exts))
|
||||
for i := 0; i < image.modules.Len(); i++ {
|
||||
name := image.moduleName(ctx, i)
|
||||
for _, ext := range exts {
|
||||
ret = append(ret, dir.Join(ctx, name+ext))
|
||||
@@ -253,7 +253,7 @@ func getBootImageJar(ctx android.SingletonContext, image *bootImageConfig, modul
|
||||
}
|
||||
|
||||
name := ctx.ModuleName(module)
|
||||
index := android.IndexList(name, android.GetJarsFromApexJarPairs(ctx, image.modules))
|
||||
index := image.modules.IndexOfJar(name)
|
||||
if index == -1 {
|
||||
return -1, nil
|
||||
}
|
||||
@@ -295,7 +295,7 @@ func getBootImageJar(ctx android.SingletonContext, image *bootImageConfig, modul
|
||||
func buildBootImage(ctx android.SingletonContext, image *bootImageConfig) *bootImageConfig {
|
||||
// Collect dex jar paths for the boot image modules.
|
||||
// This logic is tested in the apex package to avoid import cycle apex <-> java.
|
||||
bootDexJars := make(android.Paths, len(image.modules))
|
||||
bootDexJars := make(android.Paths, image.modules.Len())
|
||||
ctx.VisitAllModules(func(module android.Module) {
|
||||
if i, j := getBootImageJar(ctx, image, module); i != -1 {
|
||||
bootDexJars[i] = j
|
||||
@@ -306,7 +306,7 @@ func buildBootImage(ctx android.SingletonContext, image *bootImageConfig) *bootI
|
||||
// Ensure all modules were converted to paths
|
||||
for i := range bootDexJars {
|
||||
if bootDexJars[i] == nil {
|
||||
_, m := android.SplitApexJarPair(ctx, image.modules[i])
|
||||
m := image.modules.Jar(i)
|
||||
if ctx.Config().AllowMissingDependencies() {
|
||||
missingDeps = append(missingDeps, m)
|
||||
bootDexJars[i] = android.PathForOutput(ctx, "missing")
|
||||
@@ -608,7 +608,7 @@ func updatableBcpPackagesRule(ctx android.SingletonContext, image *bootImageConf
|
||||
|
||||
return ctx.Config().Once(updatableBcpPackagesRuleKey, func() interface{} {
|
||||
global := dexpreopt.GetGlobalConfig(ctx)
|
||||
updatableModules := android.GetJarsFromApexJarPairs(ctx, global.UpdatableBootJars)
|
||||
updatableModules := global.UpdatableBootJars.CopyOfJars()
|
||||
|
||||
// Collect `permitted_packages` for updatable boot jars.
|
||||
var updatablePackages []string
|
||||
|
@@ -48,7 +48,7 @@ func testDexpreoptBoot(t *testing.T, ruleFile string, expectedInputs, expectedOu
|
||||
|
||||
pathCtx := android.PathContextForTesting(config)
|
||||
dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx)
|
||||
dexpreoptConfig.BootJars = []string{"platform:foo", "platform:bar", "platform:baz"}
|
||||
dexpreoptConfig.BootJars = android.CreateConfiguredJarList(pathCtx, []string{"platform:foo", "platform:bar", "platform:baz"})
|
||||
dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
|
||||
|
||||
ctx := testContext()
|
||||
|
@@ -37,14 +37,12 @@ func systemServerClasspath(ctx android.MakeVarsContext) []string {
|
||||
filepath.Join("/system/framework", m+".jar"))
|
||||
}
|
||||
// 2) The jars that are from an updatable apex.
|
||||
for _, m := range global.UpdatableSystemServerJars {
|
||||
systemServerClasspathLocations = append(systemServerClasspathLocations,
|
||||
dexpreopt.GetJarLocationFromApexJarPair(ctx, m))
|
||||
}
|
||||
if len(systemServerClasspathLocations) != len(global.SystemServerJars)+len(global.UpdatableSystemServerJars) {
|
||||
systemServerClasspathLocations = append(systemServerClasspathLocations,
|
||||
global.UpdatableSystemServerJars.DevicePaths(ctx.Config(), android.Android)...)
|
||||
if len(systemServerClasspathLocations) != len(global.SystemServerJars)+global.UpdatableSystemServerJars.Len() {
|
||||
panic(fmt.Errorf("Wrong number of system server jars, got %d, expected %d",
|
||||
len(systemServerClasspathLocations),
|
||||
len(global.SystemServerJars)+len(global.UpdatableSystemServerJars)))
|
||||
len(global.SystemServerJars)+global.UpdatableSystemServerJars.Len()))
|
||||
}
|
||||
return systemServerClasspathLocations
|
||||
})
|
||||
@@ -69,39 +67,6 @@ func dexpreoptTargets(ctx android.PathContext) []android.Target {
|
||||
return targets
|
||||
}
|
||||
|
||||
func stemOf(moduleName string) string {
|
||||
// b/139391334: the stem of framework-minus-apex is framework
|
||||
// This is hard coded here until we find a good way to query the stem
|
||||
// of a module before any other mutators are run
|
||||
if moduleName == "framework-minus-apex" {
|
||||
return "framework"
|
||||
}
|
||||
return moduleName
|
||||
}
|
||||
|
||||
func getDexLocation(ctx android.PathContext, target android.Target, module string) string {
|
||||
apex, jar := android.SplitApexJarPair(ctx, module)
|
||||
|
||||
name := stemOf(jar) + ".jar"
|
||||
|
||||
var subdir string
|
||||
if apex == "platform" {
|
||||
// Special apex name "platform" denotes jars do not come from an apex, but are part
|
||||
// of the platform. Such jars are installed on the /system partition on device.
|
||||
subdir = "system/framework"
|
||||
} else if apex == "system_ext" {
|
||||
subdir = "system_ext/framework"
|
||||
} else {
|
||||
subdir = filepath.Join("apex", apex, "javalib")
|
||||
}
|
||||
|
||||
if target.Os.Class == android.Host {
|
||||
return filepath.Join(ctx.Config().Getenv("OUT_DIR"), "host", ctx.Config().PrebuiltOS(), subdir, name)
|
||||
} else {
|
||||
return filepath.Join("/", subdir, name)
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
bootImageConfigKey = android.NewOnceKey("bootImageConfig")
|
||||
artBootImageName = "art"
|
||||
@@ -116,12 +81,13 @@ func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig {
|
||||
targets := dexpreoptTargets(ctx)
|
||||
deviceDir := android.PathForOutput(ctx, ctx.Config().DeviceName())
|
||||
|
||||
artModules := global.ArtApexJars
|
||||
artModules := global.ArtApexJars.CopyOf()
|
||||
// With EMMA_INSTRUMENT_FRAMEWORK=true the Core libraries depend on jacoco.
|
||||
if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
|
||||
artModules = append(artModules, "com.android.art:jacocoagent")
|
||||
artModules.Append("com.android.art", "jacocoagent")
|
||||
}
|
||||
frameworkModules := android.RemoveListFromList(global.BootJars, artModules)
|
||||
frameworkModules := global.BootJars.CopyOf()
|
||||
frameworkModules.RemoveList(artModules)
|
||||
|
||||
artSubdir := "apex/com.android.art/javalib"
|
||||
frameworkSubdir := "system/framework"
|
||||
@@ -163,10 +129,7 @@ func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig {
|
||||
// Set up known paths for them, the singleton rules will copy them there.
|
||||
// TODO(b/143682396): use module dependencies instead
|
||||
inputDir := deviceDir.Join(ctx, "dex_"+c.name+"jars_input")
|
||||
for _, m := range c.modules {
|
||||
_, jar := android.SplitApexJarPair(ctx, m)
|
||||
c.dexPaths = append(c.dexPaths, inputDir.Join(ctx, stemOf(jar)+".jar"))
|
||||
}
|
||||
c.dexPaths = c.modules.BuildPaths(ctx, inputDir)
|
||||
c.dexPathsDeps = c.dexPaths
|
||||
|
||||
// Create target-specific variants.
|
||||
@@ -178,9 +141,7 @@ func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig {
|
||||
target: target,
|
||||
images: imageDir.Join(ctx, imageName),
|
||||
imagesDeps: c.moduleFiles(ctx, imageDir, ".art", ".oat", ".vdex"),
|
||||
}
|
||||
for _, m := range c.modules {
|
||||
variant.dexLocations = append(variant.dexLocations, getDexLocation(ctx, target, m))
|
||||
dexLocations: c.modules.DevicePaths(ctx.Config(), target.Os),
|
||||
}
|
||||
variant.dexLocationsDeps = variant.dexLocations
|
||||
c.variants = append(c.variants, variant)
|
||||
@@ -213,10 +174,7 @@ func defaultBootclasspath(ctx android.PathContext) []string {
|
||||
global := dexpreopt.GetGlobalConfig(ctx)
|
||||
image := defaultBootImageConfig(ctx)
|
||||
|
||||
updatableBootclasspath := make([]string, len(global.UpdatableBootJars))
|
||||
for i, p := range global.UpdatableBootJars {
|
||||
updatableBootclasspath[i] = dexpreopt.GetJarLocationFromApexJarPair(ctx, p)
|
||||
}
|
||||
updatableBootclasspath := global.UpdatableBootJars.DevicePaths(ctx.Config(), android.Android)
|
||||
|
||||
bootclasspath := append(copyOf(image.getAnyAndroidVariant().dexLocationsDeps), updatableBootclasspath...)
|
||||
return bootclasspath
|
||||
@@ -236,5 +194,5 @@ func dexpreoptConfigMakevars(ctx android.MakeVarsContext) {
|
||||
ctx.Strict("PRODUCT_DEX2OAT_BOOTCLASSPATH", strings.Join(defaultBootImageConfig(ctx).getAnyAndroidVariant().dexLocationsDeps, ":"))
|
||||
ctx.Strict("PRODUCT_SYSTEM_SERVER_CLASSPATH", strings.Join(systemServerClasspath(ctx), ":"))
|
||||
|
||||
ctx.Strict("DEXPREOPT_BOOT_JARS_MODULES", strings.Join(defaultBootImageConfig(ctx).modules, ":"))
|
||||
ctx.Strict("DEXPREOPT_BOOT_JARS_MODULES", strings.Join(defaultBootImageConfig(ctx).modules.CopyOfApexJarPairs(), ":"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user