]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Do not add redundant newlines for stdout 1037/head
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>
Fri, 25 Mar 2022 14:27:39 +0000 (17:27 +0300)
committerOrgad Shaneh <orgad.shaneh@audiocodes.com>
Tue, 5 Apr 2022 07:22:38 +0000 (10:22 +0300)
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.

src/ccache.cpp

index 0b2fbd22e856167302a5c609a418b3c596776e3d..2598d02bed1c93fca1777f7156dda573be6b57b7 100644 (file)
@@ -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;