github.com/goproxy0/go@v0.0.0-20171111080102-49cc0c489d2c/src/cmd/api/run.go (about) 1 // Copyright 2013 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 // +build ignore 6 7 // The run program is invoked via the dist tool. 8 // To invoke manually: go tool dist test -run api --no-rebuild 9 package main 10 11 import ( 12 "fmt" 13 "log" 14 "os" 15 "os/exec" 16 "path/filepath" 17 "runtime" 18 ) 19 20 func goCmd() string { 21 var exeSuffix string 22 if runtime.GOOS == "windows" { 23 exeSuffix = ".exe" 24 } 25 path := filepath.Join(runtime.GOROOT(), "bin", "go"+exeSuffix) 26 if _, err := os.Stat(path); err == nil { 27 return path 28 } 29 return "go" 30 } 31 32 var goroot string 33 34 func main() { 35 log.SetFlags(0) 36 goroot = os.Getenv("GOROOT") // should be set by run.{bash,bat} 37 if goroot == "" { 38 log.Fatal("No $GOROOT set.") 39 } 40 41 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"), 43 "-next", file("next"), 44 "-except", file("except")).CombinedOutput() 45 if err != nil { 46 log.Fatalf("Error running API checker: %v\n%s", err, out) 47 } 48 fmt.Print(string(out)) 49 } 50 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:]...) 56 } 57 return filepath.Join(goroot, "api", s[0]+".txt") 58 }