New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: executables are sometimes named after their module's last element, not directory #27283

Open
spenczar opened this Issue Aug 27, 2018 · 3 comments

Comments

Projects
None yet
6 participants
@spenczar
Contributor

spenczar commented Aug 27, 2018

What version of Go are you using (go version)?

go1.11

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

darwin amd64

What did you do?

In a package main's directory (specifically, github.com/twitchtv/twirp/protoc-gen-twirp), I had a go.mod like this:

module github.com/twitchtv/twirp/protoc-gen-twirp/v5

I then ran GO111MODULE=on go build . from within $GOPATH/src/github.com/twitchtv/twirp/protoc-gen-twirp.

I expected an executable named protoc-gen-twirp, because that is the last element of the directory. This is the documented behavior in https://tip.golang.org/cmd/go/#hdr-Compile_packages_and_dependencies:

When compiling a single main package, build writes the resulting executable to an output file named after the first source file ('go build ed.go rx.go' writes 'ed' or 'ed.exe') or the source code directory ('go build unix/sam' writes 'sam' or 'sam.exe').

Instead, an executable was produced named v5.

However, if I invoke go build with a full path, I get the expected name. GO111MODULE=on go build github.com/twitchtv/twirp/protoc-gen-twirp produces an executable named protoc-gen-twirp.

This is either a documentation error, or a bug.

@mvdan

This comment has been minimized.

Member

mvdan commented Aug 27, 2018

@FiloSottile FiloSottile added this to the Go1.12 milestone Aug 30, 2018

@myitcv

This comment has been minimized.

Member

myitcv commented Sep 7, 2018

Confirmed.

export GOPATH=$(mktemp -d)
cd $(mktemp -d)
mkdir hello
cd hello
go mod init example.com/hello/v6
cat <<EOD > main.go

package main

func main() {}
EOD
go build .

Now:

$ ls
go.mod  main.go  v6

But:

$ go install
$ ls $GOPATH/bin
hello

go install was fixed in #24667; sounds like a similar fix needed for go build.

@gopherbot

This comment has been minimized.

gopherbot commented Oct 10, 2018

Change https://golang.org/cl/140863 mentions this issue: cmd/go: fix the default build output name for versioned binaries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment