Skip to content

Commit 4312390

Browse files
committed
cmd/api: don’t rely on hardcoded go versions
Instead of requiring that cmd/api/run.go be edited upon each release to include the next Go version number, look in $GOROOT/api for files with the prefix go1* and use those instead to perform API checks. Change-Id: I5d9407f2bd368ff5e62f487cccdd245641ca9c9b Reviewed-on: https://go-review.googlesource.com/83355 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 2fb9fe4 commit 4312390

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/cmd/api/run.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"os/exec"
1616
"path/filepath"
1717
"runtime"
18+
"strings"
1819
)
1920

2021
func goCmd() string {
@@ -38,21 +39,34 @@ func main() {
3839
log.Fatal("No $GOROOT set.")
3940
}
4041

42+
apiDir := filepath.Join(goroot, "api")
4143
out, err := exec.Command(goCmd(), "tool", "api",
42-
"-c", file("go1", "go1.1", "go1.2", "go1.3", "go1.4", "go1.5", "go1.6", "go1.7", "go1.8", "go1.9", "go1.10"),
43-
"-next", file("next"),
44-
"-except", file("except")).CombinedOutput()
44+
"-c", findAPIDirFiles(apiDir),
45+
"-next", filepath.Join(apiDir, "next.txt"),
46+
"-except", filepath.Join(apiDir, "except.txt")).CombinedOutput()
4547
if err != nil {
4648
log.Fatalf("Error running API checker: %v\n%s", err, out)
4749
}
4850
fmt.Print(string(out))
4951
}
5052

51-
// file expands s to $GOROOT/api/s.txt.
52-
// If there are more than 1, they're comma-separated.
53-
func file(s ...string) string {
54-
if len(s) > 1 {
55-
return file(s[0]) + "," + file(s[1:]...)
53+
// findAPIDirFiles returns a comma-separated list of Go API files
54+
// (go1.txt, go1.1.txt, etc.) located in apiDir.
55+
func findAPIDirFiles(apiDir string) string {
56+
dir, err := os.Open(apiDir)
57+
if err != nil {
58+
log.Fatal(err)
59+
}
60+
defer dir.Close()
61+
fs, err := dir.Readdirnames(-1)
62+
if err != nil {
63+
log.Fatal(err)
64+
}
65+
var apiFiles []string
66+
for _, fn := range fs {
67+
if strings.HasPrefix(fn, "go1") {
68+
apiFiles = append(apiFiles, filepath.Join(apiDir, fn))
69+
}
5670
}
57-
return filepath.Join(goroot, "api", s[0]+".txt")
71+
return strings.Join(apiFiles, ",")
5872
}

0 commit comments

Comments
 (0)