Add ART boot image profile to the ART APEX.

We will need the profile when we generate the primary boot image on
device.

Bug: 203492478
Test: Run `banchan com.android.art x86_64 && m` and see
  `$ANDROID_PRODUCT_OUT/apex/com.android.art/etc/boot-image.prof`.
Test: Run `lunch aosp_cf_x86_64_phone-userdebug && m` and see both
  `$ANDROID_PRODUCT_OUT/apex/com.android.art/etc/boot-image.prof` and
  `$ANDROID_PRODUCT_OUT/system/etc/boot-image.prof`, in different
  sizes.
Test: Start Cuttlefish with the built image and see both
  `/apex/com.android.art/etc/boot-image.prof` and
  `/system/etc/boot-image.prof` on device.
Change-Id: Id879dc49b234133dfbb9563814328661a1f4a6c0
This commit is contained in:
Jiakai Zhang
2021-11-26 18:09:27 +00:00
parent 7c721018bb
commit 49b1eb6b04
8 changed files with 101 additions and 27 deletions

View File

@@ -2159,6 +2159,40 @@ func apexBootclasspathFragmentFiles(ctx android.ModuleContext, module blueprint.
filesToAdd = append(filesToAdd, *af) filesToAdd = append(filesToAdd, *af)
} }
if pathInApex := bootclasspathFragmentInfo.ProfileInstallPathInApex(); pathInApex != "" {
pathOnHost := bootclasspathFragmentInfo.ProfilePathOnHost()
tempPath := android.PathForModuleOut(ctx, "boot_image_profile", pathInApex)
if pathOnHost != nil {
// We need to copy the profile to a temporary path with the right filename because the apexer
// will take the filename as is.
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Input: pathOnHost,
Output: tempPath,
})
} else {
// At this point, the boot image profile cannot be generated. It is probably because the boot
// image profile source file does not exist on the branch, or it is not available for the
// current build target.
// However, we cannot enforce the boot image profile to be generated because some build
// targets (such as module SDK) do not need it. It is only needed when the APEX is being
// built. Therefore, we create an error rule so that an error will occur at the ninja phase
// only if the APEX is being built.
ctx.Build(pctx, android.BuildParams{
Rule: android.ErrorRule,
Output: tempPath,
Args: map[string]string{
"error": "Boot image profile cannot be generated",
},
})
}
androidMkModuleName := filepath.Base(pathInApex)
af := newApexFile(ctx, tempPath, androidMkModuleName, filepath.Dir(pathInApex), etc, nil)
filesToAdd = append(filesToAdd, af)
}
return filesToAdd return filesToAdd
} }

View File

@@ -7037,6 +7037,7 @@ func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, preparer android.F
`, insert)) `, insert))
} }
}), }),
dexpreopt.FixtureSetBootImageProfiles("art/build/boot/boot-image-profile.txt"),
). ).
ExtendWithErrorHandler(errorHandler). ExtendWithErrorHandler(errorHandler).
RunTestWithBp(t, bp) RunTestWithBp(t, bp)

View File

