Skip to content
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

'govvv -flags -pkg' not working properly? #19

Open
stgarf opened this issue Mar 4, 2019 · 12 comments
Open

'govvv -flags -pkg' not working properly? #19

stgarf opened this issue Mar 4, 2019 · 12 comments

Comments

@stgarf
Copy link

stgarf commented Mar 4, 2019

I think this is similarly related to #17 and #18.

Anyways, some info on my environment (want to know anything else?):
Go version: 1.12
govvv version: 0.2.0
os/version: ubuntu bionic_18.04-like
🔢

$ govvv list ./cmd
# This outputs correctly, for reference.
github.com/stgarf/paperless-cli/cmd
$ cat ./VERSION
# For ref, this is correct and doesn't have any strange characters.
0.0.1
$ git describe --tags --dirty --always
# For reference.
fba178f

$ govvv -flags -pkg $(govvv list ./cmd) -version $(cat ./VERSION)
# The package is incorrect for the variables...
-X main.BuildDate=2019-03-04T00:34:31Z -X main.GitCommit=fba178f -X main.GitBranch=master -X main.GitState=clean -X main.GitSummary=fba178f -X main.Version=0.0.1

# Maybe bash command substitution was the problem, let's explore... notice I change the version to 0.0.2 also.
$ govvv -flags -pkg github.com/stgarf/paperless-cli/cmd -version 0.0.2
# Package is wrong and version is wrong...
-X main.GitCommit=fba178f -X main.GitBranch=master -X main.GitState=clean -X main.GitSummary=fba178f -X main.Version=0.0.1 -X main.BuildDate=2019-03-04T00:47:53Z

# Again, but 0.0.3 for giggles...
$ govvv -flags -pkg github.com/stgarf/paperless-cli/cmd -version 0.0.3
-X main.GitCommit=fba178f -X main.GitBranch=master -X main.GitState=clean -X main.GitSummary=fba178f -X main.Version=0.0.1 -X main.BuildDate=2019-03-04T00:47:58Z
# Package is wrong and version is wrong...

Am I maybe using the tool incorrectly? I'm able to pass the "proper" -ldflags and the resulting binary works as I'd expect it to...

$ ./build.sh; ./paperless-cli version; rm paperless-cli                                                    [17:48:39]
Building...
Build complete.
paperless-cli v0.1.1 built on 2019-03-04T01:48:57Z from git:68534c2-clean (master) by user@chrx

and the tests are even working correctly...

$ pwd; go test -v . -run TestGetFlags_pkgFlag
/home/user/repos/gocode/src/github.com/ahmetb/govvv
=== RUN   TestGetFlags_pkgFlag
Debugging flags: map[github.com/acct/coolproject/version.BuildDate:2019-03-04T01:54:48Z github.com/acct/coolproject/version.GitBranch:master github.com/acct/coolproject/version.GitCommit:8dbada4 github.com/acct/coolproject/version.GitState:clean github.com/acct/coolproject/version.GitSummary:8dbada4]
--- PASS: TestGetFlags_pkgFlag (0.07s)
PASS
ok  	github.com/ahmetb/govvv	0.072s

(notsure)

@ahmetb
Copy link
Owner

ahmetb commented Mar 13, 2019

This is odd. What if you build govvv with go1.12 and use the one you built? I can't really imagine what in Go 1.11 or 1.12 would be breaking this, so any help debugging is appreciated.

@stgarf
Copy link
Author

stgarf commented Mar 14, 2019

I've basically wiped govvv out and re-fetched it. Everything seems okay? I'm going to close this out but maybe it'll help someone else who encounters a similar issue..

