aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/load/pkg.go
diff options
context:
space:
mode:
authorDmitri Shuralyov <dmitshur@golang.org>2019-03-20 18:16:33 +0000
committerDmitri Shuralyov <dmitshur@golang.org>2019-03-22 19:22:42 +0000
commit1e83369ca002218389e81235ed96d2bb509bb779 (patch)
treebd5aeab1294e1732f0c3456a15e52346026c8546 /src/cmd/go/internal/load/pkg.go
parentd923309a17d1b7eeacc75798cdca905d5b143681 (diff)
downloadgo-1e83369ca002218389e81235ed96d2bb509bb779.tar.gz
go-1e83369ca002218389e81235ed96d2bb509bb779.zip
Revert "cmd/go: fix the default build output name for versioned binaries"
This reverts CL 140863 (commit bf94fc3ae387fc09929443393741919fac6727af). Reason for revert: There was a potential problem spotted in the original fix, which resulted in it being rolled back from release-branch.go1.12 and not included in Go 1.12.1 release. We intend to improve the fix and include it in Go 1.12.2 instead. To make the fix easier to backport, revert this change before re-applying the improved fix (next commit). Change-Id: If6c785f58482d2531b5927c5ea7002f548c21c7c Reviewed-on: https://go-review.googlesource.com/c/go/+/168402 Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Diffstat (limited to 'src/cmd/go/internal/load/pkg.go')
-rw-r--r--src/cmd/go/internal/load/pkg.go71
1 files changed, 32 insertions, 39 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index 9da01a0372..a0333bd522 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -1186,44 +1186,6 @@ var cgoSyscallExclude = map[string]bool{
var foldPath = make(map[string]string)
-// DefaultExecName returns the default executable name of the given
-// package.
-func DefaultExecName(p *Package) string {
- _, elem := filepath.Split(p.ImportPath)
- if cfg.ModulesEnabled {
- // NOTE(rsc): Using p.ImportPath instead of p.Dir
- // makes sure we install a package in the root of a
- // cached module directory as that package name
- // not name@v1.2.3.
- // Using p.ImportPath instead of p.Dir
- // is probably correct all the time,
- // even for non-module-enabled code,
- // but I'm not brave enough to change the
- // non-module behavior this late in the
- // release cycle. Maybe for Go 1.12.
- // See golang.org/issue/26869.
- _, elem = pathpkg.Split(p.ImportPath)
-
- // If this is example.com/mycmd/v2, it's more useful to install it as mycmd than as v2.
- // See golang.org/issue/24667.
- isVersion := func(v string) bool {
- if len(v) < 2 || v[0] != 'v' || v[1] < '1' || '9' < v[1] {
- return false
- }
- for i := 2; i < len(v); i++ {
- if c := v[i]; c < '0' || '9' < c {
- return false
- }
- }
- return true
- }
- if isVersion(elem) {
- _, elem = pathpkg.Split(pathpkg.Dir(p.ImportPath))
- }
- }
- return elem
-}
-
// load populates p using information from bp, err, which should
// be the result of calling build.Context.Import.
func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
@@ -1264,7 +1226,38 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
p.Error = &PackageError{Err: e}
return
}
- elem := DefaultExecName(p)
+ _, elem := filepath.Split(p.Dir)
+ if cfg.ModulesEnabled {
+ // NOTE(rsc): Using p.ImportPath instead of p.Dir
+ // makes sure we install a package in the root of a
+ // cached module directory as that package name
+ // not name@v1.2.3.
+ // Using p.ImportPath instead of p.Dir
+ // is probably correct all the time,
+ // even for non-module-enabled code,
+ // but I'm not brave enough to change the
+ // non-module behavior this late in the
+ // release cycle. Maybe for Go 1.12.
+ // See golang.org/issue/26869.
+ _, elem = pathpkg.Split(p.ImportPath)
+
+ // If this is example.com/mycmd/v2, it's more useful to install it as mycmd than as v2.
+ // See golang.org/issue/24667.
+ isVersion := func(v string) bool {
+ if len(v) < 2 || v[0] != 'v' || v[1] < '1' || '9' < v[1] {
+ return false
+ }
+ for i := 2; i < len(v); i++ {
+ if c := v[i]; c < '0' || '9' < c {
+ return false
+ }
+ }
+ return true
+ }
+ if isVersion(elem) {
+ _, elem = pathpkg.Split(pathpkg.Dir(p.ImportPath))
+ }
+ }
full := cfg.BuildContext.GOOS + "_" + cfg.BuildContext.GOARCH + "/" + elem
if cfg.BuildContext.GOOS != base.ToolGOOS || cfg.BuildContext.GOARCH != base.ToolGOARCH {
// Install cross-compiled binaries to subdirectories of bin.