]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/api: don’t rely on hardcoded go versions
authorAndrew Bonventre <andybons@golang.org>
Mon, 11 Dec 2017 21:21:07 +0000 (16:21 -0500)
committerAndrew Bonventre <andybons@golang.org>
Mon, 11 Dec 2017 22:28:37 +0000 (22:28 +0000)
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 <bradfitz@golang.org>
src/cmd/api/run.go

index eebd7b432c1f23b2936c1d253e26e85c8987a173..a36f1179c16e9839fa7f1bd417b788a27d9df6db 100644 (file)
@@ -15,6 +15,7 @@ import (
        "os/exec"
        "path/filepath"
        "runtime"
+       "strings"
 )
 
 func goCmd() string {
@@ -38,21 +39,34 @@ func main() {
                log.Fatal("No $GOROOT set.")
        }
 
+       apiDir := filepath.Join(goroot, "api")
        out, err := exec.Command(goCmd(), "tool", "api",
-               "-c", file("go1", "go1.1", "go1.2", "go1.3", "go1.4", "go1.5", "go1.6", "go1.7", "go1.8", "go1.9", "go1.10"),
-               "-next", file("next"),
-               "-except", file("except")).CombinedOutput()
+               "-c", findAPIDirFiles(apiDir),
+               "-next", filepath.Join(apiDir, "next.txt"),
+               "-except", filepath.Join(apiDir, "except.txt")).CombinedOutput()
        if err != nil {
                log.Fatalf("Error running API checker: %v\n%s", err, out)
        }
        fmt.Print(string(out))
 }
 
-// file expands s to $GOROOT/api/s.txt.
-// If there are more than 1, they're comma-separated.
-func file(s ...string) string {
-       if len(s) > 1 {
-               return file(s[0]) + "," + file(s[1:]...)
+// findAPIDirFiles returns a comma-separated list of Go API files
+// (go1.txt, go1.1.txt, etc.) located in apiDir.
+func findAPIDirFiles(apiDir string) string {
+       dir, err := os.Open(apiDir)
+       if err != nil {
+               log.Fatal(err)
+       }
+       defer dir.Close()
+       fs, err := dir.Readdirnames(-1)
+       if err != nil {
+               log.Fatal(err)
+       }
+       var apiFiles []string
+       for _, fn := range fs {
+               if strings.HasPrefix(fn, "go1") {
+                       apiFiles = append(apiFiles, filepath.Join(apiDir, fn))
+               }
        }
-       return filepath.Join(goroot, "api", s[0]+".txt")
+       return strings.Join(apiFiles, ",")
 }