diff --git a/.gitignore b/.gitignore index c081fa3..76990bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.bin /release +/gobin diff --git a/main.go b/main.go index 700bab7..da90a66 100644 --- a/main.go +++ b/main.go @@ -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" diff --git a/testdata/major_version.txt b/testdata/major_version.txt new file mode 100644 index 0000000..6b16b78 --- /dev/null +++ b/testdata/major_version.txt @@ -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 .+ diff --git a/testdata/mod/example.com_good_v2_v2.0.0.txt b/testdata/mod/example.com_good_v2_v2.0.0.txt new file mode 100644 index 0000000..9d3e3a4 --- /dev/null +++ b/testdata/mod/example.com_good_v2_v2.0.0.txt @@ -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() {}