Skip to content

Commit d99ff03

Browse files
author
Bryan C. Mills
committed
go/build: set PWD for go subcommands
Since these commands already include an explicit Env field, they will not be fixed automatically by proposal #50599. Change-Id: Ia8157a71cf0cfe208bdc0da9aef54be3d26c795f Reviewed-on: https://go-review.googlesource.com/c/go/+/391804 Trust: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Trust: Daniel Martí <[email protected]>
1 parent 471d319 commit d99ff03

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/go/build/build.go

+7
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,13 @@ func (ctxt *Context) importGo(p *Package, path, srcDir string, mode ImportMode)
11861186
"GOPATH="+ctxt.GOPATH,
11871187
"CGO_ENABLED="+cgo,
11881188
)
1189+
if cmd.Dir != "" {
1190+
// If possible, set PWD: if an error occurs and PWD includes a symlink, we
1191+
// want the error to refer to Dir, not some other name for it.
1192+
if abs, err := filepath.Abs(cmd.Dir); err == nil {
1193+
cmd.Env = append(cmd.Env, "PWD="+abs)
1194+
}
1195+
}
11891196

11901197
if err := cmd.Run(); err != nil {
11911198
return fmt.Errorf("go/build: go list %s: %v\n%s\n", path, err, stderr.String())

0 commit comments

Comments
 (0)