internal/gocommand: only set working dir if it's not empty
This was causing crashes by setting the working directory to be empty.
Fixes golang/go#38062
Fixes golang/go#38101
Change-Id: I6d679ee1d5dcab914df3d565d83aa6de0dd74cb4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225817
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/internal/gocommand/invoke.go b/internal/gocommand/invoke.go
index 468db40..3e2546c 100644
--- a/internal/gocommand/invoke.go
+++ b/internal/gocommand/invoke.go
@@ -78,8 +78,11 @@
// The Go stdlib has a special feature where if the cwd and the PWD are the
// same node then it trusts the PWD, so by setting it in the env for the child
// process we fix up all the paths returned by the go command.
- cmd.Env = append(append([]string{}, i.Env...), "PWD="+i.WorkingDir)
- cmd.Dir = i.WorkingDir
+ cmd.Env = append([]string{}, i.Env...)
+ if i.WorkingDir != "" {
+ cmd.Env = append(cmd.Env, "PWD="+i.WorkingDir)
+ cmd.Dir = i.WorkingDir
+ }
defer func(start time.Time) { log("%s for %v", time.Since(start), cmdDebugStr(cmd)) }(time.Now())