1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 // GoVersion checks the go version by running "go list" with modules off.
14 // It returns the X in Go 1.X.
15 func GoVersion(ctx context.Context, inv Invocation, r *Runner) (int, error) {
17 inv.Args = []string{"-e", "-f", `{{context.ReleaseTags}}`}
18 inv.Env = append(append([]string{}, inv.Env...), "GO111MODULE=off")
19 // Unset any unneeded flags.
22 stdoutBytes, err := r.Run(ctx, inv)
26 stdout := stdoutBytes.String()
28 return 0, fmt.Errorf("bad ReleaseTags output: %q", stdout)
30 // Split up "[go1.1 go1.15]"
31 tags := strings.Fields(stdout[1 : len(stdout)-2])
32 for i := len(tags) - 1; i >= 0; i-- {
34 if _, err := fmt.Sscanf(tags[i], "go1.%d", &version); err != nil {
39 return 0, fmt.Errorf("no parseable ReleaseTags in %v", tags)