]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Move clang/msvc code to src/ccache/compiler
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 15 Nov 2025 11:49:11 +0000 (12:49 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 22 Nov 2025 09:36:10 +0000 (10:36 +0100)
13 files changed:
src/ccache/CMakeLists.txt
src/ccache/ccache.cpp
src/ccache/compiler/CMakeLists.txt [new file with mode: 0644]
src/ccache/compiler/clang.cpp [moved from src/ccache/util/clang.cpp with 97% similarity]
src/ccache/compiler/clang.hpp [moved from src/ccache/util/clang.hpp with 95% similarity]
src/ccache/compiler/msvc.cpp [moved from src/ccache/core/msvcshowincludesoutput.cpp with 88% similarity]
src/ccache/compiler/msvc.hpp [moved from src/ccache/core/msvcshowincludesoutput.hpp with 68% similarity]
src/ccache/core/CMakeLists.txt
src/ccache/core/resultretriever.cpp
src/ccache/util/CMakeLists.txt
unittest/CMakeLists.txt
unittest/test_compiler_clang.cpp [moved from unittest/test_util_clang.cpp with 83% similarity]
unittest/test_compiler_msvc.cpp [moved from unittest/test_core_msvcshowincludesoutput.cpp with 78% similarity]

index 140173314a231600201ec41965f119cdadd3a9a7..34c1e56a425f82376dd37e1d4af58d48060ae76a 100644 (file)
@@ -79,6 +79,7 @@ endif()
 add_executable(test-lockfile test_lockfile.cpp)
 target_link_libraries(test-lockfile PRIVATE standard_settings standard_warnings ccache_framework)
 
+add_subdirectory(compiler)
 add_subdirectory(core)
 add_subdirectory(storage)
 add_subdirectory(util)
index 8450def11c4ec8964b61b7a1a9b11c805d9c6402..1dfc96d5e64fb9fb9fdec7f9e9fcac69446549f1 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <ccache/argprocessing.hpp>
 #include <ccache/argsinfo.hpp>
+#include <ccache/compiler/clang.hpp>
+#include <ccache/compiler/msvc.hpp>
 #include <ccache/compopt.hpp>
 #include <ccache/context.hpp>
 #include <ccache/core/cacheentry.hpp>
@@ -28,7 +30,6 @@
 #include <ccache/core/exceptions.hpp>
 #include <ccache/core/mainoptions.hpp>
 #include <ccache/core/manifest.hpp>
-#include <ccache/core/msvcshowincludesoutput.hpp>
 #include <ccache/core/result.hpp>
 #include <ccache/core/resultretriever.hpp>
 #include <ccache/core/sloppiness.hpp>
@@ -46,7 +47,6 @@
 #include <ccache/util/args.hpp>
 #include <ccache/util/assertions.hpp>
 #include <ccache/util/bytes.hpp>
-#include <ccache/util/clang.hpp>
 #include <ccache/util/conversion.hpp>
 #include <ccache/util/defer.hpp>
 #include <ccache/util/direntry.hpp>
@@ -790,7 +790,8 @@ struct DoExecuteResult
 static tl::expected<Hash::Digest, Failure>
 result_key_from_includes(Context& ctx, Hash& hash, std::string_view stdout_data)
 {
-  for (std::string_view include : core::MsvcShowIncludesOutput::get_includes(
+  for (std::string_view include :
+       compiler::get_includes_from_msvc_show_includes(
          stdout_data, ctx.config.msvc_dep_prefix())) {
     const fs::path path = core::make_relative_path(ctx, include);
     TRY(remember_include_file(ctx, path, hash, false, &hash));
@@ -1255,7 +1256,7 @@ to_cache(Context& ctx,
       ctx, util::to_string_view(result->stderr_data), STDERR_FILENO);
     core::send_to_console(
       ctx,
-      util::to_string_view(core::MsvcShowIncludesOutput::strip_includes(
+      util::to_string_view(compiler::strip_includes_from_msvc_show_includes(
         ctx, std::move(result->stdout_data))),
       STDOUT_FILENO);
 
@@ -1326,7 +1327,7 @@ to_cache(Context& ctx,
   // Send stdout after stderr, it makes the output clearer with MSVC.
   core::send_to_console(
     ctx,
-    util::to_string_view(core::MsvcShowIncludesOutput::strip_includes(
+    util::to_string_view(compiler::strip_includes_from_msvc_show_includes(
       ctx, std::move(result->stdout_data))),
     STDOUT_FILENO);
 
@@ -1468,7 +1469,7 @@ get_result_key_from_cpp(Context& ctx, util::Args& args, Hash& hash)
       return tl::unexpected(Statistic::internal_error);
     }
     auto chunks =
-      util::split_preprocessed_file_from_clang_cuda(preprocessed_path);
+      compiler::split_preprocessed_file_from_clang_cuda(preprocessed_path);
     for (size_t i = 0; i < chunks.size(); ++i) {
       TRY(process_cuda_chunk(ctx, hash, chunks[i], i));
     }
diff --git a/src/ccache/compiler/CMakeLists.txt b/src/ccache/compiler/CMakeLists.txt
new file mode 100644 (file)
index 0000000..ddefb18
--- /dev/null
@@ -0,0 +1,10 @@
+set(
+  sources
+  clang.cpp
+  msvc.cpp
+)
+
+file(GLOB headers *.hpp)
+list(APPEND sources ${headers})
+
+target_sources(ccache_framework PRIVATE ${sources})
similarity index 97%
rename from src/ccache/util/clang.cpp
rename to src/ccache/compiler/clang.cpp
index 3eb4caee47b53986e4d375e52ee1007142803f15..63cb05fb28cb70bea52227da808e500c034a6472 100644 (file)
@@ -28,7 +28,7 @@
 
 namespace fs = util::filesystem;
 
-namespace util {
+namespace compiler {
 
 std::vector<std::string>
 split_preprocessed_file_from_clang_cuda(const fs::path& path)
@@ -65,4 +65,4 @@ split_preprocessed_file_from_clang_cuda(const fs::path& path)
   return chunks;
 }
 
-} // namespace util
+} // namespace compiler
similarity index 95%
rename from src/ccache/util/clang.hpp
rename to src/ccache/compiler/clang.hpp
index d05c3ff6c528cac72661fc1c1fe7ba12590e73cf..e9654ef2a4bf579c4d98017696b013e6c8cf271c 100644 (file)
@@ -22,9 +22,9 @@
 #include <string>
 #include <vector>
 
-namespace util {
+namespace compiler {
 
 std::vector<std::string>
 split_preprocessed_file_from_clang_cuda(const std::filesystem::path& path);
 
-} // namespace util
+} // namespace compiler
similarity index 88%
rename from src/ccache/core/msvcshowincludesoutput.cpp
rename to src/ccache/compiler/msvc.cpp
index 66d5518f3ad12af8f16fe9b1ecbf0bc50e3c2c96..05eec4c29b456a6b883c9cb480e92017f0e33522 100644 (file)
 // this program; if not, write to the Free Software Foundation, Inc., 51
 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
-#include "msvcshowincludesoutput.hpp"
+#include "msvc.hpp"
 
 #include <ccache/context.hpp>
 #include <ccache/util/string.hpp>
 
-namespace core::MsvcShowIncludesOutput {
+namespace compiler {
 
 std::vector<std::string_view>
-get_includes(std::string_view file_content, std::string_view prefix)
+get_includes_from_msvc_show_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:
@@ -49,7 +50,8 @@ get_includes(std::string_view file_content, std::string_view prefix)
 }
 
 util::Bytes
-strip_includes(const Context& ctx, util::Bytes&& stdout_data)
+strip_includes_from_msvc_show_includes(const Context& ctx,
+                                       util::Bytes&& stdout_data)
 {
   using util::Tokenizer;
   using Mode = Tokenizer::Mode;
@@ -72,4 +74,4 @@ strip_includes(const Context& ctx, util::Bytes&& stdout_data)
   return new_stdout_data;
 }
 
-} // namespace core::MsvcShowIncludesOutput
+} // namespace compiler
similarity index 68%
rename from src/ccache/core/msvcshowincludesoutput.hpp
rename to src/ccache/compiler/msvc.hpp
index db703f031f632bab95f6b8bcaaaae22d6ced387a..34da6fd8eb199db4ae698ac7fe03c2c380b6b371 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2022-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2022-2025 Joel Rosdahl and other contributors
 //
 // See doc/authors.adoc for a complete list of contributors.
 //
 
 class Context;
 
-namespace core::MsvcShowIncludesOutput {
+namespace compiler {
 
-std::vector<std::string_view> get_includes(std::string_view file_content,
-                                           std::string_view prefix);
+std::vector<std::string_view>
+get_includes_from_msvc_show_includes(std::string_view file_content,
+                                     std::string_view prefix);
 
-util::Bytes strip_includes(const Context& ctx, util::Bytes&& stdout_data);
+util::Bytes strip_includes_from_msvc_show_includes(const Context& ctx,
+                                                   util::Bytes&& stdout_data);
 
-} // namespace core::MsvcShowIncludesOutput
+} // namespace compiler
index 70c9ed9a1c647db25fb5109578a79c641bbfbf90..3673c2fdd03f9f868ccb3e02e817e18d0a20cf3b 100644 (file)
@@ -6,7 +6,6 @@ set(
   filerecompressor.cpp
   mainoptions.cpp
   manifest.cpp
-  msvcshowincludesoutput.cpp
   result.cpp
   resultextractor.cpp
   resultinspector.cpp
index ab0edd187dbd0936a23c33441a50ac5fe95e1e6a..8451d60206b2136d67fbfa496715131c548e05b7 100644 (file)
@@ -21,7 +21,6 @@
 #include <ccache/context.hpp>
 #include <ccache/core/common.hpp>
 #include <ccache/core/exceptions.hpp>
-#include <ccache/core/msvcshowincludesoutput.hpp>
 #include <ccache/depfile.hpp>
 #include <ccache/util/direntry.hpp>
 #include <ccache/util/expected.hpp>
@@ -70,7 +69,8 @@ ResultRetriever::on_embedded_file(uint8_t file_number,
   if (file_type == FileType::stdout_output) {
     core::send_to_console(
       m_ctx,
-      util::to_string_view(MsvcShowIncludesOutput::strip_includes(m_ctx, data)),
+      util::to_string_view(
+        compiler::strip_includes_from_msvc_show_includes(m_ctx, data)),
       STDOUT_FILENO);
   } else if (file_type == FileType::stderr_output) {
     core::send_to_console(m_ctx, util::to_string_view(data), STDERR_FILENO);
index 494457beba6b4f2d6c5680d6ede5d0de0542582b..5c9314e112e2ab6ad45638f8aeafa9cc09d5f376 100644 (file)
@@ -3,7 +3,6 @@ set(
   args.cpp
   assertions.cpp
   bytes.cpp
-  clang.cpp
   configreader.cpp
   cpu.cpp
   direntry.cpp
index 84dbe70654ba1d80dd561975a630b248542047a3..1e64b85b8928db814d00faaf72f360bb45fa813c 100644 (file)
@@ -3,12 +3,13 @@ set(
   main.cpp
   test_argprocessing.cpp
   test_ccache.cpp
+  test_compiler_clang.cpp
+  test_compiler_msvc.cpp
   test_compopt.cpp
   test_compression_types.cpp
   test_config.cpp
   test_core_atomicfile.cpp
   test_core_common.cpp
-  test_core_msvcshowincludesoutput.cpp
   test_core_statistics.cpp
   test_core_statisticscounters.cpp
   test_core_statslog.cpp
@@ -20,7 +21,6 @@ set(
   test_util_args.cpp
   test_util_bitset.cpp
   test_util_bytes.cpp
-  test_util_clang.cpp
   test_util_configreader.cpp
   test_util_conversion.cpp
   test_util_direntry.cpp
similarity index 83%
rename from unittest/test_util_clang.cpp
rename to unittest/test_compiler_clang.cpp
index d78f200d69c5873af1b03442661d7e9fce3fa575..b29b88d092c7739c49a983cf9a7ad5c93ade58c0 100644 (file)
@@ -18,7 +18,7 @@
 
 #include "testutil.hpp"
 
-#include <ccache/util/clang.hpp>
+#include <ccache/compiler/clang.hpp>
 #include <ccache/util/file.hpp>
 #include <ccache/util/filesystem.hpp>
 
@@ -30,9 +30,9 @@ namespace fs = util::filesystem;
 
 using TestUtil::TestContext;
 
-TEST_SUITE_BEGIN("util");
+TEST_SUITE_BEGIN("clang");
 
-TEST_CASE("util::split_preprocessed_file_from_clang_cuda")
+TEST_CASE("compiler::split_preprocessed_file_from_clang_cuda")
 {
   TestContext test_context;
 
@@ -50,7 +50,7 @@ void caller() {
 # 1 "<built-in>" 3
 )"));
 
-    auto result = util::split_preprocessed_file_from_clang_cuda(filename);
+    auto result = compiler::split_preprocessed_file_from_clang_cuda(filename);
 
     REQUIRE(result.size() == 2);
     CHECK(result[0] == R"(# 1 "test_cuda.cu"
@@ -69,7 +69,7 @@ void caller() {
   SUBCASE("non-existent file")
   {
     fs::path filename = "nonexistent_file.txt";
-    CHECK(util::split_preprocessed_file_from_clang_cuda(filename).empty());
+    CHECK(compiler::split_preprocessed_file_from_clang_cuda(filename).empty());
   }
 
   SUBCASE("empty file")
@@ -77,7 +77,7 @@ void caller() {
     fs::path filename = "test_empty.txt";
     REQUIRE(util::write_file(filename, ""));
 
-    CHECK(util::split_preprocessed_file_from_clang_cuda(filename).empty());
+    CHECK(compiler::split_preprocessed_file_from_clang_cuda(filename).empty());
   }
 }
 
similarity index 78%
rename from unittest/test_core_msvcshowincludesoutput.cpp
rename to unittest/test_compiler_msvc.cpp
index 654621c9f6e50df36c5a1cff63c65ac3dc43fed5..74c2241fafa881b517bc331626e73b74232ab6a2 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2025 Joel Rosdahl and other contributors
 //
 // See doc/authors.adoc for a complete list of contributors.
 //
 
 #include "testutil.hpp"
 
+#include <ccache/compiler/msvc.hpp>
 #include <ccache/context.hpp>
-#include <ccache/core/msvcshowincludesoutput.hpp>
 #include <ccache/util/string.hpp>
 
 #include <doctest/doctest.h>
 
 static const std::string defaultPrefix = "Note: including file:";
 
-TEST_SUITE_BEGIN("MsvcShowIncludesOutput");
+TEST_SUITE_BEGIN("msvc");
 
-TEST_CASE("MsvcShowIncludesOutput::get_includes")
+TEST_CASE("get_includes_from_msvc_show_includes")
 {
   SUBCASE("Parse empty output")
   {
     std::string contents;
     const auto result =
-      core::MsvcShowIncludesOutput::get_includes(contents, defaultPrefix);
+      compiler::get_includes_from_msvc_show_includes(contents, defaultPrefix);
     CHECK(result.size() == 0);
   }
 
@@ -48,7 +48,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::MsvcShowIncludesOutput::get_includes(contents, defaultPrefix);
+      compiler::get_includes_from_msvc_show_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)");
@@ -65,7 +65,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::MsvcShowIncludesOutput::get_includes(contents, defaultPrefix);
+      compiler::get_includes_from_msvc_show_includes(contents, defaultPrefix);
     REQUIRE(result.size() == 2);
     CHECK(result[0] == "foo");
     CHECK(result[1] == "bar");
@@ -78,7 +78,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::MsvcShowIncludesOutput::get_includes(contents, defaultPrefix);
+      compiler::get_includes_from_msvc_show_includes(contents, defaultPrefix);
     REQUIRE(result.size() == 2);
     CHECK(result[0] == "foo");
     CHECK(result[1] == "bar");
@@ -90,14 +90,14 @@ Note: including file:   C:\Program Files\Microsoft Visual Studio\2022\Community\
 custom   bar
 Just a line with custom in the middle)";
     const auto result =
-      core::MsvcShowIncludesOutput::get_includes(contents, "custom");
+      compiler::get_includes_from_msvc_show_includes(contents, "custom");
     REQUIRE(result.size() == 2);
     CHECK(result[0] == "foo");
     CHECK(result[1] == "bar");
   }
 }
 
-TEST_CASE("MsvcShowIncludesOutput::strip_includes")
+TEST_CASE("strip_includes_from_msvc_show_includes")
 {
   Context ctx;
   const util::Bytes input = util::to_span(
@@ -108,14 +108,14 @@ TEST_CASE("MsvcShowIncludesOutput::strip_includes")
   SUBCASE("Empty output")
   {
     const util::Bytes result =
-      core::MsvcShowIncludesOutput::strip_includes(ctx, {});
+      compiler::strip_includes_from_msvc_show_includes(ctx, {});
     CHECK(result.size() == 0);
   }
 
   SUBCASE("Feature disabled")
   {
     const util::Bytes result =
-      core::MsvcShowIncludesOutput::strip_includes(ctx, util::Bytes(input));
+      compiler::strip_includes_from_msvc_show_includes(ctx, util::Bytes(input));
     CHECK(result == input);
   }
 
@@ -124,7 +124,7 @@ TEST_CASE("MsvcShowIncludesOutput::strip_includes")
   SUBCASE("Wrong compiler")
   {
     const util::Bytes result =
-      core::MsvcShowIncludesOutput::strip_includes(ctx, util::Bytes(input));
+      compiler::strip_includes_from_msvc_show_includes(ctx, util::Bytes(input));
     CHECK(result == input);
   }
 
@@ -133,13 +133,13 @@ TEST_CASE("MsvcShowIncludesOutput::strip_includes")
   SUBCASE("Simple output")
   {
     const util::Bytes result =
-      core::MsvcShowIncludesOutput::strip_includes(ctx, util::Bytes(input));
+      compiler::strip_includes_from_msvc_show_includes(ctx, util::Bytes(input));
     CHECK(result == util::to_span("First\nSecond\n"));
   }
 
   SUBCASE("Empty lines")
   {
-    const util::Bytes result = core::MsvcShowIncludesOutput::strip_includes(
+    const util::Bytes result = compiler::strip_includes_from_msvc_show_includes(
       ctx,
       util::to_span("First\n"
                     "\n"
@@ -152,7 +152,7 @@ TEST_CASE("MsvcShowIncludesOutput::strip_includes")
 
   SUBCASE("CRLF")
   {
-    const util::Bytes result = core::MsvcShowIncludesOutput::strip_includes(
+    const util::Bytes result = compiler::strip_includes_from_msvc_show_includes(
       ctx,
       util::to_span("First\r\n"
                     "Note: including file: foo\r\n"
@@ -163,7 +163,7 @@ TEST_CASE("MsvcShowIncludesOutput::strip_includes")
   SUBCASE("Custom prefix")
   {
     ctx.config.set_msvc_dep_prefix("custom");
-    const util::Bytes result = core::MsvcShowIncludesOutput::strip_includes(
+    const util::Bytes result = compiler::strip_includes_from_msvc_show_includes(
       ctx,
       util::to_span("First\n"
                     "custom: including file: foo\n"