@@ -21,6 +21,7 @@ import (
"testing" "testing"
"android/soong/android" "android/soong/android"
"android/soong/dexpreopt"
"android/soong/java" "android/soong/java"
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
@@ -35,11 +36,14 @@ var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers(
) )
// Some additional files needed for the art apex. // Some additional files needed for the art apex.
var prepareForTestWithArtApex = android.FixtureMergeMockFs(android.MockFS{ var prepareForTestWithArtApex = android.GroupFixturePreparers(
"com.android.art.avbpubkey": nil, android.FixtureMergeMockFs(android.MockFS{
"com.android.art.pem": nil, "com.android.art.avbpubkey": nil,
"system/sepolicy/apex/com.android.art-file_contexts": nil, "com.android.art.pem": nil,
}) "system/sepolicy/apex/com.android.art-file_contexts": nil,
}),
dexpreopt.FixtureSetBootImageProfiles("art/build/boot/boot-image-profile.txt"),
)
func TestBootclasspathFragments(t *testing.T) { func TestBootclasspathFragments(t *testing.T) {
result := android.GroupFixturePreparers( result := android.GroupFixturePreparers(
@@ -408,6 +412,7 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) {
).RunTest(t) ).RunTest(t)
ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
"etc/boot-image.prof",
"etc/classpaths/bootclasspath.pb", "etc/classpaths/bootclasspath.pb",
"javalib/arm/boot.art", "javalib/arm/boot.art",
"javalib/arm/boot.oat", "javalib/arm/boot.oat",
@@ -451,6 +456,7 @@ func TestBootclasspathFragmentInArtApex(t *testing.T) {
).RunTest(t) ).RunTest(t)
ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
"etc/boot-image.prof",
"etc/classpaths/bootclasspath.pb", "etc/classpaths/bootclasspath.pb",
"javalib/arm/boot.art", "javalib/arm/boot.art",
"javalib/arm/boot.oat", "javalib/arm/boot.oat",

View File

@@ -85,12 +85,12 @@ var PrepareForTestWithFakeDex2oatd = android.GroupFixturePreparers(
// Prepares a test fixture by enabling dexpreopt, registering the fake_tool_binary module type and // Prepares a test fixture by enabling dexpreopt, registering the fake_tool_binary module type and
// using that to define the `dex2oatd` module. // using that to define the `dex2oatd` module.
var PrepareForTestByEnablingDexpreopt = android.GroupFixturePreparers( var PrepareForTestByEnablingDexpreopt = android.GroupFixturePreparers(
FixtureModifyGlobalConfig(func(*GlobalConfig) {}), FixtureModifyGlobalConfig(func(android.PathContext, *GlobalConfig) {}),
) )
// FixtureModifyGlobalConfig enables dexpreopt (unless modified by the mutator) and modifies the // FixtureModifyGlobalConfig enables dexpreopt (unless modified by the mutator) and modifies the
// configuration. // configuration.
func FixtureModifyGlobalConfig(configModifier func(dexpreoptConfig *GlobalConfig)) android.FixturePreparer { func FixtureModifyGlobalConfig(configModifier func(ctx android.PathContext, dexpreoptConfig *GlobalConfig)) android.FixturePreparer {
return android.FixtureModifyConfig(func(config android.Config) { return android.FixtureModifyConfig(func(config android.Config) {
// Initialize the dexpreopt GlobalConfig to an empty structure. This has no effect if it has // Initialize the dexpreopt GlobalConfig to an empty structure. This has no effect if it has
// already been set. // already been set.
@@ -100,48 +100,48 @@ func FixtureModifyGlobalConfig(configModifier func(dexpreoptConfig *GlobalConfig
// Retrieve the existing configuration and modify it. // Retrieve the existing configuration and modify it.
dexpreoptConfig = GetGlobalConfig(pathCtx) dexpreoptConfig = GetGlobalConfig(pathCtx)
configModifier(dexpreoptConfig) configModifier(pathCtx, dexpreoptConfig)
}) })
} }
// FixtureSetArtBootJars enables dexpreopt and sets the ArtApexJars property. // FixtureSetArtBootJars enables dexpreopt and sets the ArtApexJars property.
func FixtureSetArtBootJars(bootJars ...string) android.FixturePreparer { func FixtureSetArtBootJars(bootJars ...string) android.FixturePreparer {
return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) { return FixtureModifyGlobalConfig(func(_ android.PathContext, dexpreoptConfig *GlobalConfig) {
dexpreoptConfig.ArtApexJars = android.CreateTestConfiguredJarList(bootJars) dexpreoptConfig.ArtApexJars = android.CreateTestConfiguredJarList(bootJars)
}) })
} }
// FixtureSetBootJars enables dexpreopt and sets the BootJars property. // FixtureSetBootJars enables dexpreopt and sets the BootJars property.
func FixtureSetBootJars(bootJars ...string) android.FixturePreparer { func FixtureSetBootJars(bootJars ...string) android.FixturePreparer {
return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) { return FixtureModifyGlobalConfig(func(_ android.PathContext, dexpreoptConfig *GlobalConfig) {
dexpreoptConfig.BootJars = android.CreateTestConfiguredJarList(bootJars) dexpreoptConfig.BootJars = android.CreateTestConfiguredJarList(bootJars)
}) })
} }
// FixtureSetApexBootJars sets the ApexBootJars property in the global config. // FixtureSetApexBootJars sets the ApexBootJars property in the global config.
func FixtureSetApexBootJars(bootJars ...string) android.FixturePreparer { func FixtureSetApexBootJars(bootJars ...string) android.FixturePreparer {
return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) { return FixtureModifyGlobalConfig(func(_ android.PathContext, dexpreoptConfig *GlobalConfig) {
dexpreoptConfig.ApexBootJars = android.CreateTestConfiguredJarList(bootJars) dexpreoptConfig.ApexBootJars = android.CreateTestConfiguredJarList(bootJars)
}) })
} }
// FixtureSetStandaloneSystemServerJars sets the StandaloneSystemServerJars property. // FixtureSetStandaloneSystemServerJars sets the StandaloneSystemServerJars property.
func FixtureSetStandaloneSystemServerJars(jars ...string) android.FixturePreparer { func FixtureSetStandaloneSystemServerJars(jars ...string) android.FixturePreparer {
return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) { return FixtureModifyGlobalConfig(func(_ android.PathContext, dexpreoptConfig *GlobalConfig) {
dexpreoptConfig.StandaloneSystemServerJars = android.CreateTestConfiguredJarList(jars) dexpreoptConfig.StandaloneSystemServerJars = android.CreateTestConfiguredJarList(jars)
}) })
} }
// FixtureSetSystemServerJars sets the SystemServerJars property. // FixtureSetSystemServerJars sets the SystemServerJars property.
func FixtureSetSystemServerJars(jars ...string) android.FixturePreparer { func FixtureSetSystemServerJars(jars ...string) android.FixturePreparer {
return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) { return FixtureModifyGlobalConfig(func(_ android.PathContext, dexpreoptConfig *GlobalConfig) {
dexpreoptConfig.SystemServerJars = android.CreateTestConfiguredJarList(jars) dexpreoptConfig.SystemServerJars = android.CreateTestConfiguredJarList(jars)
}) })
} }
// FixtureSetApexSystemServerJars sets the ApexSystemServerJars property in the global config. // FixtureSetApexSystemServerJars sets the ApexSystemServerJars property in the global config.
func FixtureSetApexSystemServerJars(jars ...string) android.FixturePreparer { func FixtureSetApexSystemServerJars(jars ...string) android.FixturePreparer {
return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) { return FixtureModifyGlobalConfig(func(_ android.PathContext, dexpreoptConfig *GlobalConfig) {
dexpreoptConfig.ApexSystemServerJars = android.CreateTestConfiguredJarList(jars) dexpreoptConfig.ApexSystemServerJars = android.CreateTestConfiguredJarList(jars)
}) })
} }
@@ -149,14 +149,21 @@ func FixtureSetApexSystemServerJars(jars ...string) android.FixturePreparer {
// FixtureSetApexStandaloneSystemServerJars sets the ApexStandaloneSystemServerJars property in the // FixtureSetApexStandaloneSystemServerJars sets the ApexStandaloneSystemServerJars property in the
// global config. // global config.
func FixtureSetApexStandaloneSystemServerJars(jars ...string) android.FixturePreparer { func FixtureSetApexStandaloneSystemServerJars(jars ...string) android.FixturePreparer {
return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) { return FixtureModifyGlobalConfig(func(_ android.PathContext, dexpreoptConfig *GlobalConfig) {
dexpreoptConfig.ApexStandaloneSystemServerJars = android.CreateTestConfiguredJarList(jars) dexpreoptConfig.ApexStandaloneSystemServerJars = android.CreateTestConfiguredJarList(jars)
}) })
} }
// FixtureSetPreoptWithUpdatableBcp sets the PreoptWithUpdatableBcp property in the global config. // FixtureSetPreoptWithUpdatableBcp sets the PreoptWithUpdatableBcp property in the global config.
func FixtureSetPreoptWithUpdatableBcp(value bool) android.FixturePreparer { func FixtureSetPreoptWithUpdatableBcp(value bool) android.FixturePreparer {
return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) { return FixtureModifyGlobalConfig(func(_ android.PathContext, dexpreoptConfig *GlobalConfig) {
dexpreoptConfig.PreoptWithUpdatableBcp = value dexpreoptConfig.PreoptWithUpdatableBcp = value
}) })
} }
// FixtureSetBootImageProfiles sets the BootImageProfiles property in the global config.
func FixtureSetBootImageProfiles(profiles ...string) android.FixturePreparer {
return FixtureModifyGlobalConfig(func(ctx android.PathContext, dexpreoptConfig *GlobalConfig) {
dexpreoptConfig.BootImageProfiles = android.PathsForSource(ctx, profiles)
})
}

