Commit 43123903 authored by Andrew Bonventre's avatar Andrew Bonventre

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/83355Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 2fb9fe48
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings"
) )
func goCmd() string { func goCmd() string {
...@@ -38,21 +39,34 @@ func main() { ...@@ -38,21 +39,34 @@ func main() {
log.Fatal("No $GOROOT set.") log.Fatal("No $GOROOT set.")
} }
apiDir := filepath.Join(goroot, "api")
out, err := exec.Command(goCmd(), "tool", "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"), "-c", findAPIDirFiles(apiDir),
"-next", file("next"), "-next", filepath.Join(apiDir, "next.txt"),
"-except", file("except")).CombinedOutput() "-except", filepath.Join(apiDir, "except.txt")).CombinedOutput()
if err != nil { if err != nil {
log.Fatalf("Error running API checker: %v\n%s", err, out) log.Fatalf("Error running API checker: %v\n%s", err, out)
} }
fmt.Print(string(out)) fmt.Print(string(out))
} }
// file expands s to $GOROOT/api/s.txt. // findAPIDirFiles returns a comma-separated list of Go API files
// If there are more than 1, they're comma-separated. // (go1.txt, go1.1.txt, etc.) located in apiDir.
func file(s ...string) string { func findAPIDirFiles(apiDir string) string {
if len(s) > 1 { dir, err := os.Open(apiDir)
return file(s[0]) + "," + file(s[1:]...) 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, ",")
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment