Ensure environment dependencies are correct
Store the os Environment on init, then clear it so that it's only
available via a call to Config.Getenv(). That way we're guaranteed to
know about all dependencies.
Test: Add some os.Getenv/Config.Getenv calls and ensure correct behavior
Test: cs/ shows no os.Getenv / os.LookupEnv / os.ExpandEnv calls that
would be affected
Change-Id: Ic519e0c871f340e752df03b8af0599d47c1d91d8
diff --git a/android/config.go b/android/config.go
index 8be16cf..e349336 100644
--- a/android/config.go
+++ b/android/config.go
@@ -289,7 +289,7 @@
if c.envFrozen {
panic("Cannot access new environment variables after envdeps are frozen")
}
- val = os.Getenv(key)
+ val, _ = originalEnv[key]
c.envDeps[key] = val
}
return val
diff --git a/android/env.go b/android/env.go
index c7409e8..ec5794e 100644
--- a/android/env.go
+++ b/android/env.go
@@ -15,6 +15,9 @@
package android
import (
+ "os"
+ "strings"
+
"android/soong/env"
"github.com/google/blueprint"
@@ -27,6 +30,19 @@
// compare the contents of the environment variables, rewriting the file if necessary to cause
// a manifest regeneration.
+var originalEnv map[string]string
+
+func init() {
+ originalEnv = make(map[string]string)
+ for _, env := range os.Environ() {
+ idx := strings.IndexRune(env, '=')
+ if idx != -1 {
+ originalEnv[env[:idx]] = env[idx+1:]
+ }
+ }
+ os.Clearenv()
+}
+
func EnvSingleton() blueprint.Singleton {
return &envSingleton{}
}