1
0
mirror of https://github.com/golang/go synced 2024-11-19 17:44:43 -07:00

cmd/go: ignore stderr from tool version checks

There are multiple valid reasons a tool might print to stderr.
As long as we get the expected output on stdout, that's fine.

Fixes #22588.

Change-Id: I9c5d32da08288cb26dd575530a8257cd5f375367
Reviewed-on: https://go-review.googlesource.com/76017
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Russ Cox 2017-11-05 16:31:24 -05:00
parent eca28cc4f3
commit 5e48d2b62a
2 changed files with 22 additions and 4 deletions

View File

@ -4740,6 +4740,21 @@ func TestBuildCache(t *testing.T) {
tg.grepStderr(`[\\/]link|gccgo`, "did not run linker")
}
func TestIssue22588(t *testing.T) {
// Don't get confused by stderr coming from tools.
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
if _, err := os.Stat("/usr/bin/time"); err != nil {
t.Skip(err)
}
tg.run("list", "-f={{.Stale}}", "runtime")
tg.run("list", "-toolexec=/usr/bin/time", "-f={{.Stale}}", "runtime")
tg.grepStdout("false", "incorrectly reported runtime as stale")
}
func TestIssue22531(t *testing.T) {
if strings.Contains(os.Getenv("GODEBUG"), "gocacheverify") {
t.Skip("GODEBUG gocacheverify")

View File

@ -5,6 +5,7 @@
package work
import (
"bytes"
"fmt"
"os"
"os/exec"
@ -175,12 +176,14 @@ func (b *Builder) toolID(name string) string {
cmdline := str.StringList(cfg.BuildToolexec, base.Tool(name), "-V=full")
cmd := exec.Command(cmdline[0], cmdline[1:]...)
cmd.Env = base.EnvForDir(cmd.Dir, os.Environ())
out, err := cmd.CombinedOutput()
if err != nil {
base.Fatalf("go tool %s: %v\n%s", name, err, out)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
base.Fatalf("go tool %s: %v\n%s%s", name, err, stdout.Bytes(), stderr.Bytes())
}
line := string(out)
line := stdout.String()
f := strings.Fields(line)
if len(f) < 3 || f[0] != name || f[1] != "version" || f[2] == "devel" && !strings.HasPrefix(f[len(f)-1], "buildID=") {
base.Fatalf("go tool %s -V=full: unexpected output:\n\t%s", name, line)