]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/work: do not write trivial.c when testing gcc flags
authorRuss Cox <rsc@golang.org>
Tue, 14 Nov 2017 15:57:14 +0000 (10:57 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 16 Nov 2017 17:34:32 +0000 (17:34 +0000)
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: Ian Lance Taylor <iant@golang.org>
src/cmd/go/internal/work/exec.go

index 1ffa14249ec3f378ec22d6ac8e37268e90801e4e..2e8c103c507aefa3bb1b1bd8bea36c146072a71d 100644 (file)
@@ -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
 }