From ac40903eed81af49c4ce588dc79073970231b7d2 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 26 Apr 2023 10:35:41 -0400 Subject: [PATCH] internal/gocommand: simplify GoVersion invocation Detecting the go version does not require build flags, and should not depend on the value of GO111MODULE. For golang/go#59841. Change-Id: I74255953985e6d2ad01095eea2b6d72f7d280e3f Reviewed-on: https://go-review.googlesource.com/c/tools/+/489215 Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills Reviewed-by: Heschi Kreinick TryBot-Result: Gopher Robot gopls-CI: kokoro Reviewed-by: Alan Donovan --- internal/gocommand/version.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/internal/gocommand/version.go b/internal/gocommand/version.go index 307a76d474a..446c5846a60 100644 --- a/internal/gocommand/version.go +++ b/internal/gocommand/version.go @@ -23,21 +23,11 @@ import ( func GoVersion(ctx context.Context, inv Invocation, r *Runner) (int, error) { inv.Verb = "list" inv.Args = []string{"-e", "-f", `{{context.ReleaseTags}}`, `--`, `unsafe`} - inv.Env = append(append([]string{}, inv.Env...), "GO111MODULE=off") - // Unset any unneeded flags, and remove them from BuildFlags, if they're - // present. - inv.ModFile = "" + inv.BuildFlags = nil // This is not a build command. inv.ModFlag = "" - var buildFlags []string - for _, flag := range inv.BuildFlags { - // Flags can be prefixed by one or two dashes. - f := strings.TrimPrefix(strings.TrimPrefix(flag, "-"), "-") - if strings.HasPrefix(f, "mod=") || strings.HasPrefix(f, "modfile=") { - continue - } - buildFlags = append(buildFlags, flag) - } - inv.BuildFlags = buildFlags + inv.ModFile = "" + inv.Env = append(inv.Env[:len(inv.Env):len(inv.Env)], "GO111MODULE=off") + stdoutBytes, err := r.Run(ctx, inv) if err != nil { return 0, err