Revert "Move the Once cache for dexpreopt.GlobalConfig into the ..."
Revert submission 1211982-dex2oat-soong-dep
Reason for revert: Build failures. See b/148312086.
Reverted Changes:
Ibc427a9a8: Make dex2oat(d) visible for use as implicit dexpre...
I71df11c1e: Move the Once cache for dexpreopt.GlobalConfig int...
I38317f2d5: Get the dex2oat host tool path from module depende...
I440a09dba: Separate dexpreopt.GlobalSoongConfig to allow inde...
Bug: 148312086
Bug: 145934348
Exempt-From-Owner-Approval: Plain revert
Change-Id: I6b656afb5feaad70d958b9d38b6c6eab7b03fba1
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index cd74ec8..63d55df 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -176,9 +176,10 @@
return constructPath(ctx, path).(android.WritablePath)
}
-// ParseGlobalConfig parses the given data assumed to be read from the global
-// dexpreopt.config file into a GlobalConfig struct.
-func ParseGlobalConfig(ctx android.PathContext, data []byte) (GlobalConfig, error) {
+// LoadGlobalConfig reads the global dexpreopt.config file into a GlobalConfig
+// struct. LoadGlobalConfig is used directly in Soong and in dexpreopt_gen
+// called from Make to read the $OUT/dexpreopt.config written by Make.
+func LoadGlobalConfig(ctx android.PathContext, data []byte) (GlobalConfig, error) {
type GlobalJSONConfig struct {
GlobalConfig
@@ -201,65 +202,10 @@
return config.GlobalConfig, nil
}
-type globalConfigAndRaw struct {
- global GlobalConfig
- data []byte
-}
-
-// GetGlobalConfig returns the global dexpreopt.config that's created in the
-// make config phase. It is loaded once the first time it is called for any
-// ctx.Config(), and returns the same data for all future calls with the same
-// ctx.Config(). A value can be inserted for tests using
-// setDexpreoptTestGlobalConfig.
-func GetGlobalConfig(ctx android.PathContext) GlobalConfig {
- return getGlobalConfigRaw(ctx).global
-}
-
-// GetGlobalConfigRawData is the same as GetGlobalConfig, except that it returns
-// the literal content of dexpreopt.config.
-func GetGlobalConfigRawData(ctx android.PathContext) []byte {
- return getGlobalConfigRaw(ctx).data
-}
-
-var globalConfigOnceKey = android.NewOnceKey("DexpreoptGlobalConfig")
-var testGlobalConfigOnceKey = android.NewOnceKey("TestDexpreoptGlobalConfig")
-
-func getGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw {
- return ctx.Config().Once(globalConfigOnceKey, func() interface{} {
- if data, err := ctx.Config().DexpreoptGlobalConfig(ctx); err != nil {
- panic(err)
- } else if data != nil {
- globalConfig, err := ParseGlobalConfig(ctx, data)
- if err != nil {
- panic(err)
- }
- return globalConfigAndRaw{globalConfig, data}
- }
-
- // No global config filename set, see if there is a test config set
- return ctx.Config().Once(testGlobalConfigOnceKey, func() interface{} {
- // Nope, return a config with preopting disabled
- return globalConfigAndRaw{GlobalConfig{
- DisablePreopt: true,
- DisableGenerateProfile: true,
- }, nil}
- })
- }).(globalConfigAndRaw)
-}
-
-// SetTestGlobalConfig sets a GlobalConfig that future calls to GetGlobalConfig
-// will return. It must be called before the first call to GetGlobalConfig for
-// the config.
-func SetTestGlobalConfig(config android.Config, globalConfig GlobalConfig) {
- config.Once(testGlobalConfigOnceKey, func() interface{} { return globalConfigAndRaw{globalConfig, nil} })
-}
-
-// ParseModuleConfig parses a per-module dexpreopt.config file into a
-// ModuleConfig struct. It is not used in Soong, which receives a ModuleConfig
-// 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
-// stage.
-func ParseModuleConfig(ctx android.PathContext, data []byte) (ModuleConfig, error) {
+// LoadModuleConfig reads a per-module dexpreopt.config file into a ModuleConfig struct. It is not used in Soong, which
+// receives a ModuleConfig struct directly from java/dexpreopt.go. It is used in dexpreopt_gen called from oMake to
+// read the module dexpreopt.config written by Make.
+func LoadModuleConfig(ctx android.PathContext, data []byte) (ModuleConfig, error) {
type ModuleJSONConfig struct {
ModuleConfig
@@ -358,10 +304,9 @@
ConstructContext string
}
-// ParseGlobalSoongConfig parses the given data assumed to be read from the
-// global dexpreopt_soong.config file into a GlobalSoongConfig struct. It is
-// only used in dexpreopt_gen.
-func ParseGlobalSoongConfig(ctx android.PathContext, data []byte) (GlobalSoongConfig, error) {
+// LoadGlobalSoongConfig reads the dexpreopt_soong.config file into a
+// GlobalSoongConfig struct. It is only used in dexpreopt_gen.
+func LoadGlobalSoongConfig(ctx android.PathContext, data []byte) (GlobalSoongConfig, error) {
var jc globalJsonSoongConfig
err := json.Unmarshal(data, &jc)
diff --git a/dexpreopt/dexpreopt_gen/dexpreopt_gen.go b/dexpreopt/dexpreopt_gen/dexpreopt_gen.go
index 4da003e..708bb9b 100644
--- a/dexpreopt/dexpreopt_gen/dexpreopt_gen.go
+++ b/dexpreopt/dexpreopt_gen/dexpreopt_gen.go
@@ -84,9 +84,9 @@
os.Exit(2)
}
- globalSoongConfig, err := dexpreopt.ParseGlobalSoongConfig(ctx, globalSoongConfigData)
+ globalSoongConfig, err := dexpreopt.LoadGlobalSoongConfig(ctx, globalSoongConfigData)
if err != nil {
- fmt.Fprintf(os.Stderr, "error parsing global Soong config %q: %s\n", *globalSoongConfigPath, err)
+ fmt.Fprintf(os.Stderr, "error loading global Soong config %q: %s\n", *globalSoongConfigPath, err)
os.Exit(2)
}
@@ -96,9 +96,9 @@
os.Exit(2)
}
- globalConfig, err := dexpreopt.ParseGlobalConfig(ctx, globalConfigData)
+ globalConfig, err := dexpreopt.LoadGlobalConfig(ctx, globalConfigData)
if err != nil {
- fmt.Fprintf(os.Stderr, "error parsing global config %q: %s\n", *globalConfigPath, err)
+ fmt.Fprintf(os.Stderr, "error loading global config %q: %s\n", *globalConfigPath, err)
os.Exit(2)
}
@@ -108,9 +108,9 @@
os.Exit(2)
}
- moduleConfig, err := dexpreopt.ParseModuleConfig(ctx, moduleConfigData)
+ moduleConfig, err := dexpreopt.LoadModuleConfig(ctx, moduleConfigData)
if err != nil {
- fmt.Fprintf(os.Stderr, "error parsing module config %q: %s\n", *moduleConfigPath, err)
+ fmt.Fprintf(os.Stderr, "error loading module config %q: %s\n", *moduleConfigPath, err)
os.Exit(2)
}