aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2016-09-14 14:10:14 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2016-09-14 21:54:17 +0000
commit1c5ac0827d2d0d2f5fb3b7f2b34b37e170beff1d (patch)
tree5e342109682fd283e6ffbe33188e86a94a125c0e /src
parentb78108d5dc198a1bb8ed294b8b974f0c0d51b55c (diff)
downloadgo-1c5ac0827d2d0d2f5fb3b7f2b34b37e170beff1d.tar.xz
cmd/vet/all: check platforms concurrently
Change-Id: I63e7fd7f62aa80e1252b0c5b6c472439aa66da73 Reviewed-on: https://go-review.googlesource.com/29169 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/vet/all/main.go34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/cmd/vet/all/main.go b/src/cmd/vet/all/main.go
index 8440312f53..a4c43763f3 100644
--- a/src/cmd/vet/all/main.go
+++ b/src/cmd/vet/all/main.go
@@ -21,7 +21,9 @@ import (
"os/exec"
"path/filepath"
"runtime"
+ "strconv"
"strings"
+ "sync"
)
var (
@@ -58,7 +60,7 @@ func main() {
vetPlatforms(allPlatforms())
default:
host := platform{os: build.Default.GOOS, arch: build.Default.GOARCH}
- host.vet()
+ host.vet(runtime.GOMAXPROCS(-1))
}
}
@@ -181,17 +183,29 @@ var ignorePathPrefixes = [...]string{
}
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 {
- 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" {
// TODO: reinstate when s390x gets vet support (issue 15454)
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).
w := make(whitelist)
@@ -204,7 +218,7 @@ func (p platform) vet() {
// 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,
// 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
out, err := cmd.CombinedOutput()
if err != nil {
@@ -271,9 +285,9 @@ NextLine:
if w[key] == 0 {
// Vet error with no match in the whitelist. Print it.
if *flagNoLines {
- fmt.Printf("%s: %s\n", file, msg)
+ fmt.Fprintf(&buf, "%s: %s\n", file, msg)
} else {
- fmt.Printf("%s:%s: %s\n", file, lineno, msg)
+ fmt.Fprintf(&buf, "%s:%s: %s\n", file, lineno, msg)
}
continue
}
@@ -293,15 +307,17 @@ NextLine:
for k, v := range w {
if v != 0 {
if !printedHeader {
- fmt.Println("unmatched whitelist entries:")
+ fmt.Fprintln(&buf, "unmatched whitelist entries:")
printedHeader = true
}
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.