diff options
| author | Hiroshi Ioka <hirochachacha@gmail.com> | 2017-09-19 18:18:09 +0900 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2017-09-20 03:54:16 +0000 |
| commit | fb54abe9ce3cbec6d464c238406b05502cb34eeb (patch) | |
| tree | 596ae2eb647e4c2b0b1d023ede6c85d5a55099b7 /src/cmd/api/goapi.go | |
| parent | 88ced021907fb96d5609a3c63db0d9738bf0ac2b (diff) | |
| download | go-fb54abe9ce3cbec6d464c238406b05502cb34eeb.tar.xz | |
all: correct location of go tool
In general, there are no guarantee that `go` command exist on $PATH.
This CL tries to get `go` command from $GOROOT/bin instead.
There are three kinds of code we should handle:
For normal code, the CL implements goCmd() or goCmdName().
For unit tests, the CL uses testenv.GoTool() or testenv.GoToolPath().
For integration tests, the CL sets PATH=$GOROOT/bin:$PATH in cmd/dist.
Note that make.bash sets PATH=$GOROOT/bin:$PATH in the build process.
So this change is only useful when we use toolchain manually.
Updates #21875
Change-Id: I963b9f22ea732dd735363ececde4cf94a5db5ca2
Reviewed-on: https://go-review.googlesource.com/64650
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd/api/goapi.go')
| -rw-r--r-- | src/cmd/api/goapi.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go index 936f9e5511..8cc78c01ed 100644 --- a/src/cmd/api/goapi.go +++ b/src/cmd/api/goapi.go @@ -27,6 +27,18 @@ import ( "strings" ) +func goCmd() string { + var exeSuffix string + if runtime.GOOS == "windows" { + exeSuffix = ".exe" + } + path := filepath.Join(runtime.GOROOT(), "bin", "go"+exeSuffix) + if _, err := os.Stat(path); err == nil { + return path + } + return "go" +} + // Flags var ( checkFile = flag.String("c", "", "optional comma-separated filename(s) to check API against") @@ -127,7 +139,7 @@ func main() { if flag.NArg() > 0 { pkgNames = flag.Args() } else { - stds, err := exec.Command("go", "list", "std").Output() + stds, err := exec.Command(goCmd(), "list", "std").Output() if err != nil { log.Fatal(err) } |
