From: Orgad Shaneh Date: Fri, 25 Mar 2022 14:27:39 +0000 (+0300) Subject: fix: Do not add redundant newlines for stdout X-Git-Tag: v4.6.1~42^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F1037%2Fhead;p=thirdparty%2Fccache.git 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. --- diff --git a/src/ccache.cpp b/src/ccache.cpp index 0b2fbd22e..2598d02be 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;