Merge "Move env var config loading to be within the config package."

This commit is contained in:
Kousik Kumar
2022-01-31 04:40:50 +00:00
committed by Gerrit Code Review
2 changed files with 51 additions and 49 deletions

View File

@@ -16,7 +16,6 @@ package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
@@ -36,11 +35,6 @@ import (
"android/soong/ui/tracer"
)
const (
configDir = "vendor/google/tools/soong_config"
jsonSuffix = "json"
)
// A command represents an operation to be executed in the soong build
// system.
type command struct {
@@ -117,43 +111,6 @@ func inList(s string, list []string) bool {
return indexList(s, list) != -1
}
func loadEnvConfig(config build.Config) error {
bc := os.Getenv("ANDROID_BUILD_ENVIRONMENT_CONFIG")
if bc == "" {
return nil
}
configDirs := []string{
os.Getenv("ANDROID_BUILD_ENVIRONMENT_CONFIG_DIR"),
config.OutDir(),
configDir,
}
var cfgFile string
for _, dir := range configDirs {
cfgFile = filepath.Join(os.Getenv("TOP"), dir, fmt.Sprintf("%s.%s", bc, jsonSuffix))
if _, err := os.Stat(cfgFile); err == nil {
break
}
}
envVarsJSON, err := ioutil.ReadFile(cfgFile)
if err != nil {
fmt.Fprintf(os.Stderr, "\033[33mWARNING:\033[0m failed to open config file %s: %s\n", cfgFile, err.Error())
return nil
}
var envVars map[string]map[string]string
if err := json.Unmarshal(envVarsJSON, &envVars); err != nil {
return fmt.Errorf("env vars config file: %s did not parse correctly: %s", cfgFile, err.Error())
}
for k, v := range envVars["env"] {
if os.Getenv(k) != "" {
continue
}
config.Environment().Set(k, v)
}
return nil
}
// Main execution of soong_ui. The command format is as follows:
//
// soong_ui <command> [<arg 1> <arg 2> ... <arg n>]
@@ -218,11 +175,6 @@ func main() {
config := c.config(buildCtx, args...)
if err := loadEnvConfig(config); err != nil {
fmt.Fprintf(os.Stderr, "failed to parse env config files: %v", err)
os.Exit(1)
}
build.SetupOutDir(buildCtx, config)
if config.UseBazel() && config.Dist() {