From b53f7beb7222bf6dbadbb9d5d540acdc6d52e191 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Wed, 18 Jan 2017 14:42:09 -0800 Subject: [PATCH] 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 --- gotestrunner/gotestrunner.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gotestrunner/gotestrunner.go b/gotestrunner/gotestrunner.go index 20fbe1c..5318747 100644 --- a/gotestrunner/gotestrunner.go +++ b/gotestrunner/gotestrunner.go @@ -24,6 +24,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "syscall" ) @@ -56,12 +57,20 @@ func main() { test, err := filepath.Abs(flag.Arg(0)) 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:]...) if *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