]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet/all: check platforms concurrently
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 14 Sep 2016 21:10:14 +0000 (14:10 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Wed, 14 Sep 2016 21:54:17 +0000 (21:54 +0000)
Change-Id: I63e7fd7f62aa80e1252b0c5b6c472439aa66da73
Reviewed-on: https://go-review.googlesource.com/29169
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/vet/all/main.go

index 8440312f53c645325aecfd28107bfdec4f68b762..a4c43763f3970693d20fa2b7dcc36343f566310a 100644 (file)
@@ -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.