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

cmd/vet: document better the cmd/go flags that go vet supports #21711

anguslees opened this issue Aug 31, 2017 · 7 comments

cmd/vet: document better the cmd/go flags that go vet supports #21711

anguslees opened this issue Aug 31, 2017 · 7 comments


Copy link

@anguslees anguslees commented Aug 31, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9 linux/amd64

Does this issue reproduce with the latest release?

this is the latest release

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

GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build582418013=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I have a Makefile that (after variable expansion) runs:
go vet -ldflags="-X main.version=dev-2017-08-31T04:06:35+0000 " ./cmd/... ./utils/... ./pkg/... ./metadata/...

On 1.7, 1.8, this works. On go-1.9, this complains about -ldflags no longer being a valid option.

I note the go-1.9 release notes make a point of saying:

The vet command has been better integrated into the go tool, so go vet now supports all standard build flags while vet's own flags are now available from go vet as well as from go tool vet.

I think what I'm seeing is the exact opposite of this.

What did you expect to see?

Successful go vet output/warnings.

What did you see instead?

flag provided but not defined: -ldflags
Usage of vet:
	vet [flags] directory...
	vet [flags] files... # Must be a single package
By default, -all is set and all non-experimental checks are run.
For more information run
	go doc cmd/vet
    	enable all non-experimental checks
Copy link

@robpike robpike commented Aug 31, 2017

There is no reason whatever to pass -ldflags to vet. Just remove that flag from the call.

The documentation could be better. The "standard build flags" really refers to compile-time features such as -n, -x, and -tags. The word "build" is being misused; a better term might be "diagnostic and package-finding".

Go vet never builds, so any try build-time flags are pointless. The issue is how the go command identifies packages to pass to go tool vet.

@robpike robpike self-assigned this Aug 31, 2017
Copy link

@anguslees anguslees commented Aug 31, 2017

Ah ok. Yes, I understand that vet has no actual use for -ldflags. The change means that with 1.9 I now need to refactor into a go $cmd $(GOFLAGS) and a go vet $(GOFLAGS_FOR_VET) which makes me sad :(

Copy link

@robpike robpike commented Aug 31, 2017

I don't really understand how it ever worked before. It shouldn't have. I consider the situation to be fixed rather than broken.

Copy link

@mvdan mvdan commented Aug 31, 2017

I imagine that the flag was simply ignored before, as go vet failed to properly pass on flags: #19350

In any case, as @robpike says, it's very unlikely that the flag ever did anything useful before. The flag isn't supposed to work; vet doesn't build packages like go build. It either uses the compiled object files from go install, or it loads from source - see go vet -source.

Copy link

@ianlancetaylor ianlancetaylor commented Aug 31, 2017

Closing because it sounds like we aren't going to do anything here. Please comment if you disagree.

Copy link

@robpike robpike commented Aug 31, 2017

Reopening with a different subject. As I said earlier, the documentation could be better.

@robpike robpike reopened this Aug 31, 2017
@robpike robpike changed the title cmd/vet: no longer supports (ignores) `-ldflags` with 1.9 cmd/vet: document better the cmd/go flags that go vet supports Aug 31, 2017
Copy link

@gopherbot gopherbot commented Sep 1, 2017

Change mentions this issue: cmd/doc: document the build flags properly for vet

@gopherbot gopherbot closed this in e3f3ade Sep 1, 2017
@golang golang locked and limited conversation to collaborators Sep 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.