Skip to content

Commit 178307c

Browse files
committed
cmd/go: address review comments
Address review comments from earlier CLs. These are changes I was too scared to try to push down into the original CLs (thanks, Git). Change-Id: I0e428fad73d71bd2a7d08178cf2e856de3cef19f Reviewed-on: https://go-review.googlesource.com/36257 Reviewed-by: David Crawshaw <[email protected]>
1 parent 707cadd commit 178307c

File tree

20 files changed

+72
-47
lines changed

20 files changed

+72
-47
lines changed

src/cmd/dist/deps.go

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

src/cmd/go/internal/base/base.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ package base
88

99
import (
1010
"bytes"
11-
"cmd/go/internal/cfg"
12-
"cmd/go/internal/str"
1311
"errors"
1412
"flag"
1513
"fmt"
@@ -19,6 +17,9 @@ import (
1917
"os/exec"
2018
"strings"
2119
"sync"
20+
21+
"cmd/go/internal/cfg"
22+
"cmd/go/internal/str"
2223
)
2324

2425
// A Command is an implementation of a go command

src/cmd/go/internal/base/flag.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
package base
66

77
import (
8-
"cmd/go/internal/str"
98
"flag"
9+
10+
"cmd/go/internal/cfg"
11+
"cmd/go/internal/str"
1012
)
1113

1214
// A StringsFlag is a command-line flag that interprets its argument
@@ -28,6 +30,6 @@ func (v *StringsFlag) String() string {
2830

2931
// AddBuildFlagsNX adds the -n and -x build flags to the flag set.
3032
func AddBuildFlagsNX(flags *flag.FlagSet) {
31-
flags.BoolVar(&BuildN, "n", false, "")
32-
flags.BoolVar(&BuildX, "x", false, "")
33+
flags.BoolVar(&cfg.BuildN, "n", false, "")
34+
flags.BoolVar(&cfg.BuildX, "x", false, "")
3335
}

src/cmd/go/internal/base/path.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ import (
1010
"strings"
1111
)
1212

13-
var Cwd, _ = os.Getwd()
13+
func getwd() string {
14+
wd, err := os.Getwd()
15+
if err != nil {
16+
Fatalf("cannot determine current directory: %v", err)
17+
}
18+
return wd
19+
}
20+
21+
var Cwd = getwd()
1422

1523
// ShortPath returns an absolute or relative name for path, whatever is shorter.
1624
func ShortPath(path string) string {

src/cmd/go/internal/cfg/cfg.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package cfg
88

99
import (
10-
"flag"
1110
"go/build"
1211
"os"
1312
"path/filepath"
@@ -30,14 +29,18 @@ var (
3029
BuildRace bool // -race flag
3130
BuildToolexec []string // -toolexec flag
3231
BuildToolchainName string
33-
BuildToolchainCompiler string
34-
BuildToolchainLinker string
32+
BuildToolchainCompiler func() string
33+
BuildToolchainLinker func() string
3534
BuildV bool // -v flag
3635
BuildWork bool // -work flag
3736
BuildX bool // -x flag
38-
3937
)
4038

39+
func init() {
40+
BuildToolchainCompiler = func() string { return "missing-compiler" }
41+
BuildToolchainLinker = func() string { return "missing-linker" }
42+
}
43+
4144
// The test coverage mode affects package loading. Sigh.
4245
var TestCoverMode string // -covermode flag
4346

@@ -50,8 +53,10 @@ type EnvVar struct {
5053
// OrigEnv is the original environment of the program at startup.
5154
var OrigEnv []string
5255

53-
// NewEnv is the new environment for running commands.
54-
var NewEnv []EnvVar
56+
// CmdEnv is the new environment for running go tool commands.
57+
// User binaries (during go test or go run) are run with OrigEnv,
58+
// not CmdEnv.
59+
var CmdEnv []EnvVar
5560

5661
// Global build parameters (used during package load)
5762
var (
@@ -61,12 +66,6 @@ var (
6166
Gopath []string
6267
)
6368

64-
// AddBuildFlagsNX adds the -n and -x build flags to the flag set.
65-
func AddBuildFlagsNX(flags *flag.FlagSet) {
66-
flags.BoolVar(&BuildN, "n", false, "")
67-
flags.BoolVar(&BuildX, "x", false, "")
68-
}
69-
7069
var (
7170
GOROOT = filepath.Clean(runtime.GOROOT())
7271
GOBIN = os.Getenv("GOBIN")

src/cmd/go/internal/clean/clean.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
// Package clean implements the ``go clean'' command.
56
package clean
67

78
import (

src/cmd/go/internal/doc/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
// Package doc implements the ``go doc'' command.
56
package doc
67

78
import (

src/cmd/go/internal/env/env.go renamed to src/cmd/go/internal/envcmd/env.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package env
5+
// Package envcmd implements the ``go env'' command.
6+
package envcmd
67

78
import (
89
"fmt"
@@ -103,7 +104,7 @@ func ExtraEnvVars() []cfg.EnvVar {
103104
}
104105

105106
func runEnv(cmd *base.Command, args []string) {
106-
env := cfg.NewEnv
107+
env := cfg.CmdEnv
107108
env = append(env, ExtraEnvVars()...)
108109
if len(args) > 0 {
109110
for _, name := range args {

src/cmd/go/internal/fix/fix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
// Package fix implements the ``go fix'' command.
56
package fix
67

78
import (

src/cmd/go/internal/fmt/fmt.go renamed to src/cmd/go/internal/fmtcmd/fmt.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package fmt
5+
// Package fmtcmd implements the ``go fmt'' command.
6+
package fmtcmd
67

78
import (
89
"os"
@@ -15,7 +16,7 @@ import (
1516
)
1617

1718
func init() {
18-
cfg.AddBuildFlagsNX(&CmdFmt.Flag)
19+
base.AddBuildFlagsNX(&CmdFmt.Flag)
1920
}
2021

2122
var CmdFmt = &base.Command{

0 commit comments

Comments
 (0)