golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.3k stars 611 forks source link

allow version flag to work when built with goroleaser #389

Closed codyoss closed 4 years ago

codyoss commented 4 years ago

Actual behavior A clear and concise description of what the bug is.

When building locally unable to retrieve a version. This makes it hard should we want to publish pre-built binaries.

git clone https://github.com/golang/mock.git
go build ./...
.mockgen/mockgen -version` outputs `(devlel)

Expected behavior A clear and concise description of what you expected to happen.

mockgen -version outputs version info.

minicuts commented 4 years ago

@codyoss what are the commands that you use to get mockgen? This is what I get:

nguyenfilip@nguyenfilip:~$ GO111MODULE=on go get github.com/golang/mock/mockgen@latest
go: finding github.com/golang/mock v1.4.0
go: downloading github.com/golang/mock v1.4.0
go: extracting github.com/golang/mock v1.4.0
nguyenfilip@nguyenfilip:~$ mockgen -version
v1.4.0

My go version:

nguyenfilip@nguyenfilip:~$ go version
go version go1.13.4 linux/amd64
codyoss commented 4 years ago

Sorry, you are right that does work. The use case I ran into was for us publishing prebuilt binaries. Updated initial steps. Thoughts?

minicuts commented 4 years ago

What are the steps that you use to prebuild binaries? I will check if we can build in a way that it includes the module info. As a sidenote: As I mentioned in the description of #362, the best way to support prebuilt binaries would be to combine the current approach with build flags (-ldflags). Note that the build flags approach is useful only for prebuild binaries. It would not help at all when running go get - which is what most of our users seem to be doing.

codyoss commented 4 years ago

Good point on the ldflags. That would work fine. I will using goreleaser to make the binaries. That does allow for custom flags to be sent through. goreleaser release --skip-publish --skip-validate --rm-dist is the command I used locally to do a dry run that builds the binaries. Note there is a small bug in the config right now I noticed when I was playing with it last night. If we could just update that to pass the proper flags though I think that is good enough.

minicuts commented 4 years ago

@codyoss I will check the goroleaser. It would be nice if we mitigated a need for build flags