What version of Go are you using (go version)?
$ go version
go version go1.21.0 linux/amd64
Does this issue reproduce with the latest release?
Yes.
What did you do?
What did you expect to see?
I expected the go command to reject the -gcflags flag because it makes no sense for that subcommand.
What did you see instead?
It quietly succeeded.
Many of the go subcommands are sensitive not just to which packages match the package pattern, but the specific set of source files selected for a build configuration. These call work.AddBuildFlags to register the flags that affect source selection, but this function also registers many flags that only affect actual compilation and linking.
- The
clean command is sensitive to source file selection because it finds all source files in the a package that have a correspondingly named binary in the directory (but are not part of package main) to delete the binaries.
- The
fix command uses work.AddBuildFlags, but appears not to be sensitive to any build flags, because it uses pkg.InternalAllGoFiles() to list source files, which should returns all source files regardless of source file selection.
- The
generate command only searches for go:generate directives in matched source files.
The full set of build flags makes sense for build, install, get, run, test, vet, and list because they all build source files (vet and list -export both invoke the toolchain to create up-to-date export files).
cc @bcmills
What version of Go are you using (
go version)?Does this issue reproduce with the latest release?
Yes.
What did you do?
What did you expect to see?
I expected the
gocommand to reject the-gcflagsflag because it makes no sense for that subcommand.What did you see instead?
It quietly succeeded.
Many of the
gosubcommands are sensitive not just to which packages match the package pattern, but the specific set of source files selected for a build configuration. These callwork.AddBuildFlagsto register the flags that affect source selection, but this function also registers many flags that only affect actual compilation and linking.cleancommand is sensitive to source file selection because it finds all source files in the a package that have a correspondingly named binary in the directory (but are not part of package main) to delete the binaries.fixcommand useswork.AddBuildFlags, but appears not to be sensitive to any build flags, because it usespkg.InternalAllGoFiles()to list source files, which should returns all source files regardless of source file selection.generatecommand only searches forgo:generatedirectives in matched source files.The full set of build flags makes sense for
build,install,get,run,test,vet, andlistbecause they all build source files (vetandlist -exportboth invoke the toolchain to create up-to-date export files).cc @bcmills