Revert "Separate dexpreopt.GlobalSoongConfig to allow independen..."
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: Ice3990225635a737e49e9aed7373f06516fccea3
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index 63d55df..2a929c5 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -22,7 +22,8 @@
)
// GlobalConfig stores the configuration for dex preopting. The fields are set
-// from product variables via dex_preopt_config.mk.
+// from product variables via dex_preopt_config.mk, except for SoongConfig
+// which come from CreateGlobalSoongConfig.
type GlobalConfig struct {
DisablePreopt bool // disable preopt for all modules
DisablePreoptModules []string // modules with preopt disabled by product-specific config
@@ -81,6 +82,8 @@
BootFlags string // extra flags to pass to 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
+
+ SoongConfig GlobalSoongConfig // settings read from dexpreopt_soong.config
}
// GlobalSoongConfig contains the global config that is generated from Soong,
@@ -177,9 +180,11 @@
}
// 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) {
+// struct, except the SoongConfig field which is set from the provided
+// soongConfig argument. 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, soongConfig GlobalSoongConfig) (GlobalConfig, error) {
type GlobalJSONConfig struct {
GlobalConfig
@@ -199,6 +204,10 @@
config.GlobalConfig.DirtyImageObjects = android.OptionalPathForPath(constructPath(ctx, config.DirtyImageObjects))
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
}
@@ -244,16 +253,9 @@
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.
-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.")
- }
-
+func CreateGlobalSoongConfig(ctx android.PathContext) GlobalSoongConfig {
// Default to debug version to help find bugs.
// Set USE_DEX2OAT_DEBUG to false for only building non-debug versions.
var dex2oatBinary string
@@ -274,26 +276,6 @@
}
}
-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 {
Profman string
Dex2oat string
@@ -328,7 +310,7 @@
}
func (s *globalSoongConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) {
- config := GetCachedGlobalSoongConfig(ctx)
+ config := CreateGlobalSoongConfig(ctx)
jc := globalJsonSoongConfig{
Profman: config.Profman.String(),
Dex2oat: config.Dex2oat.String(),
@@ -355,7 +337,7 @@
}
func (s *globalSoongConfigSingleton) MakeVars(ctx android.MakeVarsContext) {
- config := GetCachedGlobalSoongConfig(ctx)
+ config := CreateGlobalSoongConfig(ctx)
ctx.Strict("DEX2OAT", config.Dex2oat.String())
ctx.Strict("DEXPREOPT_GEN_DEPS", strings.Join([]string{
@@ -408,14 +390,7 @@
BootFlags: "",
Dex2oatImageXmx: "",
Dex2oatImageXms: "",
- }
-}
-
-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{
+ SoongConfig: GlobalSoongConfig{
Profman: android.PathForTesting("profman"),
Dex2oat: android.PathForTesting("dex2oat"),
Aapt: android.PathForTesting("aapt"),
@@ -423,6 +398,6 @@
Zip2zip: android.PathForTesting("zip2zip"),
ManifestCheck: android.PathForTesting("manifest_check"),
ConstructContext: android.PathForTesting("construct_context.sh"),
- }
- }).(GlobalSoongConfig)
+ },
+ }
}