return out
}
+// envForDir returns a copy of the environment
+// suitable for running in the given directory.
+// The environment is the current process's environment
+// but with an updated $PWD, so that an os.Getwd in the
+// child will be faster.
+func envForDir(dir string) []string {
+ env := os.Environ()
+ for i, kv := range env {
+ if strings.HasPrefix(kv, "PWD=") {
+ env[i] = "PWD=" + dir
+ return env
+ }
+ }
+ // Internally we only use rooted paths, so dir is rooted.
+ // Even if dir is not rooted, no harm done.
+ env = append(env, "PWD="+dir)
+ return env
+}
+
// matchPattern(pattern)(name) reports whether
// name matches pattern. Pattern is a limited glob
// pattern in which '...' means 'any string' and there
cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = a.p.Dir
+ cmd.Env = envForDir(cmd.Dir)
var buf bytes.Buffer
if testStreamOutput {
cmd.Stdout = os.Stdout
// If there are any local SWIG dependencies, we want to load
// the shared library from the build directory.
if a.p.usesSwig() {
- env := os.Environ()
+ env := cmd.Env
found := false
prefix := "LD_LIBRARY_PATH="
for i, v := range env {
cmd := exec.Command(v.cmd, args...)
cmd.Dir = dir
+ cmd.Env = envForDir(cmd.Dir)
if buildX {
fmt.Printf("cd %s\n", dir)
fmt.Printf("%s %s\n", v.cmd, strings.Join(args, " "))