Merge "Extract default image specific logic from buildBootImage" am: 6d4de43833
am: 29b18b8c17
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1686149 Change-Id: Ifd9767dc1b40ac4a5346c7528329fb314aadfddc
This commit is contained in:
@@ -434,10 +434,21 @@ func (d *dexpreoptBootJars) GenerateSingletonBuildActions(ctx android.SingletonC
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always create the default boot image first, to get a unique profile rule for all images.
|
// Generate the profile rule from the default boot image.
|
||||||
d.defaultBootImage = buildBootImage(ctx, defaultBootImageConfig(ctx))
|
defaultImageConfig := defaultBootImageConfig(ctx)
|
||||||
|
profile := bootImageProfileRule(ctx, defaultImageConfig)
|
||||||
|
|
||||||
|
// Generate the framework profile rule
|
||||||
|
bootFrameworkProfileRule(ctx, defaultImageConfig)
|
||||||
|
|
||||||
|
// Generate the updatable bootclasspath packages rule.
|
||||||
|
updatableBcpPackagesRule(ctx, defaultImageConfig)
|
||||||
|
|
||||||
|
// Create the default boot image.
|
||||||
|
d.defaultBootImage = buildBootImage(ctx, defaultImageConfig, profile)
|
||||||
|
|
||||||
// Create boot image for the ART apex (build artifacts are accessed via the global boot image config).
|
// Create boot image for the ART apex (build artifacts are accessed via the global boot image config).
|
||||||
d.otherImages = append(d.otherImages, buildBootImage(ctx, artBootImageConfig(ctx)))
|
d.otherImages = append(d.otherImages, buildBootImage(ctx, artBootImageConfig(ctx), profile))
|
||||||
|
|
||||||
copyUpdatableBootJars(ctx)
|
copyUpdatableBootJars(ctx)
|
||||||
|
|
||||||
@@ -605,16 +616,12 @@ func findAndCopyBootJars(ctx android.SingletonContext, bootjars android.Configur
|
|||||||
}
|
}
|
||||||
|
|
||||||
// buildBootImage takes a bootImageConfig, creates rules to build it, and returns the image.
|
// buildBootImage takes a bootImageConfig, creates rules to build it, and returns the image.
|
||||||
func buildBootImage(ctx android.SingletonContext, image *bootImageConfig) *bootImageConfig {
|
func buildBootImage(ctx android.SingletonContext, image *bootImageConfig, profile android.WritablePath) *bootImageConfig {
|
||||||
getBootJarFunc := func(module android.Module) (int, android.Path) {
|
getBootJarFunc := func(module android.Module) (int, android.Path) {
|
||||||
return getBootImageJar(ctx, image, module)
|
return getBootImageJar(ctx, image, module)
|
||||||
}
|
}
|
||||||
findAndCopyBootJars(ctx, image.modules, image.dexPaths, getBootJarFunc)
|
findAndCopyBootJars(ctx, image.modules, image.dexPaths, getBootJarFunc)
|
||||||
|
|
||||||
profile := bootImageProfileRule(ctx, image)
|
|
||||||
bootFrameworkProfileRule(ctx, image)
|
|
||||||
updatableBcpPackagesRule(ctx, image)
|
|
||||||
|
|
||||||
var zipFiles android.Paths
|
var zipFiles android.Paths
|
||||||
for _, variant := range image.variants {
|
for _, variant := range image.variants {
|
||||||
files := buildBootImageVariant(ctx, variant, profile)
|
files := buildBootImageVariant(ctx, variant, profile)
|
||||||
@@ -805,53 +812,46 @@ func bootImageProfileRule(ctx android.SingletonContext, image *bootImageConfig)
|
|||||||
if global.DisableGenerateProfile {
|
if global.DisableGenerateProfile {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
profile := ctx.Config().Once(bootImageProfileRuleKey, func() interface{} {
|
|
||||||
defaultProfile := "frameworks/base/config/boot-image-profile.txt"
|
|
||||||
|
|
||||||
rule := android.NewRuleBuilder(pctx, ctx)
|
defaultProfile := "frameworks/base/config/boot-image-profile.txt"
|
||||||
|
|
||||||
var bootImageProfile android.Path
|
rule := android.NewRuleBuilder(pctx, ctx)
|
||||||
if len(global.BootImageProfiles) > 1 {
|
|
||||||
combinedBootImageProfile := image.dir.Join(ctx, "boot-image-profile.txt")
|
|
||||||
rule.Command().Text("cat").Inputs(global.BootImageProfiles).Text(">").Output(combinedBootImageProfile)
|
|
||||||
bootImageProfile = combinedBootImageProfile
|
|
||||||
} else if len(global.BootImageProfiles) == 1 {
|
|
||||||
bootImageProfile = global.BootImageProfiles[0]
|
|
||||||
} else if path := android.ExistentPathForSource(ctx, defaultProfile); path.Valid() {
|
|
||||||
bootImageProfile = path.Path()
|
|
||||||
} else {
|
|
||||||
// No profile (not even a default one, which is the case on some branches
|
|
||||||
// like master-art-host that don't have frameworks/base).
|
|
||||||
// Return nil and continue without profile.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
profile := image.dir.Join(ctx, "boot.prof")
|
var bootImageProfile android.Path
|
||||||
|
if len(global.BootImageProfiles) > 1 {
|
||||||
rule.Command().
|
combinedBootImageProfile := image.dir.Join(ctx, "boot-image-profile.txt")
|
||||||
Text(`ANDROID_LOG_TAGS="*:e"`).
|
rule.Command().Text("cat").Inputs(global.BootImageProfiles).Text(">").Output(combinedBootImageProfile)
|
||||||
Tool(globalSoong.Profman).
|
bootImageProfile = combinedBootImageProfile
|
||||||
Flag("--output-profile-type=boot").
|
} else if len(global.BootImageProfiles) == 1 {
|
||||||
FlagWithInput("--create-profile-from=", bootImageProfile).
|
bootImageProfile = global.BootImageProfiles[0]
|
||||||
FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
|
} else if path := android.ExistentPathForSource(ctx, defaultProfile); path.Valid() {
|
||||||
FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps).
|
bootImageProfile = path.Path()
|
||||||
FlagWithOutput("--reference-profile-file=", profile)
|
} else {
|
||||||
|
// No profile (not even a default one, which is the case on some branches
|
||||||
rule.Install(profile, "/system/etc/boot-image.prof")
|
// like master-art-host that don't have frameworks/base).
|
||||||
|
// Return nil and continue without profile.
|
||||||
rule.Build("bootJarsProfile", "profile boot jars")
|
return nil
|
||||||
|
|
||||||
image.profileInstalls = rule.Installs()
|
|
||||||
|
|
||||||
return profile
|
|
||||||
})
|
|
||||||
if profile == nil {
|
|
||||||
return nil // wrap nil into a typed pointer with value nil
|
|
||||||
}
|
}
|
||||||
return profile.(android.WritablePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
var bootImageProfileRuleKey = android.NewOnceKey("bootImageProfileRule")
|
profile := image.dir.Join(ctx, "boot.prof")
|
||||||
|
|
||||||
|
rule.Command().
|
||||||
|
Text(`ANDROID_LOG_TAGS="*:e"`).
|
||||||
|
Tool(globalSoong.Profman).
|
||||||
|
Flag("--output-profile-type=boot").
|
||||||
|
FlagWithInput("--create-profile-from=", bootImageProfile).
|
||||||
|
FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
|
||||||
|
FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps).
|
||||||
|
FlagWithOutput("--reference-profile-file=", profile)
|
||||||
|
|
||||||
|
rule.Install(profile, "/system/etc/boot-image.prof")
|
||||||
|
|
||||||
|
rule.Build("bootJarsProfile", "profile boot jars")
|
||||||
|
|
||||||
|
image.profileInstalls = rule.Installs()
|
||||||
|
|
||||||
|
return profile
|
||||||
|
}
|
||||||
|
|
||||||
func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImageConfig) android.WritablePath {
|
func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImageConfig) android.WritablePath {
|
||||||
globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
|
globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
|
||||||
@@ -860,96 +860,88 @@ func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImageConf
|
|||||||
if global.DisableGenerateProfile || ctx.Config().UnbundledBuild() {
|
if global.DisableGenerateProfile || ctx.Config().UnbundledBuild() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return ctx.Config().Once(bootFrameworkProfileRuleKey, func() interface{} {
|
|
||||||
|
|
||||||
// Some branches like master-art-host don't have frameworks/base, so manually
|
// Some branches like master-art-host don't have frameworks/base, so manually
|
||||||
// handle the case that the default is missing. Those branches won't attempt to build the profile rule,
|
// handle the case that the default is missing. Those branches won't attempt to build the profile rule,
|
||||||
// and if they do they'll get a missing deps error.
|
// and if they do they'll get a missing deps error.
|
||||||
defaultProfile := "frameworks/base/config/boot-profile.txt"
|
defaultProfile := "frameworks/base/config/boot-profile.txt"
|
||||||
path := android.ExistentPathForSource(ctx, defaultProfile)
|
path := android.ExistentPathForSource(ctx, defaultProfile)
|
||||||
var bootFrameworkProfile android.Path
|
var bootFrameworkProfile android.Path
|
||||||
var missingDeps []string
|
var missingDeps []string
|
||||||
if path.Valid() {
|
if path.Valid() {
|
||||||
bootFrameworkProfile = path.Path()
|
bootFrameworkProfile = path.Path()
|
||||||
} else {
|
} else {
|
||||||
missingDeps = append(missingDeps, defaultProfile)
|
missingDeps = append(missingDeps, defaultProfile)
|
||||||
bootFrameworkProfile = android.PathForOutput(ctx, "missing", defaultProfile)
|
bootFrameworkProfile = android.PathForOutput(ctx, "missing", defaultProfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
profile := image.dir.Join(ctx, "boot.bprof")
|
profile := image.dir.Join(ctx, "boot.bprof")
|
||||||
|
|
||||||
rule := android.NewRuleBuilder(pctx, ctx)
|
rule := android.NewRuleBuilder(pctx, ctx)
|
||||||
rule.MissingDeps(missingDeps)
|
rule.MissingDeps(missingDeps)
|
||||||
rule.Command().
|
rule.Command().
|
||||||
Text(`ANDROID_LOG_TAGS="*:e"`).
|
Text(`ANDROID_LOG_TAGS="*:e"`).
|
||||||
Tool(globalSoong.Profman).
|
Tool(globalSoong.Profman).
|
||||||
Flag("--output-profile-type=bprof").
|
Flag("--output-profile-type=bprof").
|
||||||
FlagWithInput("--create-profile-from=", bootFrameworkProfile).
|
FlagWithInput("--create-profile-from=", bootFrameworkProfile).
|
||||||
FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
|
FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
|
||||||
FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps).
|
FlagForEachArg("--dex-location=", image.getAnyAndroidVariant().dexLocationsDeps).
|
||||||
FlagWithOutput("--reference-profile-file=", profile)
|
FlagWithOutput("--reference-profile-file=", profile)
|
||||||
|
|
||||||
rule.Install(profile, "/system/etc/boot-image.bprof")
|
rule.Install(profile, "/system/etc/boot-image.bprof")
|
||||||
rule.Build("bootFrameworkProfile", "profile boot framework jars")
|
rule.Build("bootFrameworkProfile", "profile boot framework jars")
|
||||||
image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
|
image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
|
||||||
|
|
||||||
return profile
|
return profile
|
||||||
}).(android.WritablePath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var bootFrameworkProfileRuleKey = android.NewOnceKey("bootFrameworkProfileRule")
|
|
||||||
|
|
||||||
func updatableBcpPackagesRule(ctx android.SingletonContext, image *bootImageConfig) android.WritablePath {
|
func updatableBcpPackagesRule(ctx android.SingletonContext, image *bootImageConfig) android.WritablePath {
|
||||||
if ctx.Config().UnbundledBuild() {
|
if ctx.Config().UnbundledBuild() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.Config().Once(updatableBcpPackagesRuleKey, func() interface{} {
|
global := dexpreopt.GetGlobalConfig(ctx)
|
||||||
global := dexpreopt.GetGlobalConfig(ctx)
|
updatableModules := global.UpdatableBootJars.CopyOfJars()
|
||||||
updatableModules := global.UpdatableBootJars.CopyOfJars()
|
|
||||||
|
|
||||||
// Collect `permitted_packages` for updatable boot jars.
|
// Collect `permitted_packages` for updatable boot jars.
|
||||||
var updatablePackages []string
|
var updatablePackages []string
|
||||||
ctx.VisitAllModules(func(module android.Module) {
|
ctx.VisitAllModules(func(module android.Module) {
|
||||||
if !isActiveModule(module) {
|
if !isActiveModule(module) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if j, ok := module.(PermittedPackagesForUpdatableBootJars); ok {
|
if j, ok := module.(PermittedPackagesForUpdatableBootJars); ok {
|
||||||
name := ctx.ModuleName(module)
|
name := ctx.ModuleName(module)
|
||||||
if i := android.IndexList(name, updatableModules); i != -1 {
|
if i := android.IndexList(name, updatableModules); i != -1 {
|
||||||
pp := j.PermittedPackagesForUpdatableBootJars()
|
pp := j.PermittedPackagesForUpdatableBootJars()
|
||||||
if len(pp) > 0 {
|
if len(pp) > 0 {
|
||||||
updatablePackages = append(updatablePackages, pp...)
|
updatablePackages = append(updatablePackages, pp...)
|
||||||
} else {
|
} else {
|
||||||
ctx.Errorf("Missing permitted_packages for %s", name)
|
ctx.Errorf("Missing permitted_packages for %s", name)
|
||||||
}
|
|
||||||
// Do not match the same library repeatedly.
|
|
||||||
updatableModules = append(updatableModules[:i], updatableModules[i+1:]...)
|
|
||||||
}
|
}
|
||||||
|
// Do not match the same library repeatedly.
|
||||||
|
updatableModules = append(updatableModules[:i], updatableModules[i+1:]...)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Sort updatable packages to ensure deterministic ordering.
|
// Sort updatable packages to ensure deterministic ordering.
|
||||||
sort.Strings(updatablePackages)
|
sort.Strings(updatablePackages)
|
||||||
|
|
||||||
updatableBcpPackagesName := "updatable-bcp-packages.txt"
|
updatableBcpPackagesName := "updatable-bcp-packages.txt"
|
||||||
updatableBcpPackages := image.dir.Join(ctx, updatableBcpPackagesName)
|
updatableBcpPackages := image.dir.Join(ctx, updatableBcpPackagesName)
|
||||||
|
|
||||||
// WriteFileRule automatically adds the last end-of-line.
|
// WriteFileRule automatically adds the last end-of-line.
|
||||||
android.WriteFileRule(ctx, updatableBcpPackages, strings.Join(updatablePackages, "\n"))
|
android.WriteFileRule(ctx, updatableBcpPackages, strings.Join(updatablePackages, "\n"))
|
||||||
|
|
||||||
rule := android.NewRuleBuilder(pctx, ctx)
|
rule := android.NewRuleBuilder(pctx, ctx)
|
||||||
rule.Install(updatableBcpPackages, "/system/etc/"+updatableBcpPackagesName)
|
rule.Install(updatableBcpPackages, "/system/etc/"+updatableBcpPackagesName)
|
||||||
// TODO: Rename `profileInstalls` to `extraInstalls`?
|
// TODO: Rename `profileInstalls` to `extraInstalls`?
|
||||||
// Maybe even move the field out of the bootImageConfig into some higher level type?
|
// Maybe even move the field out of the bootImageConfig into some higher level type?
|
||||||
image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
|
image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
|
||||||
|
|
||||||
return updatableBcpPackages
|
return updatableBcpPackages
|
||||||
}).(android.WritablePath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var updatableBcpPackagesRuleKey = android.NewOnceKey("updatableBcpPackagesRule")
|
|
||||||
|
|
||||||
func dumpOatRules(ctx android.SingletonContext, image *bootImageConfig) {
|
func dumpOatRules(ctx android.SingletonContext, image *bootImageConfig) {
|
||||||
var allPhonies android.Paths
|
var allPhonies android.Paths
|
||||||
for _, image := range image.variants {
|
for _, image := range image.variants {
|
||||||
|
Reference in New Issue
Block a user