| 1 |
// Copyright 2023 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. |
| 4 |
|
| 5 |
package toolchain |
| 6 |
|
| 7 |
import ( |
| 8 |
"io/fs" |
| 9 |
"os" |
| 10 |
"path/filepath" |
| 11 |
|
| 12 |
"cmd/go/internal/gover" |
| 13 |
) |
| 14 |
|
| 15 |
// pathDirs returns the directories in the system search path. |
| 16 |
func pathDirs() []string { |
| 17 |
return filepath.SplitList(os.Getenv("path")) |
| 18 |
} |
| 19 |
|
| 20 |
// pathVersion returns the Go version implemented by the file |
| 21 |
// described by de and info in directory dir. |
| 22 |
// The analysis only uses the name itself; it does not run the program. |
| 23 |
func pathVersion(dir string, de fs.DirEntry, info fs.FileInfo) (string, bool) { |
| 24 |
v := gover.FromToolchain(de.Name()) |
| 25 |
if v == "" || info.Mode()&0111 == 0 { |
| 26 |
return "", false |
| 27 |
} |
| 28 |
return v, true |
| 29 |
} |