From: Joel Rosdahl Date: Mon, 5 Jul 2021 17:08:04 +0000 (+0200) Subject: Don’t collapse empty lines in Depfile::rewrite_paths X-Git-Tag: v4.4~157 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=89dcb43c28651ae672f4662100fdd841c71c2446;p=thirdparty%2Fccache.git Don’t collapse empty lines in Depfile::rewrite_paths --- diff --git a/src/Depfile.cpp b/src/Depfile.cpp index ec49f4418..7afe04494 100644 --- a/src/Depfile.cpp +++ b/src/Depfile.cpp @@ -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(' '); } diff --git a/unittest/test_Depfile.cpp b/unittest/test_Depfile.cpp index b098800b4..c4f7e3530 100644 --- a/unittest/test_Depfile.cpp +++ b/unittest/test_Depfile.cpp @@ -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); }