Pass dexpreopt config structs by reference.

Should cut down on a bit of copying, and also required for an upcoming
CL that'll change GetCachedGlobalSoongConfig.

Test: m nothing
Bug: 145934348
Change-Id: I6bed737d9b061b5239cc603ad881f4ccd4312e43
This commit is contained in:
Martin Stjernholm
2020-01-31 17:44:54 +00:00
parent d90676fdde
commit 8d80ceeb12
5 changed files with 45 additions and 45 deletions

View File

@@ -180,9 +180,9 @@ func constructWritablePath(ctx android.PathContext, path string) android.Writabl
// ParseGlobalConfig parses the given data assumed to be read from the global // ParseGlobalConfig parses the given data assumed to be read from the global
// dexpreopt.config file into a GlobalConfig struct. // dexpreopt.config file into a GlobalConfig struct.
func ParseGlobalConfig(ctx android.PathContext, data []byte) (GlobalConfig, error) { func ParseGlobalConfig(ctx android.PathContext, data []byte) (*GlobalConfig, error) {
type GlobalJSONConfig struct { type GlobalJSONConfig struct {
GlobalConfig *GlobalConfig
// Copies of entries in GlobalConfig that are not constructable without extra parameters. They will be // Copies of entries in GlobalConfig that are not constructable without extra parameters. They will be
// used to construct the real value manually below. // used to construct the real value manually below.
@@ -204,7 +204,7 @@ func ParseGlobalConfig(ctx android.PathContext, data []byte) (GlobalConfig, erro
} }
type globalConfigAndRaw struct { type globalConfigAndRaw struct {
global GlobalConfig global *GlobalConfig
data []byte data []byte
} }
@@ -213,7 +213,7 @@ type globalConfigAndRaw struct {
// ctx.Config(), and returns the same data for all future calls with the same // ctx.Config(), and returns the same data for all future calls with the same
// ctx.Config(). A value can be inserted for tests using // ctx.Config(). A value can be inserted for tests using
// setDexpreoptTestGlobalConfig. // setDexpreoptTestGlobalConfig.
func GetGlobalConfig(ctx android.PathContext) GlobalConfig { func GetGlobalConfig(ctx android.PathContext) *GlobalConfig {
return getGlobalConfigRaw(ctx).global return getGlobalConfigRaw(ctx).global
} }
@@ -241,7 +241,7 @@ func getGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw {
// No global config filename set, see if there is a test config set // No global config filename set, see if there is a test config set
return ctx.Config().Once(testGlobalConfigOnceKey, func() interface{} { return ctx.Config().Once(testGlobalConfigOnceKey, func() interface{} {
// Nope, return a config with preopting disabled // Nope, return a config with preopting disabled
return globalConfigAndRaw{GlobalConfig{ return globalConfigAndRaw{&GlobalConfig{
DisablePreopt: true, DisablePreopt: true,
DisableGenerateProfile: true, DisableGenerateProfile: true,
}, nil} }, nil}
@@ -252,7 +252,7 @@ func getGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw {
// SetTestGlobalConfig sets a GlobalConfig that future calls to GetGlobalConfig // SetTestGlobalConfig sets a GlobalConfig that future calls to GetGlobalConfig
// will return. It must be called before the first call to GetGlobalConfig for // will return. It must be called before the first call to GetGlobalConfig for
// the config. // the config.
func SetTestGlobalConfig(config android.Config, globalConfig GlobalConfig) { func SetTestGlobalConfig(config android.Config, globalConfig *GlobalConfig) {
config.Once(testGlobalConfigOnceKey, func() interface{} { return globalConfigAndRaw{globalConfig, nil} }) config.Once(testGlobalConfigOnceKey, func() interface{} { return globalConfigAndRaw{globalConfig, nil} })
} }
@@ -261,9 +261,9 @@ func SetTestGlobalConfig(config android.Config, globalConfig GlobalConfig) {
// struct directly from java/dexpreopt.go. It is used in dexpreopt_gen called // struct directly from java/dexpreopt.go. It is used in dexpreopt_gen called
// from Make to read the module dexpreopt.config written in the Make config // from Make to read the module dexpreopt.config written in the Make config
// stage. // stage.
func ParseModuleConfig(ctx android.PathContext, data []byte) (ModuleConfig, error) { func ParseModuleConfig(ctx android.PathContext, data []byte) (*ModuleConfig, error) {
type ModuleJSONConfig struct { type ModuleJSONConfig struct {
ModuleConfig *ModuleConfig
// Copies of entries in ModuleConfig that are not constructable without extra parameters. They will be // Copies of entries in ModuleConfig that are not constructable without extra parameters. They will be
// used to construct the real value manually below. // used to construct the real value manually below.
@@ -367,7 +367,7 @@ func dex2oatPathFromDep(ctx android.ModuleContext) android.Path {
// 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.ModuleContext) GlobalSoongConfig { func createGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig {
if ctx.Config().TestProductVariables != nil { if ctx.Config().TestProductVariables != nil {
// If we're called in a test there'll be a confusing error from the path // 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 // functions below that gets reported without a stack trace, so let's panic
@@ -375,7 +375,7 @@ func createGlobalSoongConfig(ctx android.ModuleContext) GlobalSoongConfig {
panic("This should not be called from tests. Please call GlobalSoongConfigForTests somewhere in the test setup.") panic("This should not be called from tests. Please call GlobalSoongConfigForTests somewhere in the test setup.")
} }
return GlobalSoongConfig{ return &GlobalSoongConfig{
Profman: ctx.Config().HostToolPath(ctx, "profman"), Profman: ctx.Config().HostToolPath(ctx, "profman"),
Dex2oat: dex2oatPathFromDep(ctx), Dex2oat: dex2oatPathFromDep(ctx),
Aapt: ctx.Config().HostToolPath(ctx, "aapt"), Aapt: ctx.Config().HostToolPath(ctx, "aapt"),
@@ -400,10 +400,10 @@ var globalSoongConfigOnceKey = android.NewOnceKey("DexpreoptGlobalSoongConfig")
// GetGlobalSoongConfig creates a GlobalSoongConfig the first time it's called, // GetGlobalSoongConfig creates a GlobalSoongConfig the first time it's called,
// and later returns the same cached instance. // and later returns the same cached instance.
func GetGlobalSoongConfig(ctx android.ModuleContext) GlobalSoongConfig { func GetGlobalSoongConfig(ctx android.ModuleContext) *GlobalSoongConfig {
globalSoong := ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} { globalSoong := ctx.Config().Once(globalSoongConfigOnceKey, func() interface{} {
return createGlobalSoongConfig(ctx) return createGlobalSoongConfig(ctx)
}).(GlobalSoongConfig) }).(*GlobalSoongConfig)
// Always resolve the tool path from the dependency, to ensure that every // Always resolve the tool path from the dependency, to ensure that every
// module has the dependency added properly. // module has the dependency added properly.
@@ -420,8 +420,8 @@ func GetGlobalSoongConfig(ctx android.ModuleContext) GlobalSoongConfig {
// compatible with a basic PathContext, since it doesn't try to create a // compatible with a basic PathContext, since it doesn't try to create a
// GlobalSoongConfig (which requires a full ModuleContext). It will panic if // GlobalSoongConfig (which requires a full ModuleContext). It will panic if
// called before the first GetGlobalSoongConfig call. // called before the first GetGlobalSoongConfig call.
func GetCachedGlobalSoongConfig(ctx android.PathContext) GlobalSoongConfig { func GetCachedGlobalSoongConfig(ctx android.PathContext) *GlobalSoongConfig {
return ctx.Config().Get(globalSoongConfigOnceKey).(GlobalSoongConfig) return ctx.Config().Get(globalSoongConfigOnceKey).(*GlobalSoongConfig)
} }
type globalJsonSoongConfig struct { type globalJsonSoongConfig struct {
@@ -437,15 +437,15 @@ type globalJsonSoongConfig struct {
// ParseGlobalSoongConfig parses the given data assumed to be read from the // ParseGlobalSoongConfig parses the given data assumed to be read from the
// global dexpreopt_soong.config file into a GlobalSoongConfig struct. It is // global dexpreopt_soong.config file into a GlobalSoongConfig struct. It is
// only used in dexpreopt_gen. // only used in dexpreopt_gen.
func ParseGlobalSoongConfig(ctx android.PathContext, data []byte) (GlobalSoongConfig, error) { func ParseGlobalSoongConfig(ctx android.PathContext, data []byte) (*GlobalSoongConfig, error) {
var jc globalJsonSoongConfig var jc globalJsonSoongConfig
err := json.Unmarshal(data, &jc) err := json.Unmarshal(data, &jc)
if err != nil { if err != nil {
return GlobalSoongConfig{}, err return &GlobalSoongConfig{}, err
} }
config := GlobalSoongConfig{ config := &GlobalSoongConfig{
Profman: constructPath(ctx, jc.Profman), Profman: constructPath(ctx, jc.Profman),
Dex2oat: constructPath(ctx, jc.Dex2oat), Dex2oat: constructPath(ctx, jc.Dex2oat),
Aapt: constructPath(ctx, jc.Aapt), Aapt: constructPath(ctx, jc.Aapt),
@@ -508,8 +508,8 @@ func (s *globalSoongConfigSingleton) MakeVars(ctx android.MakeVarsContext) {
}, " ")) }, " "))
} }
func GlobalConfigForTests(ctx android.PathContext) GlobalConfig { func GlobalConfigForTests(ctx android.PathContext) *GlobalConfig {
return GlobalConfig{ return &GlobalConfig{
DisablePreopt: false, DisablePreopt: false,
DisablePreoptModules: nil, DisablePreoptModules: nil,
OnlyPreoptBootImageAndSystemServer: false, OnlyPreoptBootImageAndSystemServer: false,
@@ -550,11 +550,11 @@ func GlobalConfigForTests(ctx android.PathContext) GlobalConfig {
} }
} }
func GlobalSoongConfigForTests(config android.Config) GlobalSoongConfig { func GlobalSoongConfigForTests(config android.Config) *GlobalSoongConfig {
// Install the test GlobalSoongConfig in the Once cache so that later calls to // 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. // Get(Cached)GlobalSoongConfig returns it without trying to create a real one.
return config.Once(globalSoongConfigOnceKey, func() interface{} { return config.Once(globalSoongConfigOnceKey, func() interface{} {
return GlobalSoongConfig{ 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"),
@@ -563,5 +563,5 @@ func GlobalSoongConfigForTests(config android.Config) GlobalSoongConfig {
ManifestCheck: android.PathForTesting("manifest_check"), ManifestCheck: android.PathForTesting("manifest_check"),
ConstructContext: android.PathForTesting("construct_context.sh"), ConstructContext: android.PathForTesting("construct_context.sh"),
} }
}).(GlobalSoongConfig) }).(*GlobalSoongConfig)
} }

View File

@@ -58,8 +58,8 @@ 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, globalSoong GlobalSoongConfig, 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() {
if r := recover(); r != nil { if r := recover(); r != nil {
@@ -104,7 +104,7 @@ func GenerateDexpreoptRule(ctx android.PathContext, globalSoong GlobalSoongConfi
return rule, nil return rule, nil
} }
func dexpreoptDisabled(ctx android.PathContext, global GlobalConfig, module ModuleConfig) bool { func dexpreoptDisabled(ctx android.PathContext, global *GlobalConfig, module *ModuleConfig) bool {
if contains(global.DisablePreoptModules, module.Name) { if contains(global.DisablePreoptModules, module.Name) {
return true return true
} }
@@ -135,8 +135,8 @@ func dexpreoptDisabled(ctx android.PathContext, global GlobalConfig, module Modu
return false return false
} }
func profileCommand(ctx android.PathContext, globalSoong GlobalSoongConfig, global GlobalConfig, func profileCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, global *GlobalConfig,
module ModuleConfig, 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"
@@ -174,8 +174,8 @@ func profileCommand(ctx android.PathContext, globalSoong GlobalSoongConfig, glob
return profilePath return profilePath
} }
func bootProfileCommand(ctx android.PathContext, globalSoong GlobalSoongConfig, global GlobalConfig, func bootProfileCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, global *GlobalConfig,
module ModuleConfig, 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"
@@ -206,8 +206,8 @@ func bootProfileCommand(ctx android.PathContext, globalSoong GlobalSoongConfig,
return profilePath return profilePath
} }
func dexpreoptCommand(ctx android.PathContext, globalSoong GlobalSoongConfig, global GlobalConfig, func dexpreoptCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, global *GlobalConfig,
module ModuleConfig, rule *android.RuleBuilder, archIdx int, profile android.WritablePath, module *ModuleConfig, rule *android.RuleBuilder, archIdx int, profile android.WritablePath,
appImage bool, generateDM bool) { appImage bool, generateDM bool) {
arch := module.Archs[archIdx] arch := module.Archs[archIdx]
@@ -521,14 +521,14 @@ func dexpreoptCommand(ctx android.PathContext, globalSoong GlobalSoongConfig, gl
rule.Install(vdexPath, vdexInstallPath) rule.Install(vdexPath, vdexInstallPath)
} }
func shouldGenerateDM(module ModuleConfig, global GlobalConfig) bool { func shouldGenerateDM(module *ModuleConfig, global *GlobalConfig) bool {
// Generating DM files only makes sense for verify, avoid doing for non verify compiler filter APKs. // Generating DM files only makes sense for verify, avoid doing for non verify compiler filter APKs.
// No reason to use a dm file if the dex is already uncompressed. // No reason to use a dm file if the dex is already uncompressed.
return global.GenerateDMFiles && !module.UncompressedDex && return global.GenerateDMFiles && !module.UncompressedDex &&
contains(module.PreoptFlags, "--compiler-filter=verify") contains(module.PreoptFlags, "--compiler-filter=verify")
} }
func OdexOnSystemOtherByName(name string, dexLocation string, global GlobalConfig) bool { func OdexOnSystemOtherByName(name string, dexLocation string, global *GlobalConfig) bool {
if !global.HasSystemOther { if !global.HasSystemOther {
return false return false
} }
@@ -550,7 +550,7 @@ func OdexOnSystemOtherByName(name string, dexLocation string, global GlobalConfi
return false return false
} }
func odexOnSystemOther(module ModuleConfig, global GlobalConfig) bool { func odexOnSystemOther(module *ModuleConfig, global *GlobalConfig) bool {
return OdexOnSystemOtherByName(module.Name, module.DexLocation, global) return OdexOnSystemOtherByName(module.Name, module.DexLocation, global)
} }
@@ -563,7 +563,7 @@ func PathToLocation(path android.Path, arch android.ArchType) string {
return filepath.Join(filepath.Dir(filepath.Dir(path.String())), filepath.Base(path.String())) return filepath.Join(filepath.Dir(filepath.Dir(path.String())), filepath.Base(path.String()))
} }
func pathForLibrary(module ModuleConfig, lib string) android.Path { func pathForLibrary(module *ModuleConfig, lib string) android.Path {
path, ok := module.LibraryPaths[lib] path, ok := module.LibraryPaths[lib]
if !ok { if !ok {
panic(fmt.Errorf("unknown library path for %q", lib)) panic(fmt.Errorf("unknown library path for %q", lib))
@@ -602,7 +602,7 @@ var nonUpdatableSystemServerJarsKey = android.NewOnceKey("nonUpdatableSystemServ
// TODO: eliminate the superficial global config parameter by moving global config definition // TODO: eliminate the superficial global config parameter by moving global config definition
// from java subpackage to dexpreopt. // from java subpackage to dexpreopt.
func NonUpdatableSystemServerJars(ctx android.PathContext, global GlobalConfig) []string { func NonUpdatableSystemServerJars(ctx android.PathContext, global *GlobalConfig) []string {
return ctx.Config().Once(nonUpdatableSystemServerJarsKey, func() interface{} { return ctx.Config().Once(nonUpdatableSystemServerJarsKey, func() interface{} {
return android.RemoveListFromList(global.SystemServerJars, return android.RemoveListFromList(global.SystemServerJars,
GetJarsFromApexJarPairs(global.UpdatableSystemServerJars)) GetJarsFromApexJarPairs(global.UpdatableSystemServerJars))

View File

@@ -133,8 +133,8 @@ func main() {
writeScripts(ctx, globalSoongConfig, globalConfig, moduleConfig, *dexpreoptScriptPath) writeScripts(ctx, globalSoongConfig, globalConfig, moduleConfig, *dexpreoptScriptPath)
} }
func writeScripts(ctx android.PathContext, globalSoong dexpreopt.GlobalSoongConfig, func writeScripts(ctx android.PathContext, globalSoong *dexpreopt.GlobalSoongConfig,
global dexpreopt.GlobalConfig, module dexpreopt.ModuleConfig, dexpreoptScriptPath string) { global *dexpreopt.GlobalConfig, module *dexpreopt.ModuleConfig, dexpreoptScriptPath string) {
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(ctx, globalSoong, global, module) dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(ctx, globalSoong, global, module)
if err != nil { if err != nil {
panic(err) panic(err)

View File

@@ -20,20 +20,20 @@ import (
"testing" "testing"
) )
func testSystemModuleConfig(ctx android.PathContext, name string) ModuleConfig { func testSystemModuleConfig(ctx android.PathContext, name string) *ModuleConfig {
return testModuleConfig(ctx, name, "system") return testModuleConfig(ctx, name, "system")
} }
func testSystemProductModuleConfig(ctx android.PathContext, name string) ModuleConfig { func testSystemProductModuleConfig(ctx android.PathContext, name string) *ModuleConfig {
return testModuleConfig(ctx, name, "system/product") return testModuleConfig(ctx, name, "system/product")
} }
func testProductModuleConfig(ctx android.PathContext, name string) ModuleConfig { func testProductModuleConfig(ctx android.PathContext, name string) *ModuleConfig {
return testModuleConfig(ctx, name, "product") return testModuleConfig(ctx, name, "product")
} }
func testModuleConfig(ctx android.PathContext, name, partition string) ModuleConfig { func testModuleConfig(ctx android.PathContext, name, partition string) *ModuleConfig {
return ModuleConfig{ return &ModuleConfig{
Name: name, Name: name,
DexLocation: fmt.Sprintf("/%s/app/test/%s.apk", partition, name), DexLocation: fmt.Sprintf("/%s/app/test/%s.apk", partition, name),
BuildPath: android.PathForOutput(ctx, fmt.Sprintf("%s/%s.apk", name, name)), BuildPath: android.PathForOutput(ctx, fmt.Sprintf("%s/%s.apk", name, name)),
@@ -94,7 +94,7 @@ func TestDexPreoptSystemOther(t *testing.T) {
global.HasSystemOther = true global.HasSystemOther = true
type moduleTest struct { type moduleTest struct {
module ModuleConfig module *ModuleConfig
expectedPartition string expectedPartition string
} }
tests := []struct { tests := []struct {

View File

@@ -157,7 +157,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo
} }
} }
dexpreoptConfig := dexpreopt.ModuleConfig{ dexpreoptConfig := &dexpreopt.ModuleConfig{
Name: ctx.ModuleName(), Name: ctx.ModuleName(),
DexLocation: dexLocation, DexLocation: dexLocation,
BuildPath: android.PathForModuleOut(ctx, "dexpreopt", ctx.ModuleName()+".jar").OutputPath, BuildPath: android.PathForModuleOut(ctx, "dexpreopt", ctx.ModuleName()+".jar").OutputPath,