]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Move Util::is_ccache_executable to ccache
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 17 Jul 2023 16:46:27 +0000 (18:46 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 18 Jul 2023 19:37:27 +0000 (21:37 +0200)
src/Util.cpp
src/Util.hpp
src/ccache.cpp
src/ccache.hpp
src/execute.cpp
unittest/test_Util.cpp
unittest/test_ccache.cpp

index 8118dc656a32528b5c998aee19419bc4af5b5e3d..021114d859ce7b9bab1718d50223d9da85c23919 100644 (file)
@@ -353,16 +353,6 @@ is_absolute_path_with_prefix(std::string_view path)
   return std::nullopt;
 }
 
-bool
-is_ccache_executable(const std::string_view path)
-{
-  std::string name(Util::base_name(path));
-#ifdef _WIN32
-  name = util::to_lowercase(name);
-#endif
-  return util::starts_with(name, "ccache");
-}
-
 std::string
 make_relative_path(const std::string& base_dir,
                    const std::string& actual_cwd,
index 755ab2b5e176d6830b3d5fd69cb35e59a9569aeb..f47d1d4c862c225f5ecb3ebecbddd11ef33eef47 100644 (file)
@@ -78,9 +78,6 @@ std::string get_relative_path(std::string_view dir, std::string_view path);
 // point.
 std::optional<size_t> is_absolute_path_with_prefix(std::string_view path);
 
-// Detmine if `path` refers to a ccache executable.
-bool is_ccache_executable(std::string_view path);
-
 // Return whether `ch` is a directory separator, i.e. '/' on POSIX systems and
 // '/' or '\\' on Windows systems.
 inline bool
index 4a9882547fa6b9aa03f0a6a1824b3c30c67e1931..3112d795e835d5ea016cc9dc3cf34dfa0c410477 100644 (file)
@@ -2166,7 +2166,7 @@ find_compiler(Context& ctx,
     throw core::Fatal(FMT("Could not find compiler \"{}\" in PATH", compiler));
   }
 
-  if (Util::is_ccache_executable(resolved_compiler)) {
+  if (is_ccache_executable(resolved_compiler)) {
     throw core::Fatal("Recursive invocation of ccache");
   }
 
@@ -2311,7 +2311,7 @@ split_argv(int argc, const char* const* argv)
 {
   ArgvParts argv_parts;
   int i = 0;
-  while (i < argc && Util::is_ccache_executable(argv[i])) {
+  while (i < argc && is_ccache_executable(argv[i])) {
     argv_parts.masquerading_as_compiler = false;
     ++i;
   }
@@ -2681,11 +2681,21 @@ do_cache_compilation(Context& ctx)
   return ctx.config.recache() ? Statistic::recache : Statistic::cache_miss;
 }
 
+bool
+is_ccache_executable(const std::string_view path)
+{
+  std::string name(Util::base_name(path));
+#ifdef _WIN32
+  name = util::to_lowercase(name);
+#endif
+  return util::starts_with(name, "ccache");
+}
+
 int
 ccache_main(int argc, const char* const* argv)
 {
   try {
-    if (Util::is_ccache_executable(argv[0])) {
+    if (is_ccache_executable(argv[0])) {
       if (argc < 2) {
         PRINT_RAW(stderr, core::get_usage_text(Util::base_name(argv[0])));
         exit(EXIT_FAILURE);
index a3d0be77e8c581ef6cb1a89d60a3b359d534d108..3d8072e6f77983aa637d6763a420432078baf825 100644 (file)
@@ -52,3 +52,4 @@ void find_compiler(Context& ctx,
                    const FindExecutableFunction& find_executable_function,
                    bool masquerading_as_compiler);
 CompilerType guess_compiler(std::string_view path);
+bool is_ccache_executable(std::string_view path);
index 27cb24ae11a668f7f6d191233f434ce42b1e48b0..44215c66e9a7d992df69b49e38fc43ae2a869f70 100644 (file)
@@ -29,6 +29,7 @@
 #include "Util.hpp"
 #include "Win32Util.hpp"
 
+#include <ccache.hpp>
 #include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 #include <fmtmacros.hpp>
@@ -399,7 +400,7 @@ find_executable_in_path(const std::string& name,
       if (candidate_exists) {
         const auto real_candidate = util::real_path(candidate);
         if ((real_exclude_path.empty() || real_candidate != real_exclude_path)
-            && !Util::is_ccache_executable(real_candidate)) {
+            && !is_ccache_executable(real_candidate)) {
           return candidate;
         }
       }
index 2fe814c4de36129971e6af7edee063ca1f872c4a..d3879afef337880fe528f742d65295210089a829 100644 (file)
@@ -207,21 +207,6 @@ TEST_CASE("Util::is_absolute_path_with_prefix")
 #endif
 }
 
-TEST_CASE("Util::is_ccache_executable")
-{
-  CHECK(Util::is_ccache_executable("ccache"));
-  CHECK(Util::is_ccache_executable("ccache-1.2.3"));
-  CHECK(!Util::is_ccache_executable("fooccache"));
-  CHECK(!Util::is_ccache_executable("gcc"));
-#ifdef _WIN32
-  CHECK(Util::is_ccache_executable("CCACHE"));
-  CHECK(Util::is_ccache_executable("CCACHE.exe"));
-  CHECK(Util::is_ccache_executable("CCACHE-1.2.3"));
-  CHECK(Util::is_ccache_executable("CCACHE.EXE"));
-  CHECK(Util::is_ccache_executable("CCACHE-1.2.3.EXE"));
-#endif
-}
-
 TEST_CASE("Util::is_dir_separator")
 {
   CHECK(!Util::is_dir_separator('x'));
index bb4bf8860504f6364f3be72017c9cb0f44468bbf..cab8cf3d617c0ee09a2cc1f977fa8b52f126767a 100644 (file)
@@ -204,4 +204,19 @@ TEST_CASE("guess_compiler")
 #endif
 }
 
+TEST_CASE("is_ccache_executable")
+{
+  CHECK(is_ccache_executable("ccache"));
+  CHECK(is_ccache_executable("ccache-1.2.3"));
+  CHECK(!is_ccache_executable("fooccache"));
+  CHECK(!is_ccache_executable("gcc"));
+#ifdef _WIN32
+  CHECK(is_ccache_executable("CCACHE"));
+  CHECK(is_ccache_executable("CCACHE.exe"));
+  CHECK(is_ccache_executable("CCACHE-1.2.3"));
+  CHECK(is_ccache_executable("CCACHE.EXE"));
+  CHECK(is_ccache_executable("CCACHE-1.2.3.EXE"));
+#endif
+}
+
 TEST_SUITE_END();