Commit 178307c3 authored by Russ Cox's avatar Russ Cox

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/36257Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
parent 707cadd7
This diff is collapsed.
......@@ -8,8 +8,6 @@ package base
import (
"bytes"
"cmd/go/internal/cfg"
"cmd/go/internal/str"
"errors"
"flag"
"fmt"
......@@ -19,6 +17,9 @@ import (
"os/exec"
"strings"
"sync"
"cmd/go/internal/cfg"
"cmd/go/internal/str"
)
// A Command is an implementation of a go command
......
......@@ -5,8 +5,10 @@
package base
import (
"cmd/go/internal/str"
"flag"
"cmd/go/internal/cfg"
"cmd/go/internal/str"
)
// A StringsFlag is a command-line flag that interprets its argument
......@@ -28,6 +30,6 @@ func (v *StringsFlag) String() string {
// AddBuildFlagsNX adds the -n and -x build flags to the flag set.
func AddBuildFlagsNX(flags *flag.FlagSet) {
flags.BoolVar(&BuildN, "n", false, "")
flags.BoolVar(&BuildX, "x", false, "")
flags.BoolVar(&cfg.BuildN, "n", false, "")
flags.BoolVar(&cfg.BuildX, "x", false, "")
}
......@@ -10,7 +10,15 @@ import (
"strings"
)
var Cwd, _ = os.Getwd()
func getwd() string {
wd, err := os.Getwd()
if err != nil {
Fatalf("cannot determine current directory: %v", err)
}
return wd
}
var Cwd = getwd()
// ShortPath returns an absolute or relative name for path, whatever is shorter.
func ShortPath(path string) string {
......
......@@ -7,7 +7,6 @@
package cfg
import (
"flag"
"go/build"
"os"
"path/filepath"
......@@ -30,14 +29,18 @@ var (
BuildRace bool // -race flag
BuildToolexec []string // -toolexec flag
BuildToolchainName string
BuildToolchainCompiler string
BuildToolchainLinker string
BuildToolchainCompiler func() string
BuildToolchainLinker func() string
BuildV bool // -v flag
BuildWork bool // -work flag
BuildX bool // -x flag
)
func init() {
BuildToolchainCompiler = func() string { return "missing-compiler" }
BuildToolchainLinker = func() string { return "missing-linker" }
}
// The test coverage mode affects package loading. Sigh.
var TestCoverMode string // -covermode flag
......@@ -50,8 +53,10 @@ type EnvVar struct {
// OrigEnv is the original environment of the program at startup.
var OrigEnv []string
// NewEnv is the new environment for running commands.
var NewEnv []EnvVar
// CmdEnv is the new environment for running go tool commands.
// User binaries (during go test or go run) are run with OrigEnv,
// not CmdEnv.
var CmdEnv []EnvVar
// Global build parameters (used during package load)
var (
......@@ -61,12 +66,6 @@ var (
Gopath []string
)
// AddBuildFlagsNX adds the -n and -x build flags to the flag set.
func AddBuildFlagsNX(flags *flag.FlagSet) {
flags.BoolVar(&BuildN, "n", false, "")
flags.BoolVar(&BuildX, "x", false, "")
}
var (
GOROOT = filepath.Clean(runtime.GOROOT())
GOBIN = os.Getenv("GOBIN")
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package clean implements the ``go clean'' command.
package clean
import (
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package doc implements the ``go doc'' command.
package doc
import (
......
......@@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package env
// Package envcmd implements the ``go env'' command.
package envcmd
import (
"fmt"
......@@ -103,7 +104,7 @@ func ExtraEnvVars() []cfg.EnvVar {
}
func runEnv(cmd *base.Command, args []string) {
env := cfg.NewEnv
env := cfg.CmdEnv
env = append(env, ExtraEnvVars()...)
if len(args) > 0 {
for _, name := range args {
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package fix implements the ``go fix'' command.
package fix
import (
......
......@@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fmt
// Package fmtcmd implements the ``go fmt'' command.
package fmtcmd
import (
"os"
......@@ -15,7 +16,7 @@ import (
)
func init() {
cfg.AddBuildFlagsNX(&CmdFmt.Flag)
base.AddBuildFlagsNX(&CmdFmt.Flag)
}
var CmdFmt = &base.Command{
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package generate implements the ``go generate'' command.
package generate
import (
......
......@@ -2,17 +2,17 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package help implements "go help".
// Package help implements the ``go help'' command.
package help
import (
"bufio"
"bytes"
"fmt"
"html/template"
"io"
"os"
"strings"
"text/template"
"unicode"
"unicode/utf8"
......
......@@ -2,19 +2,21 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package list implements the ``go list'' command.
package list
import (
"bufio"
"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/load"
"cmd/go/internal/work"
"encoding/json"
"io"
"os"
"strings"
"text/template"
"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/load"
"cmd/go/internal/work"
)
var CmdList = &base.Command{
......
......@@ -883,7 +883,7 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) *Package
p.Internal.Target = filepath.Join(cfg.GOROOTpkg, "tool", full)
}
if p.Internal.Target != "" && cfg.BuildContext.GOOS == "windows" {
p.Internal.Target += ".Internal.Exe"
p.Internal.Target += ".exe"
}
} else if p.Internal.Local {
// Local import turned into absolute path.
......@@ -1562,10 +1562,10 @@ func isStale(p *Package) (bool, string) {
// Excluding $GOROOT used to also fix issue 4106, but that's now
// taken care of above (at least when the installed Go is a released version).
if p.Root != cfg.GOROOT {
if olderThan(cfg.BuildToolchainCompiler) {
if olderThan(cfg.BuildToolchainCompiler()) {
return true, "newer compiler"
}
if p.Internal.Build.IsCommand() && olderThan(cfg.BuildToolchainLinker) {
if p.Internal.Build.IsCommand() && olderThan(cfg.BuildToolchainLinker()) {
return true, "newer linker"
}
}
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package run implements the ``go run'' command.
package run
import (
......@@ -66,7 +67,7 @@ func runRun(cmd *base.Command, args []string) {
}
for _, file := range files {
if strings.HasSuffix(file, "_test.go") {
// goFilesPackage is going to assign this to TestGoFiles.
// GoFilesPackage is going to assign this to TestGoFiles.
// Reject since it won't be part of the build.
base.Fatalf("go run: cannot run *_test.go files (%s)", file)
}
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package tool implements the ``go tool'' command.
package tool
import (
......
......@@ -2,12 +2,14 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package version implements the ``go version'' command.
package version
import (
"cmd/go/internal/base"
"fmt"
"runtime"
"cmd/go/internal/base"
)
var CmdVersion = &base.Command{
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package vet implements the ``go vet'' command.
package vet
import (
......
......@@ -180,8 +180,8 @@ func (c buildCompiler) Set(value string) error {
return fmt.Errorf("unknown compiler %q", value)
}
cfg.BuildToolchainName = value
cfg.BuildToolchainCompiler = BuildToolchain.compiler()
cfg.BuildToolchainLinker = BuildToolchain.linker()
cfg.BuildToolchainCompiler = BuildToolchain.compiler
cfg.BuildToolchainLinker = BuildToolchain.linker
cfg.BuildContext.Compiler = value
return nil
}
......@@ -1317,9 +1317,11 @@ func (b *Builder) build(a *Action) (err error) {
sfiles = nil
}
cgoExe := base.Tool("cgo")
var cgoExe string
if a.cgo != nil && a.cgo.Target != "" {
cgoExe = a.cgo.Target
} else {
cgoExe = base.Tool("cgo")
}
outGo, outObj, err := b.cgo(a, cgoExe, obj, pcCFLAGS, pcLDFLAGS, cgofiles, objdirCgofiles, gccfiles, cxxfiles, a.Package.MFiles, a.Package.FFiles)
if err != nil {
......
......@@ -20,9 +20,9 @@ import (
"cmd/go/internal/cfg"
"cmd/go/internal/clean"
"cmd/go/internal/doc"
"cmd/go/internal/env"
"cmd/go/internal/envcmd"
"cmd/go/internal/fix"
fmtcmd "cmd/go/internal/fmt"
"cmd/go/internal/fmtcmd"
"cmd/go/internal/generate"
"cmd/go/internal/get"
"cmd/go/internal/help"
......@@ -40,7 +40,7 @@ func init() {
work.CmdBuild,
clean.CmdClean,
doc.CmdDoc,
env.CmdEnv,
envcmd.CmdEnv,
bug.CmdBug,
fix.CmdFix,
fmtcmd.CmdFmt,
......@@ -114,8 +114,8 @@ func main() {
// but in practice there might be skew
// This makes sure we all agree.
cfg.OrigEnv = os.Environ()
cfg.NewEnv = env.MkEnv()
for _, env := range cfg.NewEnv {
cfg.CmdEnv = envcmd.MkEnv()
for _, env := range cfg.CmdEnv {
if os.Getenv(env.Name) != env.Value {
os.Setenv(env.Name, env.Value)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment