Commit d48336b7 authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/go: tweak support options test for old compilers

Fixes #22787

Change-Id: Ie0f3995e4bb611ee5927345b17b0d5b381a5ed74
Reviewed-on: https://go-review.googlesource.com/78543
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 12e2933b
...@@ -1759,18 +1759,13 @@ func (b *Builder) gccSupportsFlag(compiler []string, flag string) bool { ...@@ -1759,18 +1759,13 @@ func (b *Builder) gccSupportsFlag(compiler []string, flag string) bool {
if b.flagCache == nil { if b.flagCache == nil {
b.flagCache = make(map[[2]string]bool) b.flagCache = make(map[[2]string]bool)
} }
// We used to write an empty C file, but we already look to make // We used to write an empty C file, but that gets complicated with
// sure the error is specifically about the command-line option, // go build -n. We tried using a file that does not exist, but that
// so the file does not need to exist at all. This avoids creating a // fails on systems with GCC version 4.2.1; that is the last GPLv2
// file in -n mode and (if -n mode must not create a file) ensures // version of GCC, so some systems have frozen on it.
// that -n mode matches the regular mode. // Now we pass an empty file on stdin, which should work at least for
cmdArgs := str.StringList(compiler, flag, "-c", "does_not_exist.c") // GCC and clang.
if cfg.BuildN || cfg.BuildX { cmdArgs := str.StringList(compiler, flag, "-c", "-x", "c", "-")
b.Showcmd(b.WorkDir, "%s", joinUnambiguously(cmdArgs))
if cfg.BuildN {
return false
}
}
if cfg.BuildN || cfg.BuildX { if cfg.BuildN || cfg.BuildX {
b.Showcmd(b.WorkDir, "%s", joinUnambiguously(cmdArgs)) b.Showcmd(b.WorkDir, "%s", joinUnambiguously(cmdArgs))
if cfg.BuildN { if cfg.BuildN {
...@@ -1783,7 +1778,10 @@ func (b *Builder) gccSupportsFlag(compiler []string, flag string) bool { ...@@ -1783,7 +1778,10 @@ func (b *Builder) gccSupportsFlag(compiler []string, flag string) bool {
out, _ := cmd.CombinedOutput() out, _ := cmd.CombinedOutput()
// GCC says "unrecognized command line option". // GCC says "unrecognized command line option".
// clang says "unknown argument". // clang says "unknown argument".
supported := !bytes.Contains(out, []byte("unrecognized")) && !bytes.Contains(out, []byte("unknown")) // Older versions of GCC say "unrecognised debug output level".
supported := !bytes.Contains(out, []byte("unrecognized")) &&
!bytes.Contains(out, []byte("unknown")) &&
!bytes.Contains(out, []byte("unrecognised"))
b.flagCache[key] = supported b.flagCache[key] = supported
return supported return supported
} }
......
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