$ rm $(which govvv)
$ which govvv
govvv not found
$ go install github.com/ahmetb/govvv
$ govvv -flags -pkg $(govvv list ./cmd)
-X github.com/stgarf/paperless-cli/cmd.BuildDate=2019-03-14T05:00:08Z -X github.com/stgarf/paperless-cli/cmd.GitCommit=1efbc57 -X github.com/stgarf/paperless-cli/cmd.GitBranch=master -X github.com/stgarf/paperless-cli/cmd.GitState=clean -X github.com/stgarf/paperless-cli/cmd.GitSummary=1efbc57 -X github.com/stgarf/paperless-cli/cmd.Version=0.6.0%
$ govvv build -pkg $(govvv list ./cmd) -print
go build \
	-ldflags \
	"-X github.com/stgarf/paperless-cli/cmd.Version=0.6.0 -X github.com/stgarf/paperless-cli/cmd.BuildDate=2019-03-14T05:00:13Z -X github.com/stgarf/paperless-cli/cmd.GitCommit=1efbc57 -X github.com/stgarf/paperless-cli/cmd.GitBranch=master -X github.com/stgarf/paperless-cli/cmd.GitState=clean -X github.com/stgarf/paperless-cli/cmd.GitSummary=1efbc57"
$ ./paperless-cli version
paperless-cli v0.6.0 built on 2019-03-14T05:02:54Z from git:1efbc57-clean (master) by user@host

@stgarf stgarf closed this as completed Mar 14, 2019
@phantomnat
Copy link

I think the problem happened when tried to install with GO111MODULE=on

@stgarf
Copy link
Author

stgarf commented Mar 21, 2019

This is very possible in my case as well 👍

@oubiwann
Copy link

oubiwann commented Mar 25, 2019

Ditto -- ran into this myself, just now.

Update: confirmed; removed the local updates to go.mod and go.sum as a result of running with GO111MODULE=on, re-ran govvv, and now it's picking up -version and -pkg again. Note that I didn't have to reinstall govvv.

@ahmetb
Copy link
Owner

ahmetb commented Mar 25, 2019

It's weird. So what should we do here? Are people not downloading the binary release and doing go-get of this repo instead to use the tool or what?

@oubiwann
Copy link

@ahmetb: Not sure what to do -- I'm new to Go :-)

If it helps, here are the make variables and targets I have that are govvv-specific:

VERSION=0.2.0-alpha1
VERSION_PACKAGE=$(shell go list ./util)
BUILD_FLAGS=$(shell govvv -flags -version $(VERSION) -pkg $(VERSION_PACKAGE))

build: bin
	GO111MODULE=on go build -o $(BINARY) -ldflags="$(BUILD_FLAGS)"

dev-deps:
	@go get github.com/ahmetb/govvv

All of my other go commands in the Makefile set the GO111MODULE=on ENV var (and in fact, in another project, I've got a make variable GO="GO111MODULE=on go"). The go get for govvv is the only one that doesn't use GO111MODULE=on, due to the issues noted in this ticket.

@oubiwann
Copy link

As a bit of sugar on top, I should mention: I love the utility and cleanliness provided by govvv :-) Super-happy with the tool and how it lets me manage a project's version (as referenced above, I'm using it in multiple projects). The problem outlined in this ticket is of very little concern to me, as the workaround seems to be performing just fine with zero ill effects.

In summary: thanks!

@tzachshabtay
Copy link

@ahmetb while there's a workaround it's still an annoying issue (govvv doesn't work with modules) which forces us to handle it differently from all other tools, so I think this should be re-opened.

@ahmetb ahmetb reopened this May 23, 2019
@lunemec
Copy link

lunemec commented Sep 5, 2019

I tested this, and it happens with project that have go modules enabled. But when you set GO111MODULE=off just for this command, it seems to work. When running with GO111MODULE=on, it breaks with the -pkg flag notice. I have not investigated more why.

@anarcher
Copy link

I think that @master works but @0.2.0 doesn't works. go get with go module tries to get with 0.2.0. :-]

@maguro
Copy link
Contributor

maguro commented Jan 30, 2020

I had a problem where the compiler was optimizing references to Version away and, instead, using the initial value. I replaced the direct reference to Version with a function that returned Version's value and that seemed to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants