summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2022-03-25 17:27:39 +0300
committerOrgad Shaneh <orgad.shaneh@audiocodes.com>2022-04-05 10:22:38 +0300
commitff10b34851050a24fa7a13fa08064010c37bcd78 (patch)
treeac4376b317e97eaa0043b78ed2f790fe88ec1ee9
parenta5b5c5acacb4c0f610569f39a7d97f80535e56b2 (diff)
downloadccache-ff10b34851050a24fa7a13fa08064010c37bcd78.tar.gz
fix: Do not add redundant newlines for stdout
Tokenizer is used with include_empty, and the output typically ends with \n. For each line, tokenizer returns it without the \n, and the function appends it. But if the output ends with \n, the tokenizer returns an additional empty string, and a redundant LF is written to stdout. Another issue can be if the last line of the original output doesn't end with \n at all, ccache added it anyway. It was probably unnoticed until now since gcc has no output at all, while cl outputs the source file name.
-rw-r--r--src/ccache.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/ccache.cpp b/src/ccache.cpp
index 0b2fbd22..2598d02b 100644
--- a/src/ccache.cpp
+++ b/src/ccache.cpp
@@ -906,6 +906,9 @@ write_result(Context& ctx,
static std::string
rewrite_stdout_from_compiler(const Context& ctx, std::string&& stdout_data)
{
+ using util::Tokenizer;
+ using Mode = Tokenizer::Mode;
+ using IncludeDelimiter = Tokenizer::IncludeDelimiter;
// distcc-pump outputs lines like this:
//
// __________Using # distcc servers in pump mode
@@ -913,13 +916,12 @@ rewrite_stdout_from_compiler(const Context& ctx, std::string&& stdout_data)
// We don't want to cache those.
if (!stdout_data.empty()) {
std::string new_stdout_text;
- for (const auto line : util::Tokenizer(
- stdout_data, "\n", util::Tokenizer::Mode::include_empty)) {
+ for (const auto line : Tokenizer(
+ stdout_data, "\n", Mode::include_empty, IncludeDelimiter::yes)) {
if (util::starts_with(line, "__________")) {
Util::send_to_fd(ctx, std::string(line), STDOUT_FILENO);
} else {
new_stdout_text.append(line.data(), line.length());
- new_stdout_text.append("\n");
}
}
return new_stdout_text;