mirror of
https://github.com/golang/go
synced 2024-11-23 18:10:04 -07:00
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: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
62dc3c3f0d
commit
92c3582471
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user