From: Russ Cox Date: Tue, 14 Nov 2017 15:57:14 +0000 (-0500) Subject: cmd/go/internal/work: do not write trivial.c when testing gcc flags X-Git-Tag: go1.10beta1~223 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=92c35824710e001b8a6b19cddf739c0b6b05306a;p=gostls13.git 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 Reviewed-by: Ian Lance Taylor --- diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 1ffa14249e..2e8c103c50 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -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 }