sweet: don't send cockroachdb build output to stdout/stderr

Currently the build for CockroachDB always sends its output to
stdout/stderr, and bazel absolutely loves to produce a firehose of
output. This is very annoying when just trying to run sweet yourself.

This change captures the output instead and only dumps it on error.

Change-Id: I445731d3169d02bcdcc6e6d2ba02c0b510e9b64f
Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/613935
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
diff --git a/sweet/harnesses/cockroachdb.go b/sweet/harnesses/cockroachdb.go
index 3053791..2782bcd 100644
--- a/sweet/harnesses/cockroachdb.go
+++ b/sweet/harnesses/cockroachdb.go
@@ -6,7 +6,6 @@
 
 import (
 	"fmt"
-	"os"
 	"os/exec"
 	"path/filepath"
 	"runtime"
@@ -66,11 +65,12 @@
 	defer func() {
 		cmd := exec.Command(bazel(), "clean", "--expunge")
 		cmd.Dir = bcfg.SrcDir
-		cmd.Stdout = os.Stdout
-		cmd.Stderr = os.Stderr
 		// Cleanup is best effort, there might not be anything to clean up
 		// if we fail early enough in the build process.
-		_ = cmd.Run()
+		out, err := cmd.CombinedOutput()
+		if err != nil {
+			log.Printf("failed to run %q: %v: output:\n%s", cmd, err, out)
+		}
 	}()
 
 	// Configure the build env.
@@ -82,20 +82,16 @@
 	cmd := exec.Command(bazel(), "run", "//pkg/gen:code")
 	cmd.Dir = bcfg.SrcDir
 	cmd.Env = env.Collapse()
-	cmd.Stdout = os.Stdout
-	cmd.Stderr = os.Stderr
-	if err := cmd.Run(); err != nil {
-		return err
+	if out, err := cmd.CombinedOutput(); err != nil {
+		return fmt.Errorf("failed to run %q: %v: output:\n%s", cmd, err, out)
 	}
 
 	// Build the c-deps needed.
 	cmd = exec.Command(bazel(), "run", "//pkg/cmd/generate-cgo:generate-cgo", "--run_under", fmt.Sprintf("cd %s && ", bcfg.SrcDir))
 	cmd.Dir = bcfg.SrcDir
 	cmd.Env = env.Collapse()
-	cmd.Stdout = os.Stdout
-	cmd.Stderr = os.Stderr
-	if err := cmd.Run(); err != nil {
-		return err
+	if out, err := cmd.CombinedOutput(); err != nil {
+		return fmt.Errorf("failed to run %q: %v: output:\n%s", cmd, err, out)
 	}
 
 	// Get the Go version. Then, finall build the cockroach binary with `go build`.