Commit 1c5ac082 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/vet/all: check platforms concurrently

Change-Id: I63e7fd7f62aa80e1252b0c5b6c472439aa66da73
Reviewed-on: https://go-review.googlesource.com/29169Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent b78108d5
...@@ -21,7 +21,9 @@ import ( ...@@ -21,7 +21,9 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strconv"
"strings" "strings"
"sync"
) )
var ( var (
...@@ -58,7 +60,7 @@ func main() { ...@@ -58,7 +60,7 @@ func main() {
vetPlatforms(allPlatforms()) vetPlatforms(allPlatforms())
default: default:
host := platform{os: build.Default.GOOS, arch: build.Default.GOARCH} host := platform{os: build.Default.GOOS, arch: build.Default.GOARCH}
host.vet() host.vet(runtime.GOMAXPROCS(-1))
} }
} }
...@@ -181,17 +183,29 @@ var ignorePathPrefixes = [...]string{ ...@@ -181,17 +183,29 @@ var ignorePathPrefixes = [...]string{
} }
func vetPlatforms(pp []platform) { func vetPlatforms(pp []platform) {
ncpus := runtime.GOMAXPROCS(-1) / len(pp)
if ncpus < 1 {
ncpus = 1
}
var wg sync.WaitGroup
wg.Add(len(pp))
for _, p := range pp { for _, p := range pp {
p.vet() p := p
go func() {
p.vet(ncpus)
wg.Done()
}()
} }
wg.Wait()
} }
func (p platform) vet() { func (p platform) vet(ncpus int) {
if p.arch == "s390x" { if p.arch == "s390x" {
// TODO: reinstate when s390x gets vet support (issue 15454) // TODO: reinstate when s390x gets vet support (issue 15454)
return return
} }
fmt.Printf("go run main.go -p %s\n", p) var buf bytes.Buffer
fmt.Fprintf(&buf, "go run main.go -p %s\n", p)
// Load whitelist(s). // Load whitelist(s).
w := make(whitelist) w := make(whitelist)
...@@ -204,7 +218,7 @@ func (p platform) vet() { ...@@ -204,7 +218,7 @@ func (p platform) vet() {
// Not installing leads to non-obvious failures due to inability to typecheck. // Not installing leads to non-obvious failures due to inability to typecheck.
// TODO: If go/loader ever makes it to the standard library, have vet use it, // TODO: If go/loader ever makes it to the standard library, have vet use it,
// at which point vet can work off source rather than compiled packages. // at which point vet can work off source rather than compiled packages.
cmd := exec.Command(cmdGoPath, "install", "std") cmd := exec.Command(cmdGoPath, "install", "-p", strconv.Itoa(ncpus), "std")
cmd.Env = env cmd.Env = env
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
...@@ -271,9 +285,9 @@ NextLine: ...@@ -271,9 +285,9 @@ NextLine:
if w[key] == 0 { if w[key] == 0 {
// Vet error with no match in the whitelist. Print it. // Vet error with no match in the whitelist. Print it.
if *flagNoLines { if *flagNoLines {
fmt.Printf("%s: %s\n", file, msg) fmt.Fprintf(&buf, "%s: %s\n", file, msg)
} else { } else {
fmt.Printf("%s:%s: %s\n", file, lineno, msg) fmt.Fprintf(&buf, "%s:%s: %s\n", file, lineno, msg)
} }
continue continue
} }
...@@ -293,15 +307,17 @@ NextLine: ...@@ -293,15 +307,17 @@ NextLine:
for k, v := range w { for k, v := range w {
if v != 0 { if v != 0 {
if !printedHeader { if !printedHeader {
fmt.Println("unmatched whitelist entries:") fmt.Fprintln(&buf, "unmatched whitelist entries:")
printedHeader = true printedHeader = true
} }
for i := 0; i < v; i++ { for i := 0; i < v; i++ {
fmt.Println(k) fmt.Fprintln(&buf, k)
} }
} }
} }
} }
os.Stdout.Write(buf.Bytes())
} }
// nbits maps from architecture names to the number of bits in a pointer. // nbits maps from architecture names to the number of bits in a pointer.
......
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