aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/work/build.go
diff options
context:
space:
mode:
authorHana Kim <hyangah@gmail.com>2019-01-14 11:13:34 -0500
committerBrad Fitzpatrick <bradfitz@golang.org>2019-03-13 20:18:44 +0000
commitbf94fc3ae387fc09929443393741919fac6727af (patch)
tree35309b175f08722e2cd5985d321b816488f0181e /src/cmd/go/internal/work/build.go
parent0a04c0430e9671bd531a2928a8416424da1e3dde (diff)
downloadgo-bf94fc3ae387fc09929443393741919fac6727af.tar.gz
go-bf94fc3ae387fc09929443393741919fac6727af.zip
cmd/go: fix the default build output name for versioned binaries
`go build` has chosen the last element of the package import path as the default output name when -o option is given. That caused the output of a package build when the module root is the major version component such as 'v2'. A similar issue involving `go install` was fixed in https://golang.org/cl/128900. This CL refactors the logic added with the change and makes it available as internal/load.DefaultExecName. This CL makes 'go test' to choose the right default test binary name when the tested package is in the module root. (E.g., instead of v2.test, choose pkg.test for the test of 'path/pkg/v2') Fixes #27283. Change-Id: I6905754f0906db46e3ce069552715f45356913ae Reviewed-on: https://go-review.googlesource.com/c/go/+/140863 Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/work/build.go')
-rw-r--r--src/cmd/go/internal/work/build.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
index 145b87513a..26234d15cc 100644
--- a/src/cmd/go/internal/work/build.go
+++ b/src/cmd/go/internal/work/build.go
@@ -10,7 +10,7 @@ import (
"go/build"
"os"
"os/exec"
- "path"
+ //"path"
"path/filepath"
"runtime"
"strings"
@@ -285,7 +285,7 @@ func runBuild(cmd *base.Command, args []string) {
pkgs := load.PackagesForBuild(args)
if len(pkgs) == 1 && pkgs[0].Name == "main" && cfg.BuildO == "" {
- _, cfg.BuildO = path.Split(pkgs[0].ImportPath)
+ cfg.BuildO = load.DefaultExecName(pkgs[0])
cfg.BuildO += cfg.ExeSuffix
}