Commit 92c35824 authored by Russ Cox's avatar Russ Cox

cmd/go/internal/work: do not write trivial.c when testing gcc flags

CL 61111 disabled the writing of trivial.c in -n mode, which
made -n mode at least inconsistent with regular mode in
how it was testing for flags. We think that both were getting
the same answer, so avoid creating the file in both modes
to make sure.

If this CL turns out to be wrong, then when we revert it we
should make sure that the empty file is written even in -n mode,
because this check affects the command-line flags printed
by other commands in that mode.

Change-Id: I0a050bfc148fe5a9d430a153d7816b2821277f0d
Reviewed-on: https://go-review.googlesource.com/78115
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 62dc3c3f
......@@ -1770,19 +1770,20 @@ func (b *Builder) gccSupportsFlag(compiler []string, flag string) bool {
return b
}
if b.flagCache == nil {
if cfg.BuildN || cfg.BuildX {
b.Showcmd(b.WorkDir, "touch trivial.c")
}
if !cfg.BuildN {
src := filepath.Join(b.WorkDir, "trivial.c")
if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil {
return false
}
}
b.flagCache = make(map[[2]string]bool)
}
cmdArgs := append([]string(nil), compiler...)
cmdArgs = append(cmdArgs, flag, "-c", "trivial.c")
// We used to write an empty C file, but we already look to make
// sure the error is specifically about the command-line option,
// so the file does not need to exist at all. This avoids creating a
// file in -n mode and (if -n mode must not create a file) ensures
// that -n mode matches the regular mode.
cmdArgs := str.StringList(compiler, flag, "-c", "does_not_exist.c")
if cfg.BuildN || cfg.BuildX {
b.Showcmd(b.WorkDir, "%s", joinUnambiguously(cmdArgs))
if cfg.BuildN {
return false
}
}
if cfg.BuildN || cfg.BuildX {
b.Showcmd(b.WorkDir, "%s", joinUnambiguously(cmdArgs))
if cfg.BuildN {
......@@ -1792,10 +1793,10 @@ func (b *Builder) gccSupportsFlag(compiler []string, flag string) bool {
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
cmd.Dir = b.WorkDir
cmd.Env = base.MergeEnvLists([]string{"LC_ALL=C"}, base.EnvForDir(cmd.Dir, os.Environ()))
out, err := cmd.CombinedOutput()
out, _ := cmd.CombinedOutput()
// GCC says "unrecognized command line option".
// clang says "unknown argument".
supported := err == nil && !bytes.Contains(out, []byte("unrecognized")) && !bytes.Contains(out, []byte("unknown"))
supported := !bytes.Contains(out, []byte("unrecognized")) && !bytes.Contains(out, []byte("unknown"))
b.flagCache[key] = 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