Skip to content

Commit ac40903

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
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 <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gopher Robot <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent 9e0a7b1 commit ac40903

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

internal/gocommand/version.go

+4-14
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,11 @@ import (
2323
func GoVersion(ctx context.Context, inv Invocation, r *Runner) (int, error) {
2424
inv.Verb = "list"
2525
inv.Args = []string{"-e", "-f", `{{context.ReleaseTags}}`, `--`, `unsafe`}
26-
inv.Env = append(append([]string{}, inv.Env...), "GO111MODULE=off")
27-
// Unset any unneeded flags, and remove them from BuildFlags, if they're
28-
// present.
29-
inv.ModFile = ""
26+
inv.BuildFlags = nil // This is not a build command.
3027
inv.ModFlag = ""
31-
var buildFlags []string
32-
for _, flag := range inv.BuildFlags {
33-
// Flags can be prefixed by one or two dashes.
34-
f := strings.TrimPrefix(strings.TrimPrefix(flag, "-"), "-")
35-
if strings.HasPrefix(f, "mod=") || strings.HasPrefix(f, "modfile=") {
36-
continue
37-
}
38-
buildFlags = append(buildFlags, flag)
39-
}
40-
inv.BuildFlags = buildFlags
28+
inv.ModFile = ""
29+
inv.Env = append(inv.Env[:len(inv.Env):len(inv.Env)], "GO111MODULE=off")
30+
4131
stdoutBytes, err := r.Run(ctx, inv)
4232
if err != nil {
4333
return 0, err

0 commit comments

Comments
 (0)