aboutsummaryrefslogtreecommitdiffstats
path: root/dexpreopt
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2020-01-10 18:51:04 +0000
committerColin Cross <ccross@android.com>2020-01-10 18:51:04 +0000
commit47e4f9e1e8d46bb72958145edc830c625fbb5f8a (patch)
treebfea06532add95dc1204a80de29a00e18633daf6 /dexpreopt
parent05c25ccb4adb5329add700b533416c226cdbfa96 (diff)
downloadbuild_soong-47e4f9e1e8d46bb72958145edc830c625fbb5f8a.tar.gz
build_soong-47e4f9e1e8d46bb72958145edc830c625fbb5f8a.tar.bz2
build_soong-47e4f9e1e8d46bb72958145edc830c625fbb5f8a.zip
Revert "Sandbox soong_build by changing to root directory"
This reverts commit 05c25ccb4adb5329add700b533416c226cdbfa96. Reason for revert: broke absolute OUT_DIR Bug: 146437378 Change-Id: I523ed79d40e1c1ef040212ba794a7a084abea75d
Diffstat (limited to 'dexpreopt')
-rw-r--r--dexpreopt/config.go37
-rw-r--r--dexpreopt/dexpreopt_gen/dexpreopt_gen.go30
2 files changed, 35 insertions, 32 deletions
diff --git a/dexpreopt/config.go b/dexpreopt/config.go
index 2a929c53..0c79ccc7 100644
--- a/dexpreopt/config.go
+++ b/dexpreopt/config.go
@@ -16,6 +16,7 @@ package dexpreopt
import (
"encoding/json"
+ "io/ioutil"
"strings"
"android/soong/android"
@@ -184,7 +185,7 @@ func constructWritablePath(ctx android.PathContext, path string) android.Writabl
// 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) {
+func LoadGlobalConfig(ctx android.PathContext, path string, soongConfig GlobalSoongConfig) (GlobalConfig, []byte, error) {
type GlobalJSONConfig struct {
GlobalConfig
@@ -195,9 +196,9 @@ func LoadGlobalConfig(ctx android.PathContext, data []byte, soongConfig GlobalSo
}
config := GlobalJSONConfig{}
- err := json.Unmarshal(data, &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.
@@ -208,13 +209,13 @@ func LoadGlobalConfig(ctx android.PathContext, data []byte, soongConfig GlobalSo
// either CreateGlobalSoongConfig or LoadGlobalSoongConfig).
config.GlobalConfig.SoongConfig = soongConfig
- 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
// 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) {
+func LoadModuleConfig(ctx android.PathContext, path string) (ModuleConfig, error) {
type ModuleJSONConfig struct {
ModuleConfig
@@ -232,7 +233,7 @@ func LoadModuleConfig(ctx android.PathContext, data []byte) (ModuleConfig, error
config := ModuleJSONConfig{}
- err := json.Unmarshal(data, &config)
+ _, err := loadConfig(ctx, path, &config)
if err != nil {
return config.ModuleConfig, err
}
@@ -288,10 +289,10 @@ type globalJsonSoongConfig struct {
// 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) {
+func LoadGlobalSoongConfig(ctx android.PathContext, path string) (GlobalSoongConfig, error) {
var jc globalJsonSoongConfig
- err := json.Unmarshal(data, &jc)
+ _, err := loadConfig(ctx, path, &jc)
if err != nil {
return GlobalSoongConfig{}, err
}
@@ -351,6 +352,26 @@ func (s *globalSoongConfigSingleton) MakeVars(ctx android.MakeVarsContext) {
}, " "))
}
+func loadConfig(ctx android.PathContext, path string, config interface{}) ([]byte, error) {
+ r, err := ctx.Fs().Open(path)
+ if err != nil {
+ return nil, err
+ }
+ defer r.Close()
+
+ data, err := ioutil.ReadAll(r)
+ if err != nil {
+ return nil, err
+ }
+
+ err = json.Unmarshal(data, config)
+ if err != nil {
+ return nil, err
+ }
+
+ return data, nil
+}
+
func GlobalConfigForTests(ctx android.PathContext) GlobalConfig {
return GlobalConfig{
DisablePreopt: false,
diff --git a/dexpreopt/dexpreopt_gen/dexpreopt_gen.go b/dexpreopt/dexpreopt_gen/dexpreopt_gen.go
index e2818bb6..d2faa00d 100644
--- a/dexpreopt/dexpreopt_gen/dexpreopt_gen.go
+++ b/dexpreopt/dexpreopt_gen/dexpreopt_gen.go
@@ -18,7 +18,6 @@ import (
"bytes"
"flag"
"fmt"
- "io/ioutil"
"os"
"path/filepath"
"runtime"
@@ -42,6 +41,7 @@ type pathContext struct {
config android.Config
}
+func (x *pathContext) Fs() pathtools.FileSystem { return pathtools.OsFs }
func (x *pathContext) Config() android.Config { return x.config }
func (x *pathContext) AddNinjaFileDeps(...string) {}
@@ -76,39 +76,21 @@ func main() {
usage("--module configuration file is required")
}
- ctx := &pathContext{android.NullConfig(*outDir)}
+ ctx := &pathContext{android.TestConfig(*outDir, nil, "", nil)}
- globalSoongConfigData, err := ioutil.ReadFile(*globalSoongConfigPath)
- if err != nil {
- fmt.Fprintf(os.Stderr, "error reading global config %q: %s\n", *globalSoongConfigPath, err)
- os.Exit(2)
- }
-
- globalSoongConfig, err := dexpreopt.LoadGlobalSoongConfig(ctx, globalSoongConfigData)
+ globalSoongConfig, err := dexpreopt.LoadGlobalSoongConfig(ctx, *globalSoongConfigPath)
if err != nil {
fmt.Fprintf(os.Stderr, "error loading global config %q: %s\n", *globalSoongConfigPath, err)
os.Exit(2)
}
- globalConfigData, err := ioutil.ReadFile(*globalConfigPath)
- if err != nil {
- fmt.Fprintf(os.Stderr, "error reading global config %q: %s\n", *globalConfigPath, err)
- os.Exit(2)
- }
-
- globalConfig, err := dexpreopt.LoadGlobalConfig(ctx, globalConfigData, globalSoongConfig)
- if err != nil {
- fmt.Fprintf(os.Stderr, "error parse global config %q: %s\n", *globalConfigPath, err)
- os.Exit(2)
- }
-
- moduleConfigData, err := ioutil.ReadFile(*moduleConfigPath)
+ globalConfig, _, err := dexpreopt.LoadGlobalConfig(ctx, *globalConfigPath, globalSoongConfig)
if err != nil {
- fmt.Fprintf(os.Stderr, "error reading module config %q: %s\n", *moduleConfigPath, err)
+ fmt.Fprintf(os.Stderr, "error loading global config %q: %s\n", *globalConfigPath, err)
os.Exit(2)
}
- moduleConfig, err := dexpreopt.LoadModuleConfig(ctx, moduleConfigData)
+ moduleConfig, err := dexpreopt.LoadModuleConfig(ctx, *moduleConfigPath)
if err != nil {
fmt.Fprintf(os.Stderr, "error loading module config %q: %s\n", *moduleConfigPath, err)
os.Exit(2)