Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 07d85846 authored by Kousik Kumar's avatar Kousik Kumar Committed by Gerrit Code Review
Browse files

Merge "Add additional directories from which env config can be loaded"

parents 2a1291d0 7b7dca43
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -117,12 +117,23 @@ func inList(s string, list []string) bool {
	return indexList(s, list) != -1
}

func loadEnvConfig() error {
func loadEnvConfig(config build.Config) error {
	bc := os.Getenv("ANDROID_BUILD_ENVIRONMENT_CONFIG")
	if bc == "" {
		return nil
	}
	cfgFile := filepath.Join(os.Getenv("TOP"), configDir, fmt.Sprintf("%s.%s", bc, jsonSuffix))
	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 {
@@ -138,9 +149,7 @@ func loadEnvConfig() error {
		if os.Getenv(k) != "" {
			continue
		}
		if err := os.Setenv(k, v); err != nil {
			return err
		}
		config.Environment().Set(k, v)
	}
	return nil
}
@@ -207,13 +216,13 @@ func main() {
		Status:  stat,
	}}

	if err := loadEnvConfig(); err != nil {
	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)
	}

	config := c.config(buildCtx, args...)

	build.SetupOutDir(buildCtx, config)

	if config.UseBazel() && config.Dist() {