Write dexpreopt.config again during the build
Writing $OUT/dexpreopt.config during build setup and then using
it during the build causes bad incremental builds if a cleanspec
removes $OUT/dexpreopt.config. Create a rule in Soong to write
out a copy so that it is a normal build artifact.
Bug: 132379813
Test: m checkbuild
Change-Id: I7755a7f8c1d6561fc83022a7f4cf7e4a64e989c9
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index 3b77042..1e0f862 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -176,7 +176,7 @@
// LoadGlobalConfig reads the global dexpreopt.config file into a GlobalConfig struct. It 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, path string) (GlobalConfig, error) {
+func LoadGlobalConfig(ctx android.PathContext, path string) (GlobalConfig, []byte, error) {
type GlobalJSONConfig struct {
GlobalConfig
@@ -199,9 +199,9 @@
}
config := GlobalJSONConfig{}
- err := loadConfig(ctx, path, &config)
+ data, err := loadConfig(ctx, path, &config)
if err != nil {
- return config.GlobalConfig, err
+ return config.GlobalConfig, nil, err
}
// Construct paths that require a PathContext.
@@ -217,7 +217,7 @@
config.GlobalConfig.Tools.VerifyUsesLibraries = constructPath(ctx, config.Tools.VerifyUsesLibraries)
config.GlobalConfig.Tools.ConstructContext = constructPath(ctx, config.Tools.ConstructContext)
- return config.GlobalConfig, nil
+ return config.GlobalConfig, data, nil
}
// LoadModuleConfig reads a per-module dexpreopt.config file into a ModuleConfig struct. It is not used in Soong, which
@@ -241,7 +241,7 @@
config := ModuleJSONConfig{}
- err := loadConfig(ctx, path, &config)
+ _, err := loadConfig(ctx, path, &config)
if err != nil {
return config.ModuleConfig, err
}
@@ -259,24 +259,24 @@
return config.ModuleConfig, nil
}
-func loadConfig(ctx android.PathContext, path string, config interface{}) error {
+func loadConfig(ctx android.PathContext, path string, config interface{}) ([]byte, error) {
r, err := ctx.Fs().Open(path)
if err != nil {
- return err
+ return nil, err
}
defer r.Close()
data, err := ioutil.ReadAll(r)
if err != nil {
- return err
+ return nil, err
}
err = json.Unmarshal(data, config)
if err != nil {
- return err
+ return nil, err
}
- return nil
+ return data, nil
}
func GlobalConfigForTests(ctx android.PathContext) GlobalConfig {