Skip to content

Commit e8c45e0

Browse files
author
Bryan C. Mills
committed
go/analysis: allow overriding V flag without code patches
In CL 149609, a file was added to src/cmd/vendor/golang.org/x/tools/go/analysis/internal/analysisflags/patch.go to override the behavior of the V flag for cmd/vet. That modification causes the behavior of cmd/vet to change when a pristine copy of x/tools is vendored in, and module-mode vendoring will only support pristine copies (see golang/go#30240). Instead, allow cmd/vet to override the V flag by defining its own V flag before it invokes unitchecker.Main. Tested manually (by patching into cmd/vendor). Updates golang/go#30240 Updates golang/go#30241 Updates golang/go#26924 Updates golang/go#30228 Change-Id: I10e4523e1f4ede94fbfc745012dadeefef48e927 Reviewed-on: https://go-review.googlesource.com/c/162989 Run-TryBot: Bryan C. Mills <[email protected]> Reviewed-by: Alan Donovan <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 9394956 commit e8c45e0

File tree

1 file changed

+7
-6
lines changed
  • go/analysis/internal/analysisflags

1 file changed

+7
-6
lines changed

go/analysis/internal/analysisflags/flags.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,13 @@ func printFlags() {
152152
// addVersionFlag registers a -V flag that, if set,
153153
// prints the executable version and exits 0.
154154
//
155-
// It is a variable not a function to permit easy
156-
// overriding in the copy vendored in $GOROOT/src/cmd/vet:
157-
//
158-
// func init() { addVersionFlag = objabi.AddVersionFlag }
159-
var addVersionFlag = func() {
160-
flag.Var(versionFlag{}, "V", "print version and exit")
155+
// If the -V flag already exists — for example, because it was already
156+
// registered by a call to cmd/internal/objabi.AddVersionFlag — then
157+
// addVersionFlag does nothing.
158+
func addVersionFlag() {
159+
if flag.Lookup("V") == nil {
160+
flag.Var(versionFlag{}, "V", "print version and exit")
161+
}
161162
}
162163

163164
// versionFlag minimally complies with the -V protocol required by "go vet".

0 commit comments

Comments
 (0)