Revert "Revert "Ensure environment dependencies are correct""
This reverts commit 4068a5db6c
.
Now the Mac xcode-select and xcrun goes through Config.HostSystemTool,
which will grab $PATH through Config.Getenv
Test: m -j (on mac)
Change-Id: I2632c4fdb2ec961e59944cf02ff165e0fd3c869d
This commit is contained in:
@@ -249,6 +249,20 @@ func (c *config) BlueprintToolLocation() string {
|
|||||||
return filepath.Join(c.buildDir, "host", c.PrebuiltOS(), "bin")
|
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
|
// PrebuiltOS returns the name of the host OS used in prebuilts directories
|
||||||
func (c *config) PrebuiltOS() string {
|
func (c *config) PrebuiltOS() string {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
@@ -289,7 +303,7 @@ func (c *config) Getenv(key string) string {
|
|||||||
if c.envFrozen {
|
if c.envFrozen {
|
||||||
panic("Cannot access new environment variables after envdeps are frozen")
|
panic("Cannot access new environment variables after envdeps are frozen")
|
||||||
}
|
}
|
||||||
val = os.Getenv(key)
|
val, _ = originalEnv[key]
|
||||||
c.envDeps[key] = val
|
c.envDeps[key] = val
|
||||||
}
|
}
|
||||||
return val
|
return val
|
||||||
|
@@ -15,6 +15,9 @@
|
|||||||
package android
|
package android
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"android/soong/env"
|
"android/soong/env"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
@@ -27,6 +30,19 @@ import (
|
|||||||
// compare the contents of the environment variables, rewriting the file if necessary to cause
|
// compare the contents of the environment variables, rewriting the file if necessary to cause
|
||||||
// a manifest regeneration.
|
// 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 {
|
func EnvSingleton() blueprint.Singleton {
|
||||||
return &envSingleton{}
|
return &envSingleton{}
|
||||||
}
|
}
|
||||||
|
@@ -115,7 +115,8 @@ const (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pctx.VariableFunc("macSdkPath", func(config interface{}) (string, error) {
|
pctx.VariableFunc("macSdkPath", func(config interface{}) (string, error) {
|
||||||
bytes, err := exec.Command("xcode-select", "--print-path").Output()
|
xcodeselect := config.(android.Config).HostSystemTool("xcode-select")
|
||||||
|
bytes, err := exec.Command(xcodeselect, "--print-path").Output()
|
||||||
return strings.TrimSpace(string(bytes)), err
|
return strings.TrimSpace(string(bytes)), err
|
||||||
})
|
})
|
||||||
pctx.VariableFunc("macSdkRoot", func(config interface{}) (string, error) {
|
pctx.VariableFunc("macSdkRoot", func(config interface{}) (string, error) {
|
||||||
@@ -123,18 +124,16 @@ func init() {
|
|||||||
})
|
})
|
||||||
pctx.StaticVariable("macMinVersion", "10.8")
|
pctx.StaticVariable("macMinVersion", "10.8")
|
||||||
pctx.VariableFunc("MacArPath", func(config interface{}) (string, error) {
|
pctx.VariableFunc("MacArPath", func(config interface{}) (string, error) {
|
||||||
bytes, err := exec.Command("xcrun", "--find", "ar").Output()
|
return xcrun(config.(android.Config), "--find", "ar")
|
||||||
return strings.TrimSpace(string(bytes)), err
|
|
||||||
})
|
})
|
||||||
|
|
||||||
pctx.VariableFunc("MacStripPath", func(config interface{}) (string, error) {
|
pctx.VariableFunc("MacStripPath", func(config interface{}) (string, error) {
|
||||||
bytes, err := exec.Command("xcrun", "--find", "strip").Output()
|
return xcrun(config.(android.Config), "--find", "strip")
|
||||||
return strings.TrimSpace(string(bytes)), err
|
|
||||||
})
|
})
|
||||||
|
|
||||||
pctx.VariableFunc("MacToolPath", func(config interface{}) (string, error) {
|
pctx.VariableFunc("MacToolPath", func(config interface{}) (string, error) {
|
||||||
bytes, err := exec.Command("xcrun", "--find", "ld").Output()
|
path, err := xcrun(config.(android.Config), "--find", "ld")
|
||||||
return filepath.Dir(strings.TrimSpace(string(bytes))), err
|
return filepath.Dir(path), err
|
||||||
})
|
})
|
||||||
|
|
||||||
pctx.StaticVariable("DarwinGccVersion", darwinGccVersion)
|
pctx.StaticVariable("DarwinGccVersion", darwinGccVersion)
|
||||||
@@ -162,13 +161,20 @@ func init() {
|
|||||||
pctx.StaticVariable("DarwinX8664ClangLdflags", strings.Join(darwinX8664ClangLdflags, " "))
|
pctx.StaticVariable("DarwinX8664ClangLdflags", strings.Join(darwinX8664ClangLdflags, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func xcrun(config android.Config, args ...string) (string, error) {
|
||||||
|
xcrun := config.HostSystemTool("xcrun")
|
||||||
|
bytes, err := exec.Command(xcrun, args...).Output()
|
||||||
|
return strings.TrimSpace(string(bytes)), err
|
||||||
|
}
|
||||||
|
|
||||||
func xcrunSdk(config android.Config, arg string) (string, error) {
|
func xcrunSdk(config android.Config, arg string) (string, error) {
|
||||||
|
xcrun := config.HostSystemTool("xcrun")
|
||||||
if selected := config.Getenv("MAC_SDK_VERSION"); selected != "" {
|
if selected := config.Getenv("MAC_SDK_VERSION"); selected != "" {
|
||||||
if !inList(selected, darwinSupportedSdkVersions) {
|
if !inList(selected, darwinSupportedSdkVersions) {
|
||||||
return "", fmt.Errorf("MAC_SDK_VERSION %s isn't supported: %q", selected, darwinSupportedSdkVersions)
|
return "", fmt.Errorf("MAC_SDK_VERSION %s isn't supported: %q", selected, darwinSupportedSdkVersions)
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes, err := exec.Command("xcrun", "--sdk", "macosx"+selected, arg).Output()
|
bytes, err := exec.Command(xcrun, "--sdk", "macosx"+selected, arg).Output()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return strings.TrimSpace(string(bytes)), err
|
return strings.TrimSpace(string(bytes)), err
|
||||||
}
|
}
|
||||||
@@ -176,7 +182,7 @@ func xcrunSdk(config android.Config, arg string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, sdk := range darwinSupportedSdkVersions {
|
for _, sdk := range darwinSupportedSdkVersions {
|
||||||
bytes, err := exec.Command("xcrun", "--sdk", "macosx"+sdk, arg).Output()
|
bytes, err := exec.Command(xcrun, "--sdk", "macosx"+sdk, arg).Output()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return strings.TrimSpace(string(bytes)), err
|
return strings.TrimSpace(string(bytes)), err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user