summaryrefslogtreecommitdiffstats
path: root/src/build.cc
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2012-01-19 00:09:16 (GMT)
committerNico Weber <thakis@chromium.org>2012-01-19 00:09:16 (GMT)
commita2c4b6780dcf105821e4f2ec1f0b591adbeb6dca (patch)
treea62348131d053354b7d8d5fb1c3ca5b3d5527d67 /src/build.cc
parent63013b3bd5ca79d454a95a6f985d98f16f21da1c (diff)
downloadNinja-a2c4b6780dcf105821e4f2ec1f0b591adbeb6dca.zip
Ninja-a2c4b6780dcf105821e4f2ec1f0b591adbeb6dca.tar.gz
Ninja-a2c4b6780dcf105821e4f2ec1f0b591adbeb6dca.tar.bz2
Strip ansi escape sequences from subcommand output when not writing to a smart terminal.
Diffstat (limited to 'src/build.cc')
-rw-r--r--src/build.cc22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/build.cc b/src/build.cc
index 94c9d77..8d0abce 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -133,8 +133,26 @@ void BuildStatus::BuildEdgeFinished(Edge* edge,
if (!success)
printf("FAILED: %s\n", edge->EvaluateCommand().c_str());
- if (!output.empty())
- printf("%s", output.c_str());
+ // ninja sets stdout and stderr of subprocesses to a pipe, to be able to
+ // check if the output is empty. Some compilers, e.g. clang, check
+ // isatty(stderr) to decide if they should print colored output.
+ // To make it possible to use colored output with ninja, subprocesses should
+ // be run with a flag that forces them to always print color escape codes.
+ // To make sure these escape codes don't show up in a file if ninja's output
+ // is piped to a file, ninja strips ansi escape codes again if it's not
+ // writing to a |smart_terminal_|.
+ // (Launching subprocesses in pseudo ttys doesn't work because there are
+ // only a few hundred available on some systems, and ninja can launch
+ // thousands of parallel compile commands.)
+ // TODO: There should be a flag to disable escape code stripping.
+ string final_output;
+ if (!smart_terminal_)
+ final_output = StripAnsiEscapeCodes(output);
+ else
+ final_output = output;
+
+ if (!final_output.empty())
+ printf("%s", final_output.c_str());
}
}