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

Closed
anguslees opened this issue Aug 31, 2017 · 7 comments
Closed

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

anguslees opened this issue Aug 31, 2017 · 7 comments

Comments

@anguslees
Copy link

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)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/travis/gopath"
GORACE=""
GOROOT="/home/travis/.gimme/versions/go1.9.linux.amd64"
GOTOOLDIR="/home/travis/.gimme/versions/go1.9.linux.amd64/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build582418013=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

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
Flags:
  -all
    	enable all non-experimental checks
  -asmdecl
  ...
@robpike
Copy link
Contributor

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
@anguslees
Copy link
Author

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 :(

@robpike
Copy link
Contributor

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.

@mvdan
Copy link
Member

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.

@ianlancetaylor
Copy link
Contributor

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

@robpike
Copy link
Contributor

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
@gopherbot
Copy link

Change https://golang.org/cl/60830 mentions this issue: cmd/doc: document the build flags properly for vet

@golang golang locked and limited conversation to collaborators Sep 1, 2018
@rsc rsc unassigned robpike Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants