]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Don’t collapse empty lines in Depfile::rewrite_paths
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 5 Jul 2021 17:08:04 +0000 (19:08 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 5 Jul 2021 17:08:04 +0000 (19:08 +0200)
src/Depfile.cpp
unittest/test_Depfile.cpp

index ec49f4418bde9008d9aa77a164b0c1f0f24d129b..7afe044944d65e92187b890d67510d00b619980a 100644 (file)
@@ -71,10 +71,11 @@ rewrite_paths(const Context& ctx, const std::string& file_content)
   adjusted_file_content.reserve(file_content.size());
 
   bool content_rewritten = false;
-  for (const auto& line : Util::split_into_views(file_content, "\n")) {
+  for (const auto line : util::Tokenizer(
+         file_content, "\n", util::Tokenizer::Mode::skip_last_empty)) {
     const auto tokens = Util::split_into_views(line, " \t");
     for (size_t i = 0; i < tokens.size(); ++i) {
-      DEBUG_ASSERT(line.length() > 0); // line.empty() -> no tokens
+      DEBUG_ASSERT(!line.empty()); // line.empty() -> no tokens
       if (i > 0 || line[0] == ' ' || line[0] == '\t') {
         adjusted_file_content.push_back(' ');
       }
index b098800b41ba6246b1363287d97f876baa9c443c..c4f7e3530291151699a4d2b56010cd09925a3380 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -45,9 +45,10 @@ TEST_CASE("Depfile::rewrite_paths")
   const auto cwd = ctx.actual_cwd;
   ctx.has_absolute_include_headers = true;
 
-  const auto content = FMT("foo.o: bar.c {0}/bar.h \\\n {1}/fie.h {0}/fum.h\n",
-                           cwd,
-                           Util::dir_name(cwd));
+  const auto content =
+    FMT("foo.o: bar.c {0}/bar.h \\\n\n {1}/fie.h {0}/fum.h\n",
+        cwd,
+        Util::dir_name(cwd));
 
   SUBCASE("Base directory not in dep file content")
   {
@@ -67,8 +68,8 @@ TEST_CASE("Depfile::rewrite_paths")
   {
     ctx.config.set_base_dir(cwd);
     const auto actual = Depfile::rewrite_paths(ctx, content);
-    const auto expected =
-      FMT("foo.o: bar.c ./bar.h \\\n {}/fie.h ./fum.h\n", Util::dir_name(cwd));
+    const auto expected = FMT("foo.o: bar.c ./bar.h \\\n\n {}/fie.h ./fum.h\n",
+                              Util::dir_name(cwd));
     REQUIRE(actual);
     CHECK(*actual == expected);
   }