compiler/msgs: Default to stderr for diagnostics
Previously we were defaulting to stdout for diagnostics, which could interfere with scripts or `nim c -r' programs outputting their results to stdout, possibly mixing their output with compiler messages. This change makes now Nim to be inline with other compilers emitting diagnostics to stderr. Also now --stdout option has proper meaning making all diagnostics to be sent to stdout instead. NOTE: Tester now calls compiler with --stdout.
This commit is contained in:
parent
2bc6acc808
commit
abb82554b7
2 changed files with 23 additions and 18 deletions
|
|
@ -734,20 +734,22 @@ proc outWriteln*(s: string) =
|
||||||
flushFile(stdout)
|
flushFile(stdout)
|
||||||
|
|
||||||
proc msgWriteln*(s: string) =
|
proc msgWriteln*(s: string) =
|
||||||
## Writes to stdout. If --stdout option is given, writes to stderr instead.
|
## Writes to stderr. If --stdout option is given, writes to stdout instead.
|
||||||
|
|
||||||
#if gCmd == cmdIdeTools and optCDebug notin gGlobalOptions: return
|
#if gCmd == cmdIdeTools and optCDebug notin gGlobalOptions: return
|
||||||
|
|
||||||
if not isNil(writelnHook):
|
if not isNil(writelnHook):
|
||||||
writelnHook(s)
|
writelnHook(s)
|
||||||
elif optStdout in gGlobalOptions:
|
elif optStdout in gGlobalOptions:
|
||||||
if eStdErr in errorOutputs:
|
|
||||||
writeLine(stderr, s)
|
|
||||||
flushFile(stderr)
|
|
||||||
else:
|
|
||||||
if eStdOut in errorOutputs:
|
if eStdOut in errorOutputs:
|
||||||
writeLine(stdout, s)
|
writeLine(stdout, s)
|
||||||
flushFile(stdout)
|
flushFile(stdout)
|
||||||
|
else:
|
||||||
|
if eStdErr in errorOutputs:
|
||||||
|
writeLine(stderr, s)
|
||||||
|
# On Windows stderr is fully-buffered when piped, regardless of C std.
|
||||||
|
when defined(windows):
|
||||||
|
flushFile(stderr)
|
||||||
|
|
||||||
macro callIgnoringStyle(theProc: typed, first: typed,
|
macro callIgnoringStyle(theProc: typed, first: typed,
|
||||||
args: varargs[expr]): stmt =
|
args: varargs[expr]): stmt =
|
||||||
|
|
@ -767,8 +769,9 @@ macro callIgnoringStyle(theProc: typed, first: typed,
|
||||||
typ != typTerminalCmd:
|
typ != typTerminalCmd:
|
||||||
result.add(arg)
|
result.add(arg)
|
||||||
|
|
||||||
macro callStyledEcho(args: varargs[expr]): stmt =
|
macro callStyledWriteLineStderr(args: varargs[expr]): stmt =
|
||||||
result = newCall(bindSym"styledEcho")
|
result = newCall(bindSym"styledWriteLine")
|
||||||
|
result.add(bindSym"stderr")
|
||||||
for arg in children(args[0][1]):
|
for arg in children(args[0][1]):
|
||||||
result.add(arg)
|
result.add(arg)
|
||||||
|
|
||||||
|
|
@ -782,16 +785,18 @@ template styledMsgWriteln*(args: varargs[expr]) =
|
||||||
if not isNil(writelnHook):
|
if not isNil(writelnHook):
|
||||||
callIgnoringStyle(callWritelnHook, nil, args)
|
callIgnoringStyle(callWritelnHook, nil, args)
|
||||||
elif optStdout in gGlobalOptions:
|
elif optStdout in gGlobalOptions:
|
||||||
if eStdErr in errorOutputs:
|
|
||||||
callIgnoringStyle(writeLine, stderr, args)
|
|
||||||
flushFile(stderr)
|
|
||||||
else:
|
|
||||||
if eStdOut in errorOutputs:
|
if eStdOut in errorOutputs:
|
||||||
if optUseColors in gGlobalOptions:
|
|
||||||
callStyledEcho(args)
|
|
||||||
else:
|
|
||||||
callIgnoringStyle(writeLine, stdout, args)
|
callIgnoringStyle(writeLine, stdout, args)
|
||||||
flushFile stdout
|
flushFile(stdout)
|
||||||
|
else:
|
||||||
|
if eStdErr in errorOutputs:
|
||||||
|
if optUseColors in gGlobalOptions:
|
||||||
|
callStyledWriteLineStderr(args)
|
||||||
|
else:
|
||||||
|
callIgnoringStyle(writeLine, stderr, args)
|
||||||
|
# On Windows stderr is fully-buffered when piped, regardless of C std.
|
||||||
|
when defined(windows):
|
||||||
|
flushFile(stderr)
|
||||||
|
|
||||||
proc coordToStr(coord: int): string =
|
proc coordToStr(coord: int): string =
|
||||||
if coord == -1: result = "???"
|
if coord == -1: result = "???"
|
||||||
|
|
@ -885,8 +890,7 @@ proc rawMessage*(msg: TMsgKind, arg: string) =
|
||||||
|
|
||||||
proc resetAttributes* =
|
proc resetAttributes* =
|
||||||
if {optUseColors, optStdout} * gGlobalOptions == {optUseColors}:
|
if {optUseColors, optStdout} * gGlobalOptions == {optUseColors}:
|
||||||
terminal.resetAttributes()
|
terminal.resetAttributes(stderr)
|
||||||
stdout.flushFile()
|
|
||||||
|
|
||||||
proc writeSurroundingSrc(info: TLineInfo) =
|
proc writeSurroundingSrc(info: TLineInfo) =
|
||||||
const indent = " "
|
const indent = " "
|
||||||
|
|
@ -1032,5 +1036,5 @@ proc listHints*() =
|
||||||
])
|
])
|
||||||
|
|
||||||
# enable colors by default on terminals
|
# enable colors by default on terminals
|
||||||
if terminal.isatty(stdout):
|
if terminal.isatty(stderr):
|
||||||
incl(gGlobalOptions, optUseColors)
|
incl(gGlobalOptions, optUseColors)
|
||||||
|
|
|
||||||
|
|
@ -292,7 +292,8 @@ proc testSpec(r: var TResults, test: TTest) =
|
||||||
case expected.action
|
case expected.action
|
||||||
of actionCompile:
|
of actionCompile:
|
||||||
var given = callCompiler(expected.cmd, test.name,
|
var given = callCompiler(expected.cmd, test.name,
|
||||||
test.options & " --hint[Path]:off --hint[Processing]:off", test.target)
|
test.options & " --stdout --hint[Path]:off --hint[Processing]:off",
|
||||||
|
test.target)
|
||||||
compilerOutputTests(test, given, expected, r)
|
compilerOutputTests(test, given, expected, r)
|
||||||
of actionRun, actionRunNoSpec:
|
of actionRun, actionRunNoSpec:
|
||||||
# In this branch of code "early return" pattern is clearer than deep
|
# In this branch of code "early return" pattern is clearer than deep
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue