Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Commit

Permalink
main: correctly determine binary name in case path ends with major ve…
Browse files Browse the repository at this point in the history
…rsion (#70)
  • Loading branch information
joefitzgerald authored and myitcv committed Mar 21, 2019
1 parent b3a85f0 commit f3d42eb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/.bin
/release
/gobin
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,12 @@ func mainerr() error {
}

gobin := filepath.Join(gobinCache, mainrel)
target := filepath.Join(gobin, path.Base(mp.ImportPath))
pref, _, ok := module.SplitPathVersion(mp.ImportPath)
if !ok {
return fmt.Errorf("failed to derive non-version prefix from %v", mp.ImportPath)
}
base := path.Base(pref)
target := filepath.Join(gobin, base)

if runtime.GOOS == "windows" {
target += ".exe"
Expand Down
7 changes: 7 additions & 0 deletions testdata/major_version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# A test to ensure that where a major version (>=2) exists
# at the end of the main package path that we end up with
# the right binary name

gobin -p example.com/good/v2
stdout [/\\]good$exe$
! stderr .+
13 changes: 13 additions & 0 deletions testdata/mod/example.com_good_v2_v2.0.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- .mod --
module example.com/good/v2

-- .info --
{"Version":"v2.0.0","Time":"2018-10-22T18:45:39Z"}

-- go.mod --
module example.com/good/v2

-- main.go --
package main

func main() {}

0 comments on commit f3d42eb

Please sign in to comment.