1
0
mirror of https://github.com/golang/go synced 2024-11-08 08:26:10 -07:00
go/src/cmd/api/run.go

59 lines
1.3 KiB
Go
Raw Normal View History

// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
// The run program is invoked via the dist tool.
// To invoke manually: go tool dist test -run api --no-rebuild
package main
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
)
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"
}
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.")
}
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()
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:]...)
}
return filepath.Join(goroot, "api", s[0]+".txt")
}