Skip to content

Commit

Permalink
Revert "[release-branch.go1.12] cmd/go: fix the default build output …
Browse files Browse the repository at this point in the history
…name for versioned binaries"

This reverts commit 746edd4 (CL 167384).

Reason for revert: Dmitri identified a potential problem in https://go-review.googlesource.com/c/go/+/140863/11#message-db0ff6bb2c7b06161ca47de771c4465afa8b1102, and we'd like more time to investigate without holding up the 1.12 release branch.

Updates #27283
Updates #30266
Updates #30821

Change-Id: I49d7bbbe200e80b81899c3bcbf7844717af010aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/167617
Reviewed-by: Andrew Bonventre <andybons@golang.org>
  • Loading branch information
Bryan C. Mills committed Mar 14, 2019
1 parent 35ddc14 commit 32355f5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 63 deletions.
71 changes: 32 additions & 39 deletions src/cmd/go/internal/load/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1178,44 +1178,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) {
Expand Down Expand Up @@ -1256,7 +1218,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.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ func builderTest(b *work.Builder, p *load.Package) (buildAction, runAction, prin
if p.ImportPath == "command-line-arguments" {
elem = p.Name
} else {
elem = load.DefaultExecName(p)
_, elem = path.Split(p.ImportPath)
}
testBinary := elem + ".test"

Expand Down
3 changes: 2 additions & 1 deletion src/cmd/go/internal/work/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"go/build"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
Expand Down Expand Up @@ -284,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 = load.DefaultExecName(pkgs[0])
_, cfg.BuildO = path.Split(pkgs[0].ImportPath)
cfg.BuildO += cfg.ExeSuffix
}

Expand Down
6 changes: 0 additions & 6 deletions src/cmd/go/testdata/mod/rsc.io_fortune_v2_v2.0.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,3 @@ import "rsc.io/quote"
func main() {
println(quote.Hello())
}
-- fortune_test.go --
package main

import "testing"

func TestFortuneV2(t *testing.T) {}
16 changes: 0 additions & 16 deletions src/cmd/go/testdata/script/mod_build_versioned.txt

This file was deleted.

0 comments on commit 32355f5

Please sign in to comment.