2016-03-01 15:57:46 -07:00
|
|
|
// Copyright 2013 The Go Authors. All rights reserved.
|
2013-08-07 14:49:37 -06:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2013-08-09 16:44:00 -06:00
|
|
|
// +build ignore
|
|
|
|
|
2015-04-07 12:04:01 -06:00
|
|
|
// The run program is invoked via the dist tool.
|
|
|
|
// To invoke manually: go tool dist test -run api --no-rebuild
|
2013-08-07 14:49:37 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
2017-09-19 03:18:09 -06:00
|
|
|
"runtime"
|
2017-12-11 14:21:07 -07:00
|
|
|
"strings"
|
2013-08-07 14:49:37 -06:00
|
|
|
)
|
|
|
|
|
2017-09-19 03:18:09 -06:00
|
|
|
func goCmd() string {
|
|
|
|
var exeSuffix string
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
exeSuffix = ".exe"
|
|
|
|
}
|
|
|
|
path := filepath.Join(runtime.GOROOT(), "bin", "go"+exeSuffix)
|
|
|
|
if _, err := os.Stat(path); err == nil {
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
return "go"
|
|
|
|
}
|
|
|
|
|
2013-08-07 14:49:37 -06:00
|
|
|
var goroot string
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
log.SetFlags(0)
|
|
|
|
goroot = os.Getenv("GOROOT") // should be set by run.{bash,bat}
|
|
|
|
if goroot == "" {
|
|
|
|
log.Fatal("No $GOROOT set.")
|
|
|
|
}
|
2013-08-08 12:06:38 -06:00
|
|
|
|
2017-12-11 14:21:07 -07:00
|
|
|
apiDir := filepath.Join(goroot, "api")
|
2017-09-19 03:18:09 -06:00
|
|
|
out, err := exec.Command(goCmd(), "tool", "api",
|
2017-12-11 14:21:07 -07:00
|
|
|
"-c", findAPIDirFiles(apiDir),
|
|
|
|
"-next", filepath.Join(apiDir, "next.txt"),
|
|
|
|
"-except", filepath.Join(apiDir, "except.txt")).CombinedOutput()
|
2013-08-07 14:49:37 -06:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error running API checker: %v\n%s", err, out)
|
|
|
|
}
|
2013-08-08 14:36:22 -06:00
|
|
|
fmt.Print(string(out))
|
2013-08-07 14:49:37 -06:00
|
|
|
}
|
|
|
|
|
2017-12-11 14:21:07 -07:00
|
|
|
// 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))
|
|
|
|
}
|
2013-08-07 14:49:37 -06:00
|
|
|
}
|
2017-12-11 14:21:07 -07:00
|
|
|
return strings.Join(apiFiles, ",")
|
2013-08-07 14:49:37 -06:00
|
|
|
}
|