Merge "Revert "Revert "Ensure environment dependencies are correct"""

This commit is contained in:
Treehugger Robot
2017-05-16 00:25:07 +00:00
committed by Gerrit Code Review
3 changed files with 46 additions and 10 deletions

View File

@@ -249,6 +249,20 @@ func (c *config) BlueprintToolLocation() string {
return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin")
}
// HostSystemTool looks for non-hermetic tools from the system we're running on.
// Generally shouldn't be used, but useful to find the XCode SDK, etc.
func (c *config) HostSystemTool(name string) string {
for _, dir := range filepath.SplitList(c.Getenv("PATH")) {
path := filepath.Join(dir, name)
if s, err := os.Stat(path); err != nil {
continue
} else if m := s.Mode(); !s.IsDir() && m&0111 != 0 {
return path
}
}
return name
}
// PrebuiltOS returns the name of the host OS used in prebuilts directories
func (c *config) PrebuiltOS() string {
switch runtime.GOOS {
@@ -289,7 +303,7 @@ func (c *config) Getenv(key string) string {
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

View File

@@ -15,6 +15,9 @@
package android
import (
"os"
"strings"
"android/soong/env"
"github.com/google/blueprint"
@@ -27,6 +30,19 @@ import (
// 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{}
}