View File

@@ -390,6 +390,13 @@ type BootclasspathFragmentApexContentInfo struct {
// Map from the base module name (without prebuilt_ prefix) of a fragment's contents module to the // Map from the base module name (without prebuilt_ prefix) of a fragment's contents module to the
// hidden API encoded dex jar path. // hidden API encoded dex jar path.
contentModuleDexJarPaths bootDexJarByModule contentModuleDexJarPaths bootDexJarByModule
// Path to the image profile file on host (or empty, if profile is not generated).
profilePathOnHost android.Path
// Install path of the boot image profile if it needs to be installed in the APEX, or empty if not
// needed.
profileInstallPathInApex string
} }
func (i BootclasspathFragmentApexContentInfo) Modules() android.ConfiguredJarList { func (i BootclasspathFragmentApexContentInfo) Modules() android.ConfiguredJarList {
@@ -418,6 +425,14 @@ func (i BootclasspathFragmentApexContentInfo) DexBootJarPathForContentModule(mod
} }
} }
func (i BootclasspathFragmentApexContentInfo) ProfilePathOnHost() android.Path {
return i.profilePathOnHost
}
func (i BootclasspathFragmentApexContentInfo) ProfileInstallPathInApex() string {
return i.profileInstallPathInApex
}
func (b *BootclasspathFragmentModule) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { func (b *BootclasspathFragmentModule) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
tag := ctx.OtherModuleDependencyTag(dep) tag := ctx.OtherModuleDependencyTag(dep)
if IsBootclasspathFragmentContentDepTag(tag) { if IsBootclasspathFragmentContentDepTag(tag) {
@@ -579,6 +594,8 @@ func (b *BootclasspathFragmentModule) provideApexContentInfo(ctx android.ModuleC
if imageConfig != nil { if imageConfig != nil {
info.modules = imageConfig.modules info.modules = imageConfig.modules
info.profilePathOnHost = imageConfig.profilePathOnHost
info.profileInstallPathInApex = imageConfig.profileInstallPathInApex
} }
info.bootImageFilesByArch = bootImageFilesByArch info.bootImageFilesByArch = bootImageFilesByArch

View File

@@ -256,6 +256,10 @@ type bootImageConfig struct {
// Subdirectory where the image files on device are installed. // Subdirectory where the image files on device are installed.
installDirOnDevice string installDirOnDevice string
// Install path of the boot image profile if it needs to be installed in the APEX, or empty if not
// needed.
profileInstallPathInApex string
// A list of (location, jar) pairs for the Java modules in this image. // A list of (location, jar) pairs for the Java modules in this image.
modules android.ConfiguredJarList modules android.ConfiguredJarList
@@ -272,6 +276,9 @@ type bootImageConfig struct {
// Rules which should be used in make to install the outputs. // Rules which should be used in make to install the outputs.
profileInstalls android.RuleBuilderInstalls profileInstalls android.RuleBuilderInstalls
// Path to the image profile file on host (or empty, if profile is not generated).
profilePathOnHost android.Path
// Target-dependent fields. // Target-dependent fields.
variants []*bootImageVariant variants []*bootImageVariant
} }
@@ -769,11 +776,14 @@ func bootImageProfileRule(ctx android.ModuleContext, image *bootImageConfig) and
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.prof") if image == defaultBootImageConfig(ctx) {
rule.Install(profile, "/system/etc/boot-image.prof")
image.profileInstalls = append(image.profileInstalls, rule.Installs()...)
}
rule.Build("bootJarsProfile", "profile boot jars") rule.Build("bootJarsProfile", "profile boot jars")
image.profileInstalls = append(image.profileInstalls, rule.Installs()...) image.profilePathOnHost = profile
return profile return profile
} }

View File

@@ -56,22 +56,20 @@ func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig {
artModules := global.ArtApexJars artModules := global.ArtApexJars
frameworkModules := global.BootJars.RemoveList(artModules) frameworkModules := global.BootJars.RemoveList(artModules)
artDirOnHost := "apex/art_boot_images/javalib"
artDirOnDevice := "apex/com.android.art/javalib"
frameworkSubdir := "system/framework"
// ART config for the primary boot image in the ART apex. // ART config for the primary boot image in the ART apex.
// It includes the Core Libraries. // It includes the Core Libraries.
artCfg := bootImageConfig{ artCfg := bootImageConfig{
name: artBootImageName, name: artBootImageName,
stem: "boot", stem: "boot",
installDirOnHost: artDirOnHost, installDirOnHost: "apex/art_boot_images/javalib",
installDirOnDevice: artDirOnDevice, installDirOnDevice: "apex/com.android.art/javalib",
modules: artModules, profileInstallPathInApex: "etc/boot-image.prof",
modules: artModules,
} }
// Framework config for the boot image extension. // Framework config for the boot image extension.
// It includes framework libraries and depends on the ART config. // It includes framework libraries and depends on the ART config.
frameworkSubdir := "system/framework"
frameworkCfg := bootImageConfig{ frameworkCfg := bootImageConfig{
extends: &artCfg, extends: &artCfg,
name: frameworkBootImageName, name: frameworkBootImageName,

View File

@@ -40,6 +40,7 @@ func fixtureAddPlatformBootclasspathForBootclasspathFragment(apex, fragment stri
} }
`, apex, fragment)), `, apex, fragment)),
android.FixtureAddFile("frameworks/base/config/boot-profile.txt", nil), android.FixtureAddFile("frameworks/base/config/boot-profile.txt", nil),
android.FixtureAddFile("frameworks/base/config/boot-image-profile.txt", nil),
android.FixtureAddFile("build/soong/scripts/check_boot_jars/package_allowed_list.txt", nil), android.FixtureAddFile("build/soong/scripts/check_boot_jars/package_allowed_list.txt", nil),
) )
} }