diff options
author | Adam Strzelecki <adam.strzelecki@pl.abb.com> | 2015-10-13 13:49:34 +0200 |
---|---|---|
committer | Adam Strzelecki <adam.strzelecki@pl.abb.com> | 2015-10-16 20:55:17 +0200 |
commit | abb82554b7e9fce4073e6c072174b0ecb8a92d2f (patch) | |
tree | 014c5940e9750d7c712c3dc420f2a54d4ff0ed67 /compiler | |
parent | 2bc6acc808f18de3910b7db12014c394dd400b39 (diff) | |
download | Nim-abb82554b7e9fce4073e6c072174b0ecb8a92d2f.tar.gz |
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.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/msgs.nim | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 4dd134177..3fabf6bbf 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -734,20 +734,22 @@ proc outWriteln*(s: string) = flushFile(stdout) 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 not isNil(writelnHook): writelnHook(s) elif optStdout in gGlobalOptions: - if eStdErr in errorOutputs: - writeLine(stderr, s) - flushFile(stderr) - else: if eStdOut in errorOutputs: writeLine(stdout, s) 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, args: varargs[expr]): stmt = @@ -767,8 +769,9 @@ macro callIgnoringStyle(theProc: typed, first: typed, typ != typTerminalCmd: result.add(arg) -macro callStyledEcho(args: varargs[expr]): stmt = - result = newCall(bindSym"styledEcho") +macro callStyledWriteLineStderr(args: varargs[expr]): stmt = + result = newCall(bindSym"styledWriteLine") + result.add(bindSym"stderr") for arg in children(args[0][1]): result.add(arg) @@ -782,16 +785,18 @@ template styledMsgWriteln*(args: varargs[expr]) = if not isNil(writelnHook): callIgnoringStyle(callWritelnHook, nil, args) elif optStdout in gGlobalOptions: - if eStdErr in errorOutputs: - callIgnoringStyle(writeLine, stderr, args) - flushFile(stderr) - else: if eStdOut in errorOutputs: + callIgnoringStyle(writeLine, stdout, args) + flushFile(stdout) + else: + if eStdErr in errorOutputs: if optUseColors in gGlobalOptions: - callStyledEcho(args) + callStyledWriteLineStderr(args) else: - callIgnoringStyle(writeLine, stdout, args) - flushFile stdout + 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 = if coord == -1: result = "???" @@ -885,8 +890,7 @@ proc rawMessage*(msg: TMsgKind, arg: string) = proc resetAttributes* = if {optUseColors, optStdout} * gGlobalOptions == {optUseColors}: - terminal.resetAttributes() - stdout.flushFile() + terminal.resetAttributes(stderr) proc writeSurroundingSrc(info: TLineInfo) = const indent = " " @@ -1032,5 +1036,5 @@ proc listHints*() = ]) # enable colors by default on terminals -if terminal.isatty(stdout): +if terminal.isatty(stderr): incl(gGlobalOptions, optUseColors) |