Commit 5e48d2b6 authored by Russ Cox's avatar Russ Cox

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: 's avatarDavid Crawshaw <crawshaw@golang.org>
parent eca28cc4
...@@ -4740,6 +4740,21 @@ func TestBuildCache(t *testing.T) { ...@@ -4740,6 +4740,21 @@ func TestBuildCache(t *testing.T) {
tg.grepStderr(`[\\/]link|gccgo`, "did not run linker") 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) { func TestIssue22531(t *testing.T) {
if strings.Contains(os.Getenv("GODEBUG"), "gocacheverify") { if strings.Contains(os.Getenv("GODEBUG"), "gocacheverify") {
t.Skip("GODEBUG gocacheverify") t.Skip("GODEBUG gocacheverify")
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package work package work
import ( import (
"bytes"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
...@@ -175,12 +176,14 @@ func (b *Builder) toolID(name string) string { ...@@ -175,12 +176,14 @@ func (b *Builder) toolID(name string) string {
cmdline := str.StringList(cfg.BuildToolexec, base.Tool(name), "-V=full") cmdline := str.StringList(cfg.BuildToolexec, base.Tool(name), "-V=full")
cmd := exec.Command(cmdline[0], cmdline[1:]...) cmd := exec.Command(cmdline[0], cmdline[1:]...)
cmd.Env = base.EnvForDir(cmd.Dir, os.Environ()) cmd.Env = base.EnvForDir(cmd.Dir, os.Environ())
out, err := cmd.CombinedOutput() var stdout, stderr bytes.Buffer
if err != nil { cmd.Stdout = &stdout
base.Fatalf("go tool %s: %v\n%s", name, err, out) 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) f := strings.Fields(line)
if len(f) < 3 || f[0] != name || f[1] != "version" || f[2] == "devel" && !strings.HasPrefix(f[len(f)-1], "buildID=") { 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) base.Fatalf("go tool %s -V=full: unexpected output:\n\t%s", name, line)
......
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