Skip to content

Commit

Permalink
internal/gocommand: fix environment on Windows
Browse files Browse the repository at this point in the history
Seems like os.Environ() is necessary after all. My bad for not testing
my earlier change on Windows. I'm not able to reproduce the behavior
in my test, so it's not really testing the crash correctly.

Fixes golang/go#38062

Change-Id: Ied45bbf572023a9dcd5d020db49bf3e95c824602
Reviewed-on: https://go-review.googlesource.com/c/tools/+/226370
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
  • Loading branch information
stamblerre committed Mar 30, 2020
1 parent 31583a0 commit f8bfb4e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/gocommand/invoke.go
@@ -1,3 +1,7 @@
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package gocommand is a helper for calling the go command.
package gocommand

Expand Down Expand Up @@ -78,7 +82,7 @@ func (i *Invocation) RunPiped(ctx context.Context, stdout, stderr io.Writer) err
// 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([]string{}, append(i.Env, cmd.Env...)...)
cmd.Env = append(os.Environ(), i.Env...)
if i.WorkingDir != "" {
cmd.Env = append(cmd.Env, "PWD="+i.WorkingDir)
cmd.Dir = i.WorkingDir
Expand Down
21 changes: 21 additions & 0 deletions internal/gocommand/invoke_test.go
@@ -0,0 +1,21 @@
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gocommand_test

import (
"context"
"testing"

"golang.org/x/tools/internal/gocommand"
)

func TestGoVersion(t *testing.T) {
inv := gocommand.Invocation{
Verb: "version",
}
if _, err := inv.Run(context.Background()); err != nil {
t.Error(err)
}
}

0 comments on commit f8bfb4e

Please sign in to comment.