]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "cmd/go: fix the default build output name for versioned binaries"
authorDmitri Shuralyov <dmitshur@golang.org>
Wed, 20 Mar 2019 18:16:33 +0000 (18:16 +0000)
committerDmitri Shuralyov <dmitshur@golang.org>
Fri, 22 Mar 2019 19:22:42 +0000 (19:22 +0000)
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>
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/test/test.go
src/cmd/go/internal/work/build.go
src/cmd/go/testdata/mod/rsc.io_fortune_v2_v2.0.0.txt
src/cmd/go/testdata/script/mod_build_versioned.txt [deleted file]

index 9da01a03723278503c9cc7ce77463a464bd71adb..a0333bd5223bc970a0c3f503aa9fcac51304e217 100644 (file)
@@ -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.
index aaca8fcf68e25f0f755c6afce7577dcd9137ae4a..fe90af3be51f51c487afc58c1340f12f3fbee3b1 100644 (file)
@@ -811,7 +811,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"
 
index 82ac7d692f0e8bd3117e92808e476cbe5be1e40b..21abd5ef5bf1d3d4dccd6335f33a522769763030 100644 (file)
@@ -10,6 +10,7 @@ import (
        "go/build"
        "os"
        "os/exec"
+       "path"
        "path/filepath"
        "runtime"
        "strings"
@@ -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
        }
 
@@ -325,7 +326,8 @@ func runBuild(cmd *base.Command, args []string) {
                                if p.Name != "main" {
                                        continue
                                }
-                               p.Target = filepath.Join(cfg.BuildO, load.DefaultExecName(p))
+                               _, elem := path.Split(p.ImportPath)
+                               p.Target = filepath.Join(cfg.BuildO, elem)
                                p.Target += cfg.ExeSuffix
                                p.Stale = true
                                p.StaleReason = "build -o flag in use"
index 3acd6379311f643194e45a712464b4af4aed5fa6..cfa91f08a5d84ba07ffd96eef8580a43c455899b 100644 (file)
@@ -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) {}
diff --git a/src/cmd/go/testdata/script/mod_build_versioned.txt b/src/cmd/go/testdata/script/mod_build_versioned.txt
deleted file mode 100644 (file)
index eb081c9..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-env GO111MODULE=on
-
-go get -m rsc.io/fortune/v2
-
-# The default executable name shouldn't be v2$exe
-go build rsc.io/fortune/v2
-! exists v2$exe
-exists fortune$exe
-
-# The default test binary name shouldn't be v2.test$exe
-go test -c rsc.io/fortune/v2
-! exists v2.test$exe
-exists fortune.test$exe
-
--- go.mod --
-module scratch