gotestrunner: Make GOROOT absolute before chdir
If GOROOT is a relative path (like it is in Android), then changing directories to run the test will cause GOROOT to become invalid. So make it absolute if we're going to change to a different directory. This allows tests to use the go tools without searching for a valid go installation. Change-Id: Ifab0a8533d236054ccf363dfb68b12e0bf66f6f8
This commit is contained in:
parent
10e4357dbb
commit
b53f7beb72
1 changed files with 10 additions and 1 deletions
|
@ -24,6 +24,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -56,12 +57,20 @@ func main() {
|
||||||
|
|
||||||
test, err := filepath.Abs(flag.Arg(0))
|
test, err := filepath.Abs(flag.Arg(0))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error: Failed to locate test binary: %s", err)
|
fmt.Fprintln(os.Stderr, "error: Failed to locate test binary:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command(test, flag.Args()[1:]...)
|
cmd := exec.Command(test, flag.Args()[1:]...)
|
||||||
if *chdir != "" {
|
if *chdir != "" {
|
||||||
cmd.Dir = *chdir
|
cmd.Dir = *chdir
|
||||||
|
|
||||||
|
// GOROOT is commonly a relative path in Android, make it
|
||||||
|
// absolute if we're changing directories.
|
||||||
|
if absRoot, err := filepath.Abs(runtime.GOROOT()); err == nil {
|
||||||
|
os.Setenv("GOROOT", absRoot)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintln(os.Stderr, "error: Failed to locate GOROOT:", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
Loading…
Reference in a new issue