Reland: Separate dexpreopt.GlobalSoongConfig to allow independent
caching of it. Introduce a Once cache for GlobalSoongConfig to allow it to get binary tool paths from ordinary module dependencies (coming in a future CL) that are then reused in singletons. This relands https://r.android.com/1205729. Bug: 145934348 Test: m Change-Id: I039d6e204bee5ddc16d8e2d85057fbec20e326fe
This commit is contained in:
@@ -22,8 +22,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GlobalConfig stores the configuration for dex preopting. The fields are set
|
// GlobalConfig stores the configuration for dex preopting. The fields are set
|
||||||
// from product variables via dex_preopt_config.mk, except for SoongConfig
|
// from product variables via dex_preopt_config.mk.
|
||||||
// which come from CreateGlobalSoongConfig.
|
|
||||||
type GlobalConfig struct {
|
type GlobalConfig struct {
|
||||||
DisablePreopt bool // disable preopt for all modules
|
DisablePreopt bool // disable preopt for all modules
|
||||||
DisablePreoptModules []string // modules with preopt disabled by product-specific config
|
DisablePreoptModules []string // modules with preopt disabled by product-specific config
|
||||||
@@ -81,8 +80,6 @@ type GlobalConfig struct {
|
|||||||
BootFlags string // extra flags to pass to dex2oat for the boot image
|
BootFlags string // extra flags to pass to dex2oat for the boot image
|
||||||
Dex2oatImageXmx string // max heap size for dex2oat for the boot image
|
Dex2oatImageXmx string // max heap size for dex2oat for the boot image
|
||||||
Dex2oatImageXms string // initial heap size for dex2oat for the boot image
|
Dex2oatImageXms string // initial heap size for dex2oat for the boot image
|
||||||
|
|
||||||
SoongConfig GlobalSoongConfig // settings read from dexpreopt_soong.config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GlobalSoongConfig contains the global config that is generated from Soong,
|
// GlobalSoongConfig contains the global config that is generated from Soong,
|
||||||
@@ -179,11 +176,9 @@ func constructWritablePath(ctx android.PathContext, path string) android.Writabl
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LoadGlobalConfig reads the global dexpreopt.config file into a GlobalConfig
|
// LoadGlobalConfig reads the global dexpreopt.config file into a GlobalConfig
|
||||||
// struct, except the SoongConfig field which is set from the provided
|
// struct. LoadGlobalConfig is used directly in Soong and in dexpreopt_gen
|
||||||
// soongConfig argument. LoadGlobalConfig is used directly in Soong and in
|
// called from Make to read the $OUT/dexpreopt.config written by Make.
|
||||||
// dexpreopt_gen called from Make to read the $OUT/dexpreopt.config written by
|
func LoadGlobalConfig(ctx android.PathContext, data []byte) (GlobalConfig, error) {
|
||||||
// Make.
|
|
||||||
func LoadGlobalConfig(ctx android.PathContext, data []byte, soongConfig GlobalSoongConfig) (GlobalConfig, error) {
|
|
||||||
type GlobalJSONConfig struct {
|
type GlobalJSONConfig struct {
|
||||||
GlobalConfig
|
GlobalConfig
|
||||||
|
|
||||||
@@ -203,10 +198,6 @@ func LoadGlobalConfig(ctx android.PathContext, data []byte, soongConfig GlobalSo
|
|||||||
config.GlobalConfig.DirtyImageObjects = android.OptionalPathForPath(constructPath(ctx, config.DirtyImageObjects))
|
config.GlobalConfig.DirtyImageObjects = android.OptionalPathForPath(constructPath(ctx, config.DirtyImageObjects))
|
||||||
config.GlobalConfig.BootImageProfiles = constructPaths(ctx, config.BootImageProfiles)
|
config.GlobalConfig.BootImageProfiles = constructPaths(ctx, config.BootImageProfiles)
|
||||||
|
|
||||||
// Set this here to force the caller to provide a value for this struct (from
|
|
||||||
// either CreateGlobalSoongConfig or LoadGlobalSoongConfig).
|
|
||||||
config.GlobalConfig.SoongConfig = soongConfig
|
|
||||||
|
|
||||||
return config.GlobalConfig, nil
|
return config.GlobalConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,9 +243,16 @@ func LoadModuleConfig(ctx android.PathContext, data []byte) (ModuleConfig, error
|
|||||||
return config.ModuleConfig, nil
|
return config.ModuleConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateGlobalSoongConfig creates a GlobalSoongConfig from the current context.
|
// createGlobalSoongConfig creates a GlobalSoongConfig from the current context.
|
||||||
// Should not be used in dexpreopt_gen.
|
// Should not be used in dexpreopt_gen.
|
||||||
func CreateGlobalSoongConfig(ctx android.PathContext) GlobalSoongConfig {
|
func createGlobalSoongConfig(ctx android.ModuleContext) GlobalSoongConfig {
|
||||||
|
if ctx.Config().TestProductVariables != nil {
|
||||||
|
// If we're called in a test there'll be a confusing error from the path
|
||||||
|
// functions below that gets reported without a stack trace, so let's panic
|
||||||
|
// properly with a more helpful message.
|
||||||
|
panic("This should not be called from tests. Please call GlobalSoongConfigForTests somewhere in the test setup.")
|
||||||
|
}
|
||||||
|
|
||||||
// Default to debug version to help find bugs.
|
// Default to debug version to help find bugs.
|
||||||
// Set USE_DEX2OAT_DEBUG to false for only building non-debug versions.
|
// Set USE_DEX2OAT_DEBUG to false for only building non-debug versions.
|
||||||
var dex2oatBinary string
|
var dex2oatBinary string
|
||||||
@@ -275,6 +273,26 @@ func CreateGlobalSoongConfig(ctx android.PathContext) GlobalSoongConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var globalSoongConfigOnceKey = android.NewOnceKey("DexpreoptGlobalSoongConfig")
|
||||||
|
|
||||||
|
// GetGlobalSoongConfig creates a GlobalSoongConfig the first time it's called,
|
||||||
|
// and later returns the same cached instance.
|
||||||
|
func GetGlobalSoongConfig(ctx android.ModuleContext) GlobalSoongConfig {
|
||||||
|
globalSoong := ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} {
|
||||||
|
return createGlobalSoongConfig(ctx)
|
||||||
|
}).(GlobalSoongConfig)
|
||||||
|
return globalSoong
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCachedGlobalSoongConfig returns a cached GlobalSoongConfig created by an
|
||||||
|
// earlier GetGlobalSoongConfig call. This function works with any context
|
||||||
|
// compatible with a basic PathContext, since it doesn't try to create a
|
||||||
|
// GlobalSoongConfig (which requires a full ModuleContext). It will panic if
|
||||||
|
// called before the first GetGlobalSoongConfig call.
|
||||||
|
func GetCachedGlobalSoongConfig(ctx android.PathContext) GlobalSoongConfig {
|
||||||
|
return ctx.Config().Get(globalSoongConfigOnceKey).(GlobalSoongConfig)
|
||||||
|
}
|
||||||
|
|
||||||
type globalJsonSoongConfig struct {
|
type globalJsonSoongConfig struct {
|
||||||
Profman string
|
Profman string
|
||||||
Dex2oat string
|
Dex2oat string
|
||||||
@@ -309,7 +327,7 @@ func LoadGlobalSoongConfig(ctx android.PathContext, data []byte) (GlobalSoongCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *globalSoongConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
func (s *globalSoongConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
||||||
config := CreateGlobalSoongConfig(ctx)
|
config := GetCachedGlobalSoongConfig(ctx)
|
||||||
jc := globalJsonSoongConfig{
|
jc := globalJsonSoongConfig{
|
||||||
Profman: config.Profman.String(),
|
Profman: config.Profman.String(),
|
||||||
Dex2oat: config.Dex2oat.String(),
|
Dex2oat: config.Dex2oat.String(),
|
||||||
@@ -336,7 +354,7 @@ func (s *globalSoongConfigSingleton) GenerateBuildActions(ctx android.SingletonC
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *globalSoongConfigSingleton) MakeVars(ctx android.MakeVarsContext) {
|
func (s *globalSoongConfigSingleton) MakeVars(ctx android.MakeVarsContext) {
|
||||||
config := CreateGlobalSoongConfig(ctx)
|
config := GetCachedGlobalSoongConfig(ctx)
|
||||||
|
|
||||||
ctx.Strict("DEX2OAT", config.Dex2oat.String())
|
ctx.Strict("DEX2OAT", config.Dex2oat.String())
|
||||||
ctx.Strict("DEXPREOPT_GEN_DEPS", strings.Join([]string{
|
ctx.Strict("DEXPREOPT_GEN_DEPS", strings.Join([]string{
|
||||||
@@ -389,7 +407,14 @@ func GlobalConfigForTests(ctx android.PathContext) GlobalConfig {
|
|||||||
BootFlags: "",
|
BootFlags: "",
|
||||||
Dex2oatImageXmx: "",
|
Dex2oatImageXmx: "",
|
||||||
Dex2oatImageXms: "",
|
Dex2oatImageXms: "",
|
||||||
SoongConfig: GlobalSoongConfig{
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GlobalSoongConfigForTests(config android.Config) GlobalSoongConfig {
|
||||||
|
// Install the test GlobalSoongConfig in the Once cache so that later calls to
|
||||||
|
// Get(Cached)GlobalSoongConfig returns it without trying to create a real one.
|
||||||
|
return config.Once(globalSoongConfigOnceKey, func() interface{} {
|
||||||
|
return GlobalSoongConfig{
|
||||||
Profman: android.PathForTesting("profman"),
|
Profman: android.PathForTesting("profman"),
|
||||||
Dex2oat: android.PathForTesting("dex2oat"),
|
Dex2oat: android.PathForTesting("dex2oat"),
|
||||||
Aapt: android.PathForTesting("aapt"),
|
Aapt: android.PathForTesting("aapt"),
|
||||||
@@ -397,6 +422,6 @@ func GlobalConfigForTests(ctx android.PathContext) GlobalConfig {
|
|||||||
Zip2zip: android.PathForTesting("zip2zip"),
|
Zip2zip: android.PathForTesting("zip2zip"),
|
||||||
ManifestCheck: android.PathForTesting("manifest_check"),
|
ManifestCheck: android.PathForTesting("manifest_check"),
|
||||||
ConstructContext: android.PathForTesting("construct_context.sh"),
|
ConstructContext: android.PathForTesting("construct_context.sh"),
|
||||||
},
|
}
|
||||||
}
|
}).(GlobalSoongConfig)
|
||||||
}
|
}
|
||||||
|
@@ -58,7 +58,7 @@ var SystemServerForcedDepTag = dependencyTag{name: "system-server-forced-dep"}
|
|||||||
|
|
||||||
// GenerateDexpreoptRule generates a set of commands that will preopt a module based on a GlobalConfig and a
|
// GenerateDexpreoptRule generates a set of commands that will preopt a module based on a GlobalConfig and a
|
||||||
// ModuleConfig. The produced files and their install locations will be available through rule.Installs().
|
// ModuleConfig. The produced files and their install locations will be available through rule.Installs().
|
||||||
func GenerateDexpreoptRule(ctx android.PathContext,
|
func GenerateDexpreoptRule(ctx android.PathContext, globalSoong GlobalSoongConfig,
|
||||||
global GlobalConfig, module ModuleConfig) (rule *android.RuleBuilder, err error) {
|
global GlobalConfig, module ModuleConfig) (rule *android.RuleBuilder, err error) {
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -81,10 +81,10 @@ func GenerateDexpreoptRule(ctx android.PathContext,
|
|||||||
|
|
||||||
var profile android.WritablePath
|
var profile android.WritablePath
|
||||||
if generateProfile {
|
if generateProfile {
|
||||||
profile = profileCommand(ctx, global, module, rule)
|
profile = profileCommand(ctx, globalSoong, global, module, rule)
|
||||||
}
|
}
|
||||||
if generateBootProfile {
|
if generateBootProfile {
|
||||||
bootProfileCommand(ctx, global, module, rule)
|
bootProfileCommand(ctx, globalSoong, global, module, rule)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !dexpreoptDisabled(ctx, global, module) {
|
if !dexpreoptDisabled(ctx, global, module) {
|
||||||
@@ -96,7 +96,7 @@ func GenerateDexpreoptRule(ctx android.PathContext,
|
|||||||
generateDM := shouldGenerateDM(module, global)
|
generateDM := shouldGenerateDM(module, global)
|
||||||
|
|
||||||
for archIdx, _ := range module.Archs {
|
for archIdx, _ := range module.Archs {
|
||||||
dexpreoptCommand(ctx, global, module, rule, archIdx, profile, appImage, generateDM)
|
dexpreoptCommand(ctx, globalSoong, global, module, rule, archIdx, profile, appImage, generateDM)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,8 +135,8 @@ func dexpreoptDisabled(ctx android.PathContext, global GlobalConfig, module Modu
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func profileCommand(ctx android.PathContext, global GlobalConfig, module ModuleConfig,
|
func profileCommand(ctx android.PathContext, globalSoong GlobalSoongConfig, global GlobalConfig,
|
||||||
rule *android.RuleBuilder) android.WritablePath {
|
module ModuleConfig, rule *android.RuleBuilder) android.WritablePath {
|
||||||
|
|
||||||
profilePath := module.BuildPath.InSameDir(ctx, "profile.prof")
|
profilePath := module.BuildPath.InSameDir(ctx, "profile.prof")
|
||||||
profileInstalledPath := module.DexLocation + ".prof"
|
profileInstalledPath := module.DexLocation + ".prof"
|
||||||
@@ -147,7 +147,7 @@ func profileCommand(ctx android.PathContext, global GlobalConfig, module ModuleC
|
|||||||
|
|
||||||
cmd := rule.Command().
|
cmd := rule.Command().
|
||||||
Text(`ANDROID_LOG_TAGS="*:e"`).
|
Text(`ANDROID_LOG_TAGS="*:e"`).
|
||||||
Tool(global.SoongConfig.Profman)
|
Tool(globalSoong.Profman)
|
||||||
|
|
||||||
if module.ProfileIsTextListing {
|
if module.ProfileIsTextListing {
|
||||||
// The profile is a test listing of classes (used for framework jars).
|
// The profile is a test listing of classes (used for framework jars).
|
||||||
@@ -174,8 +174,8 @@ func profileCommand(ctx android.PathContext, global GlobalConfig, module ModuleC
|
|||||||
return profilePath
|
return profilePath
|
||||||
}
|
}
|
||||||
|
|
||||||
func bootProfileCommand(ctx android.PathContext, global GlobalConfig, module ModuleConfig,
|
func bootProfileCommand(ctx android.PathContext, globalSoong GlobalSoongConfig, global GlobalConfig,
|
||||||
rule *android.RuleBuilder) android.WritablePath {
|
module ModuleConfig, rule *android.RuleBuilder) android.WritablePath {
|
||||||
|
|
||||||
profilePath := module.BuildPath.InSameDir(ctx, "profile.bprof")
|
profilePath := module.BuildPath.InSameDir(ctx, "profile.bprof")
|
||||||
profileInstalledPath := module.DexLocation + ".bprof"
|
profileInstalledPath := module.DexLocation + ".bprof"
|
||||||
@@ -186,7 +186,7 @@ func bootProfileCommand(ctx android.PathContext, global GlobalConfig, module Mod
|
|||||||
|
|
||||||
cmd := rule.Command().
|
cmd := rule.Command().
|
||||||
Text(`ANDROID_LOG_TAGS="*:e"`).
|
Text(`ANDROID_LOG_TAGS="*:e"`).
|
||||||
Tool(global.SoongConfig.Profman)
|
Tool(globalSoong.Profman)
|
||||||
|
|
||||||
// The profile is a test listing of methods.
|
// The profile is a test listing of methods.
|
||||||
// We need to generate the actual binary profile.
|
// We need to generate the actual binary profile.
|
||||||
@@ -206,8 +206,9 @@ func bootProfileCommand(ctx android.PathContext, global GlobalConfig, module Mod
|
|||||||
return profilePath
|
return profilePath
|
||||||
}
|
}
|
||||||
|
|
||||||
func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module ModuleConfig, rule *android.RuleBuilder,
|
func dexpreoptCommand(ctx android.PathContext, globalSoong GlobalSoongConfig, global GlobalConfig,
|
||||||
archIdx int, profile android.WritablePath, appImage bool, generateDM bool) {
|
module ModuleConfig, rule *android.RuleBuilder, archIdx int, profile android.WritablePath,
|
||||||
|
appImage bool, generateDM bool) {
|
||||||
|
|
||||||
arch := module.Archs[archIdx]
|
arch := module.Archs[archIdx]
|
||||||
|
|
||||||
@@ -345,14 +346,14 @@ func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module Modul
|
|||||||
if module.EnforceUsesLibraries {
|
if module.EnforceUsesLibraries {
|
||||||
if module.ManifestPath != nil {
|
if module.ManifestPath != nil {
|
||||||
rule.Command().Text(`target_sdk_version="$(`).
|
rule.Command().Text(`target_sdk_version="$(`).
|
||||||
Tool(global.SoongConfig.ManifestCheck).
|
Tool(globalSoong.ManifestCheck).
|
||||||
Flag("--extract-target-sdk-version").
|
Flag("--extract-target-sdk-version").
|
||||||
Input(module.ManifestPath).
|
Input(module.ManifestPath).
|
||||||
Text(`)"`)
|
Text(`)"`)
|
||||||
} else {
|
} else {
|
||||||
// No manifest to extract targetSdkVersion from, hope that DexJar is an APK
|
// No manifest to extract targetSdkVersion from, hope that DexJar is an APK
|
||||||
rule.Command().Text(`target_sdk_version="$(`).
|
rule.Command().Text(`target_sdk_version="$(`).
|
||||||
Tool(global.SoongConfig.Aapt).
|
Tool(globalSoong.Aapt).
|
||||||
Flag("dump badging").
|
Flag("dump badging").
|
||||||
Input(module.DexPath).
|
Input(module.DexPath).
|
||||||
Text(`| grep "targetSdkVersion" | sed -n "s/targetSdkVersion:'\(.*\)'/\1/p"`).
|
Text(`| grep "targetSdkVersion" | sed -n "s/targetSdkVersion:'\(.*\)'/\1/p"`).
|
||||||
@@ -373,7 +374,7 @@ func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module Modul
|
|||||||
Implicits(conditionalClassLoaderContextHost29)
|
Implicits(conditionalClassLoaderContextHost29)
|
||||||
rule.Command().Textf(`conditional_target_libs_29="%s"`,
|
rule.Command().Textf(`conditional_target_libs_29="%s"`,
|
||||||
strings.Join(conditionalClassLoaderContextTarget29, " "))
|
strings.Join(conditionalClassLoaderContextTarget29, " "))
|
||||||
rule.Command().Text("source").Tool(global.SoongConfig.ConstructContext).Input(module.DexPath)
|
rule.Command().Text("source").Tool(globalSoong.ConstructContext).Input(module.DexPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devices that do not have a product partition use a symlink from /product to /system/product.
|
// Devices that do not have a product partition use a symlink from /product to /system/product.
|
||||||
@@ -386,7 +387,7 @@ func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module Modul
|
|||||||
|
|
||||||
cmd := rule.Command().
|
cmd := rule.Command().
|
||||||
Text(`ANDROID_LOG_TAGS="*:e"`).
|
Text(`ANDROID_LOG_TAGS="*:e"`).
|
||||||
Tool(global.SoongConfig.Dex2oat).
|
Tool(globalSoong.Dex2oat).
|
||||||
Flag("--avoid-storing-invocation").
|
Flag("--avoid-storing-invocation").
|
||||||
FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath).
|
FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath).
|
||||||
Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatXms).
|
Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatXms).
|
||||||
@@ -455,7 +456,7 @@ func dexpreoptCommand(ctx android.PathContext, global GlobalConfig, module Modul
|
|||||||
dmInstalledPath := pathtools.ReplaceExtension(module.DexLocation, "dm")
|
dmInstalledPath := pathtools.ReplaceExtension(module.DexLocation, "dm")
|
||||||
tmpPath := module.BuildPath.InSameDir(ctx, "primary.vdex")
|
tmpPath := module.BuildPath.InSameDir(ctx, "primary.vdex")
|
||||||
rule.Command().Text("cp -f").Input(vdexPath).Output(tmpPath)
|
rule.Command().Text("cp -f").Input(vdexPath).Output(tmpPath)
|
||||||
rule.Command().Tool(global.SoongConfig.SoongZip).
|
rule.Command().Tool(globalSoong.SoongZip).
|
||||||
FlagWithArg("-L", "9").
|
FlagWithArg("-L", "9").
|
||||||
FlagWithOutput("-o", dmPath).
|
FlagWithOutput("-o", dmPath).
|
||||||
Flag("-j").
|
Flag("-j").
|
||||||
|
@@ -80,13 +80,13 @@ func main() {
|
|||||||
|
|
||||||
globalSoongConfigData, err := ioutil.ReadFile(*globalSoongConfigPath)
|
globalSoongConfigData, err := ioutil.ReadFile(*globalSoongConfigPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error reading global config %q: %s\n", *globalSoongConfigPath, err)
|
fmt.Fprintf(os.Stderr, "error reading global Soong config %q: %s\n", *globalSoongConfigPath, err)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
globalSoongConfig, err := dexpreopt.LoadGlobalSoongConfig(ctx, globalSoongConfigData)
|
globalSoongConfig, err := dexpreopt.LoadGlobalSoongConfig(ctx, globalSoongConfigData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error loading global config %q: %s\n", *globalSoongConfigPath, err)
|
fmt.Fprintf(os.Stderr, "error loading global Soong config %q: %s\n", *globalSoongConfigPath, err)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,9 +96,9 @@ func main() {
|
|||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
globalConfig, err := dexpreopt.LoadGlobalConfig(ctx, globalConfigData, globalSoongConfig)
|
globalConfig, err := dexpreopt.LoadGlobalConfig(ctx, globalConfigData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error parse global config %q: %s\n", *globalConfigPath, err)
|
fmt.Fprintf(os.Stderr, "error loading global config %q: %s\n", *globalConfigPath, err)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,12 +130,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
writeScripts(ctx, globalConfig, moduleConfig, *dexpreoptScriptPath)
|
writeScripts(ctx, globalSoongConfig, globalConfig, moduleConfig, *dexpreoptScriptPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeScripts(ctx android.PathContext, global dexpreopt.GlobalConfig, module dexpreopt.ModuleConfig,
|
func writeScripts(ctx android.PathContext, globalSoong dexpreopt.GlobalSoongConfig,
|
||||||
dexpreoptScriptPath string) {
|
global dexpreopt.GlobalConfig, module dexpreopt.ModuleConfig, dexpreoptScriptPath string) {
|
||||||
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(ctx, global, module)
|
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(ctx, globalSoong, global, module)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ func writeScripts(ctx android.PathContext, global dexpreopt.GlobalConfig, module
|
|||||||
dexpreoptRule.Command().Text("mkdir -p").Flag(filepath.Dir(installPath.String()))
|
dexpreoptRule.Command().Text("mkdir -p").Flag(filepath.Dir(installPath.String()))
|
||||||
dexpreoptRule.Command().Text("cp -f").Input(install.From).Output(installPath)
|
dexpreoptRule.Command().Text("cp -f").Input(install.From).Output(installPath)
|
||||||
}
|
}
|
||||||
dexpreoptRule.Command().Tool(global.SoongConfig.SoongZip).
|
dexpreoptRule.Command().Tool(globalSoong.SoongZip).
|
||||||
FlagWithArg("-o ", "$2").
|
FlagWithArg("-o ", "$2").
|
||||||
FlagWithArg("-C ", installDir.String()).
|
FlagWithArg("-C ", installDir.String()).
|
||||||
FlagWithArg("-D ", installDir.String())
|
FlagWithArg("-D ", installDir.String())
|
||||||
|
@@ -61,10 +61,13 @@ func testModuleConfig(ctx android.PathContext, name, partition string) ModuleCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDexPreopt(t *testing.T) {
|
func TestDexPreopt(t *testing.T) {
|
||||||
ctx := android.PathContextForTesting(android.TestConfig("out", nil, "", nil))
|
config := android.TestConfig("out", nil, "", nil)
|
||||||
global, module := GlobalConfigForTests(ctx), testSystemModuleConfig(ctx, "test")
|
ctx := android.PathContextForTesting(config)
|
||||||
|
globalSoong := GlobalSoongConfigForTests(config)
|
||||||
|
global := GlobalConfigForTests(ctx)
|
||||||
|
module := testSystemModuleConfig(ctx, "test")
|
||||||
|
|
||||||
rule, err := GenerateDexpreoptRule(ctx, global, module)
|
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -80,7 +83,9 @@ func TestDexPreopt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDexPreoptSystemOther(t *testing.T) {
|
func TestDexPreoptSystemOther(t *testing.T) {
|
||||||
ctx := android.PathContextForTesting(android.TestConfig("out", nil, "", nil))
|
config := android.TestConfig("out", nil, "", nil)
|
||||||
|
ctx := android.PathContextForTesting(config)
|
||||||
|
globalSoong := GlobalSoongConfigForTests(config)
|
||||||
global := GlobalConfigForTests(ctx)
|
global := GlobalConfigForTests(ctx)
|
||||||
systemModule := testSystemModuleConfig(ctx, "Stest")
|
systemModule := testSystemModuleConfig(ctx, "Stest")
|
||||||
systemProductModule := testSystemProductModuleConfig(ctx, "SPtest")
|
systemProductModule := testSystemProductModuleConfig(ctx, "SPtest")
|
||||||
@@ -118,7 +123,7 @@ func TestDexPreoptSystemOther(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
global.PatternsOnSystemOther = test.patterns
|
global.PatternsOnSystemOther = test.patterns
|
||||||
for _, mt := range test.moduleTests {
|
for _, mt := range test.moduleTests {
|
||||||
rule, err := GenerateDexpreoptRule(ctx, global, mt.module)
|
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, mt.module)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -138,12 +143,15 @@ func TestDexPreoptSystemOther(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDexPreoptProfile(t *testing.T) {
|
func TestDexPreoptProfile(t *testing.T) {
|
||||||
ctx := android.PathContextForTesting(android.TestConfig("out", nil, "", nil))
|
config := android.TestConfig("out", nil, "", nil)
|
||||||
global, module := GlobalConfigForTests(ctx), testSystemModuleConfig(ctx, "test")
|
ctx := android.PathContextForTesting(config)
|
||||||
|
globalSoong := GlobalSoongConfigForTests(config)
|
||||||
|
global := GlobalConfigForTests(ctx)
|
||||||
|
module := testSystemModuleConfig(ctx, "test")
|
||||||
|
|
||||||
module.ProfileClassListing = android.OptionalPathForPath(android.PathForTesting("profile"))
|
module.ProfileClassListing = android.OptionalPathForPath(android.PathForTesting("profile"))
|
||||||
|
|
||||||
rule, err := GenerateDexpreoptRule(ctx, global, module)
|
rule, err := GenerateDexpreoptRule(ctx, globalSoong, global, module)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@@ -104,6 +104,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo
|
|||||||
return dexJarFile
|
return dexJarFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
|
||||||
global := dexpreoptGlobalConfig(ctx)
|
global := dexpreoptGlobalConfig(ctx)
|
||||||
bootImage := defaultBootImageConfig(ctx)
|
bootImage := defaultBootImageConfig(ctx)
|
||||||
dexFiles := bootImage.dexPathsDeps.Paths()
|
dexFiles := bootImage.dexPathsDeps.Paths()
|
||||||
@@ -191,7 +192,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo
|
|||||||
PresignedPrebuilt: d.isPresignedPrebuilt,
|
PresignedPrebuilt: d.isPresignedPrebuilt,
|
||||||
}
|
}
|
||||||
|
|
||||||
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(ctx, global, dexpreoptConfig)
|
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(ctx, globalSoong, global, dexpreoptConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error())
|
ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error())
|
||||||
return dexJarFile
|
return dexJarFile
|
||||||
|
@@ -295,6 +295,7 @@ func buildBootImage(ctx android.SingletonContext, config bootImageConfig) *bootI
|
|||||||
func buildBootImageRuleForArch(ctx android.SingletonContext, image *bootImage,
|
func buildBootImageRuleForArch(ctx android.SingletonContext, image *bootImage,
|
||||||
arch android.ArchType, profile android.Path, missingDeps []string) android.WritablePaths {
|
arch android.ArchType, profile android.Path, missingDeps []string) android.WritablePaths {
|
||||||
|
|
||||||
|
globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
|
||||||
global := dexpreoptGlobalConfig(ctx)
|
global := dexpreoptGlobalConfig(ctx)
|
||||||
|
|
||||||
symbolsDir := image.symbolsDir.Join(ctx, image.installSubdir, arch.String())
|
symbolsDir := image.symbolsDir.Join(ctx, image.installSubdir, arch.String())
|
||||||
@@ -330,7 +331,7 @@ func buildBootImageRuleForArch(ctx android.SingletonContext, image *bootImage,
|
|||||||
|
|
||||||
invocationPath := outputPath.ReplaceExtension(ctx, "invocation")
|
invocationPath := outputPath.ReplaceExtension(ctx, "invocation")
|
||||||
|
|
||||||
cmd.Tool(global.SoongConfig.Dex2oat).
|
cmd.Tool(globalSoong.Dex2oat).
|
||||||
Flag("--avoid-storing-invocation").
|
Flag("--avoid-storing-invocation").
|
||||||
FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath).
|
FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath).
|
||||||
Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatImageXms).
|
Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatImageXms).
|
||||||
@@ -433,6 +434,7 @@ It is likely that the boot classpath is inconsistent.
|
|||||||
Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.`
|
Rebuild with ART_BOOT_IMAGE_EXTRA_ARGS="--runtime-arg -verbose:verifier" to see verification errors.`
|
||||||
|
|
||||||
func bootImageProfileRule(ctx android.SingletonContext, image *bootImage, missingDeps []string) android.WritablePath {
|
func bootImageProfileRule(ctx android.SingletonContext, image *bootImage, missingDeps []string) android.WritablePath {
|
||||||
|
globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
|
||||||
global := dexpreoptGlobalConfig(ctx)
|
global := dexpreoptGlobalConfig(ctx)
|
||||||
|
|
||||||
if global.DisableGenerateProfile || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() {
|
if global.DisableGenerateProfile || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() {
|
||||||
@@ -464,7 +466,7 @@ func bootImageProfileRule(ctx android.SingletonContext, image *bootImage, missin
|
|||||||
|
|
||||||
rule.Command().
|
rule.Command().
|
||||||
Text(`ANDROID_LOG_TAGS="*:e"`).
|
Text(`ANDROID_LOG_TAGS="*:e"`).
|
||||||
Tool(global.SoongConfig.Profman).
|
Tool(globalSoong.Profman).
|
||||||
FlagWithInput("--create-profile-from=", bootImageProfile).
|
FlagWithInput("--create-profile-from=", bootImageProfile).
|
||||||
FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
|
FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
|
||||||
FlagForEachArg("--dex-location=", image.dexLocationsDeps).
|
FlagForEachArg("--dex-location=", image.dexLocationsDeps).
|
||||||
@@ -487,6 +489,7 @@ func bootImageProfileRule(ctx android.SingletonContext, image *bootImage, missin
|
|||||||
var bootImageProfileRuleKey = android.NewOnceKey("bootImageProfileRule")
|
var bootImageProfileRuleKey = android.NewOnceKey("bootImageProfileRule")
|
||||||
|
|
||||||
func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImage, missingDeps []string) android.WritablePath {
|
func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImage, missingDeps []string) android.WritablePath {
|
||||||
|
globalSoong := dexpreopt.GetCachedGlobalSoongConfig(ctx)
|
||||||
global := dexpreoptGlobalConfig(ctx)
|
global := dexpreoptGlobalConfig(ctx)
|
||||||
|
|
||||||
if global.DisableGenerateProfile || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() {
|
if global.DisableGenerateProfile || ctx.Config().IsPdkBuild() || ctx.Config().UnbundledBuild() {
|
||||||
@@ -513,7 +516,7 @@ func bootFrameworkProfileRule(ctx android.SingletonContext, image *bootImage, mi
|
|||||||
|
|
||||||
rule.Command().
|
rule.Command().
|
||||||
Text(`ANDROID_LOG_TAGS="*:e"`).
|
Text(`ANDROID_LOG_TAGS="*:e"`).
|
||||||
Tool(global.SoongConfig.Profman).
|
Tool(globalSoong.Profman).
|
||||||
Flag("--generate-boot-profile").
|
Flag("--generate-boot-profile").
|
||||||
FlagWithInput("--create-profile-from=", bootFrameworkProfile).
|
FlagWithInput("--create-profile-from=", bootFrameworkProfile).
|
||||||
FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
|
FlagForEachInput("--apk=", image.dexPathsDeps.Paths()).
|
||||||
|
@@ -39,8 +39,7 @@ func dexpreoptGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw {
|
|||||||
if data, err := ctx.Config().DexpreoptGlobalConfig(ctx); err != nil {
|
if data, err := ctx.Config().DexpreoptGlobalConfig(ctx); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
} else if data != nil {
|
} else if data != nil {
|
||||||
soongConfig := dexpreopt.CreateGlobalSoongConfig(ctx)
|
globalConfig, err := dexpreopt.LoadGlobalConfig(ctx, data)
|
||||||
globalConfig, err := dexpreopt.LoadGlobalConfig(ctx, data, soongConfig)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@@ -57,7 +57,13 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
|
func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config {
|
||||||
return TestConfig(buildDir, env, bp, fs)
|
config := TestConfig(buildDir, env, bp, fs)
|
||||||
|
|
||||||
|
// Set up the global Once cache used for dexpreopt.GlobalSoongConfig, so that
|
||||||
|
// it doesn't create a real one, which would fail.
|
||||||
|
_ = dexpreopt.GlobalSoongConfigForTests(config)
|
||||||
|
|
||||||
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
func testContext() *android.TestContext {
|
func testContext() *android.TestContext {
|
||||||
|
Reference in New Issue
Block a user