]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Rename ShowIncludesParser to MsvcShowIncludesOutput
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 15 Oct 2022 18:26:18 +0000 (20:26 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 16 Oct 2022 08:50:09 +0000 (10:50 +0200)
I think that this is more in line with what the namespace represents. I
also renamed ShowIncludesParser::tokenize to
MsvcShowIncludesOutput::get_includes since it's not returning generic
tokens but specifically includes files.

src/ccache.cpp
src/core/CMakeLists.txt
src/core/MsvcShowIncludesOutput.cpp [moved from src/core/ShowIncludesParser.cpp with 92% similarity]
src/core/MsvcShowIncludesOutput.hpp [moved from src/core/ShowIncludesParser.hpp with 81% similarity]
src/core/ResultRetriever.cpp
unittest/CMakeLists.txt
unittest/test_core_MsvcShowIncludesOutput.cpp [moved from unittest/test_core_ShowIncludesParser.cpp with 79% similarity]

index f3333365bd739761e0774e27a58f4d142f21dcc0..3086856711e1d9dfc0b0a585c3d98782802e43e0 100644 (file)
@@ -44,9 +44,9 @@
 #include <AtomicFile.hpp>
 #include <core/CacheEntry.hpp>
 #include <core/Manifest.hpp>
+#include <core/MsvcShowIncludesOutput.hpp>
 #include <core/Result.hpp>
 #include <core/ResultRetriever.hpp>
-#include <core/ShowIncludesParser.hpp>
 #include <core/Statistics.hpp>
 #include <core/StatsLog.hpp>
 #include <core/exceptions.hpp>
@@ -698,7 +698,7 @@ struct DoExecuteResult
 static std::optional<Digest>
 result_key_from_includes(Context& ctx, Hash& hash, std::string_view stdout_data)
 {
-  for (std::string_view token : core::ShowIncludesParser::tokenize(
+  for (std::string_view token : core::MsvcShowIncludesOutput::get_includes(
          stdout_data, ctx.config.msvc_dep_prefix())) {
     const std::string path = Util::make_relative_path(ctx, token);
     remember_include_file(ctx, path, hash, false, &hash);
@@ -1076,7 +1076,7 @@ to_cache(Context& ctx,
       ctx, util::to_string_view(result->stderr_data), STDERR_FILENO);
     Util::send_to_fd(
       ctx,
-      util::to_string_view(core::ShowIncludesParser::strip_includes(
+      util::to_string_view(core::MsvcShowIncludesOutput::strip_includes(
         ctx, std::move(result->stdout_data))),
       STDOUT_FILENO);
 
@@ -1138,7 +1138,7 @@ to_cache(Context& ctx,
   // Send stdout after stderr, it makes the output clearer with MSVC.
   Util::send_to_fd(
     ctx,
-    util::to_string_view(core::ShowIncludesParser::strip_includes(
+    util::to_string_view(core::MsvcShowIncludesOutput::strip_includes(
       ctx, std::move(result->stdout_data))),
     STDOUT_FILENO);
 
index 1fa9f7073f5defcbf46140e394b8a5b230cb3d6c..c664dda5390c8020881513da69e61efebeadd3fd 100644 (file)
@@ -6,7 +6,7 @@ set(
   ResultExtractor.cpp
   ResultInspector.cpp
   ResultRetriever.cpp
-  ShowIncludesParser.cpp
+  MsvcShowIncludesOutput.cpp
   Statistics.cpp
   StatisticsCounters.cpp
   StatsLog.cpp
similarity index 92%
rename from src/core/ShowIncludesParser.cpp
rename to src/core/MsvcShowIncludesOutput.cpp
index f05521eb95dd43799be5fb69cca661dca9684950..5289eadc6f65dae82bdf2694f0116e1a461df4b9 100644 (file)
 // this program; if not, write to the Free Software Foundation, Inc., 51
 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
-#include "ShowIncludesParser.hpp"
+#include "MsvcShowIncludesOutput.hpp"
 
 #include <Context.hpp>
 #include <Util.hpp>
 #include <util/string.hpp>
 
-namespace core::ShowIncludesParser {
+namespace core::MsvcShowIncludesOutput {
 
 std::vector<std::string_view>
-tokenize(std::string_view file_content, std::string_view prefix)
+get_includes(std::string_view file_content, std::string_view prefix)
 {
   // /showIncludes output is written to stdout together with other messages.
   // Every line of it is "<prefix> <spaces> <file>" where the prefix is "Note:
@@ -73,4 +73,4 @@ strip_includes(const Context& ctx, util::Bytes&& stdout_data)
   return util::Bytes(new_stdout_text.data(), new_stdout_text.size());
 }
 
-} // namespace core::ShowIncludesParser
+} // namespace core::MsvcShowIncludesOutput
similarity index 81%
rename from src/core/ShowIncludesParser.hpp
rename to src/core/MsvcShowIncludesOutput.hpp
index a368d62b814b4537e8c1bbd3ac1bccc5c833f00a..97c59c06132ef49935086f5389f9a211fb1c3c4f 100644 (file)
 
 class Context;
 
-namespace core::ShowIncludesParser {
+namespace core::MsvcShowIncludesOutput {
 
-std::vector<std::string_view> tokenize(std::string_view file_content,
-                                       std::string_view prefix);
+std::vector<std::string_view> get_includes(std::string_view file_content,
+                                           std::string_view prefix);
 
 util::Bytes strip_includes(const Context& ctx, util::Bytes&& stdout_data);
 
-} // namespace core::ShowIncludesParser
+} // namespace core::MsvcShowIncludesOutput
index 484e1632a61a902ab556d4efd0f262de3f206c02..0aecc17d1b256158dc9a52d807ffb7775cb48bad 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <Context.hpp>
 #include <Stat.hpp>
-#include <core/ShowIncludesParser.hpp>
+#include <core/MsvcShowIncludesOutput.hpp>
 #include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 #include <fmtmacros.hpp>
@@ -64,7 +64,7 @@ ResultRetriever::on_embedded_file(uint8_t file_number,
   if (file_type == FileType::stdout_output) {
     Util::send_to_fd(
       m_ctx,
-      util::to_string_view(ShowIncludesParser::strip_includes(m_ctx, data)),
+      util::to_string_view(MsvcShowIncludesOutput::strip_includes(m_ctx, data)),
       STDOUT_FILENO);
   } else if (file_type == FileType::stderr_output) {
     Util::send_to_fd(m_ctx, util::to_string_view(data), STDERR_FILENO);
index e0ec8b3251e541d0bb47d376f18fe008135ccfeb..d6e57da32db8c25ba0ac365931b6494c027ba04b 100644 (file)
@@ -13,7 +13,7 @@ set(
   test_ccache.cpp
   test_compopt.cpp
   test_compression_types.cpp
-  test_core_ShowIncludesParser.cpp
+  test_core_MsvcShowIncludesOutput.cpp
   test_core_Statistics.cpp
   test_core_StatisticsCounters.cpp
   test_core_StatsLog.cpp
similarity index 79%
rename from unittest/test_core_ShowIncludesParser.cpp
rename to unittest/test_core_MsvcShowIncludesOutput.cpp
index 61af1f8242df81b6f4420a8c6b3724bc56db5032..0e0f71783222c79a3b2e9ecc437d667a0730f31e 100644 (file)
@@ -17,7 +17,7 @@
 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 #include "../src/Context.hpp"
-#include "../src/core/ShowIncludesParser.hpp"
+#include "../src/core/MsvcShowIncludesOutput.hpp"
 #include "../src/util/string.hpp"
 #include "TestUtil.hpp"
 
 
 static const std::string defaultPrefix = "Note: including file:";
 
-TEST_SUITE_BEGIN("ShowIncludesParser");
+TEST_SUITE_BEGIN("MsvcShowIncludesOutput");
 
-TEST_CASE("ShowIncludesParser::tokenize")
+TEST_CASE("MsvcShowIncludesOutput::get_includes")
 {
   SUBCASE("Parse empty output")
   {
     std::string contents;
     const auto result =
-      core::ShowIncludesParser::tokenize(contents, defaultPrefix);
+      core::MsvcShowIncludesOutput::get_includes(contents, defaultPrefix);
     CHECK(result.size() == 0);
   }
 
@@ -47,7 +47,7 @@ Note: including file:   F:\Projects\ccache\src\NonCopyable.hpp
 Note: including file:   C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\deque
 )";
     const auto result =
-      core::ShowIncludesParser::tokenize(contents, defaultPrefix);
+      core::MsvcShowIncludesOutput::get_includes(contents, defaultPrefix);
     REQUIRE(result.size() == 5);
     CHECK(result[0] == "F:/Projects/ccache/build-msvc/config.h");
     CHECK(result[1] == R"(F:\Projects\ccache\unittest\../src/Context.hpp)");
@@ -64,7 +64,7 @@ Note: including file:   C:\Program Files\Microsoft Visual Studio\2022\Community\
       "Note: including file: foo\r\n"
       "Note: including file: bar\r\n";
     const auto result =
-      core::ShowIncludesParser::tokenize(contents, defaultPrefix);
+      core::MsvcShowIncludesOutput::get_includes(contents, defaultPrefix);
     REQUIRE(result.size() == 2);
     CHECK(result[0] == "foo");
     CHECK(result[1] == "bar");
@@ -77,7 +77,7 @@ Note: including file:   C:\Program Files\Microsoft Visual Studio\2022\Community\
       "Note: including file: \n"
       "Note: including file:  bar\n";
     const auto result =
-      core::ShowIncludesParser::tokenize(contents, defaultPrefix);
+      core::MsvcShowIncludesOutput::get_includes(contents, defaultPrefix);
     REQUIRE(result.size() == 2);
     CHECK(result[0] == "foo");
     CHECK(result[1] == "bar");
@@ -88,14 +88,15 @@ Note: including file:   C:\Program Files\Microsoft Visual Studio\2022\Community\
     std::string contents = R"(custom foo
 custom   bar
 Just a line with custom in the middle)";
-    const auto result = core::ShowIncludesParser::tokenize(contents, "custom");
+    const auto result =
+      core::MsvcShowIncludesOutput::get_includes(contents, "custom");
     REQUIRE(result.size() == 2);
     CHECK(result[0] == "foo");
     CHECK(result[1] == "bar");
   }
 }
 
-TEST_CASE("ShowIncludesParser::strip_includes")
+TEST_CASE("MsvcShowIncludesOutput::strip_includes")
 {
   Context ctx;
   const util::Bytes input = util::to_span(
@@ -106,14 +107,14 @@ TEST_CASE("ShowIncludesParser::strip_includes")
   SUBCASE("Empty output")
   {
     const util::Bytes result =
-      core::ShowIncludesParser::strip_includes(ctx, {});
+      core::MsvcShowIncludesOutput::strip_includes(ctx, {});
     CHECK(result.size() == 0);
   }
 
   SUBCASE("Feature disabled")
   {
     const util::Bytes result =
-      core::ShowIncludesParser::strip_includes(ctx, util::Bytes(input));
+      core::MsvcShowIncludesOutput::strip_includes(ctx, util::Bytes(input));
     CHECK(result == input);
   }
 
@@ -122,7 +123,7 @@ TEST_CASE("ShowIncludesParser::strip_includes")
   SUBCASE("Wrong compiler")
   {
     const util::Bytes result =
-      core::ShowIncludesParser::strip_includes(ctx, util::Bytes(input));
+      core::MsvcShowIncludesOutput::strip_includes(ctx, util::Bytes(input));
     CHECK(result == input);
   }
 
@@ -131,13 +132,13 @@ TEST_CASE("ShowIncludesParser::strip_includes")
   SUBCASE("Simple output")
   {
     const util::Bytes result =
-      core::ShowIncludesParser::strip_includes(ctx, util::Bytes(input));
+      core::MsvcShowIncludesOutput::strip_includes(ctx, util::Bytes(input));
     CHECK(result == util::to_span("First\nSecond\n"));
   }
 
   SUBCASE("Empty lines")
   {
-    const util::Bytes result = core::ShowIncludesParser::strip_includes(
+    const util::Bytes result = core::MsvcShowIncludesOutput::strip_includes(
       ctx,
       util::to_span("First\n"
                     "\n"
@@ -150,7 +151,7 @@ TEST_CASE("ShowIncludesParser::strip_includes")
 
   SUBCASE("CRLF")
   {
-    const util::Bytes result = core::ShowIncludesParser::strip_includes(
+    const util::Bytes result = core::MsvcShowIncludesOutput::strip_includes(
       ctx,
       util::to_span("First\r\n"
                     "Note: including file: foo\r\n"
@@ -161,7 +162,7 @@ TEST_CASE("ShowIncludesParser::strip_includes")
   SUBCASE("Custom prefix")
   {
     ctx.config.set_msvc_dep_prefix("custom");
-    const util::Bytes result = core::ShowIncludesParser::strip_includes(
+    const util::Bytes result = core::MsvcShowIncludesOutput::strip_includes(
       ctx,
       util::to_span("First\n"
                     "custom: including file: foo\n"