]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Move Win32Util::error_message to util
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 2 Oct 2023 18:45:02 +0000 (20:45 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 2 Oct 2023 19:33:49 +0000 (21:33 +0200)
13 files changed:
src/CMakeLists.txt
src/Context.cpp
src/Logging.cpp
src/Util.cpp
src/ccache.cpp
src/execute.cpp
src/hashutil.cpp
src/util/CMakeLists.txt
src/util/DirEntry.cpp
src/util/LockFile.cpp
src/util/error.cpp [moved from src/Win32Util.cpp with 88% similarity]
src/util/error.hpp [moved from src/Win32Util.hpp with 80% similarity]
src/util/file.cpp

index 5c6dc11781b9dd975e2e81fdcc002729f883f03a..a61428d44544b4a6fa619eb9966ccf800ea998bb 100644 (file)
@@ -25,9 +25,7 @@ if(MTR_ENABLED)
   list(APPEND source_files MiniTrace.cpp)
 endif()
 
-if(WIN32)
-  list(APPEND source_files Win32Util.cpp)
-else()
+if(NOT WIN32)
   list(APPEND source_files SignalHandler.cpp)
 endif()
 
index fbbfb2fde5e6e7ede367b2dd78f4763617d5fbff..76768013faa884bef5d2f992b5ac371b2c8dc3d5 100644 (file)
@@ -23,7 +23,6 @@
 #include "Util.hpp"
 #include "hashutil.hpp"
 
-#include <Win32Util.hpp>
 #include <util/TimePoint.hpp>
 #include <util/file.hpp>
 #include <util/path.hpp>
index 1705024d7876aab05bce56ed6fa42c3667f9f17f..a681c06b6e92ed01b030927348b3de92df81d34c 100644 (file)
@@ -21,7 +21,6 @@
 
 #include "Config.hpp"
 #include "Util.hpp"
-#include "Win32Util.hpp"
 #include "execute.hpp"
 
 #include <util/FileStream.hpp>
index 79b91af9ad8af6b7a7844d68cca9500518b80742..aad8a6065f0fdd0b5677d6cc30d0dff08c7c2516 100644 (file)
@@ -21,7 +21,6 @@
 #include "Config.hpp"
 #include "Context.hpp"
 #include "Logging.hpp"
-#include "Win32Util.hpp"
 
 #include <Config.hpp>
 #include <core/exceptions.hpp>
index d6e6a27cdc1c4a697fd20863b2b57452442524f1..51d2a423057f2d9126afbbf32f1d93d3bc53f60a 100644 (file)
@@ -28,7 +28,6 @@
 #include "MiniTrace.hpp"
 #include "SignalHandler.hpp"
 #include "Util.hpp"
-#include "Win32Util.hpp"
 #include "argprocessing.hpp"
 #include "compopt.hpp"
 #include "execute.hpp"
index 6c52fa874ae24fdf5b6bdfdfdbe8ae5f57177352..80b5c276620d6f8a8403b5bb6c5a6dd0ea06ef15 100644 (file)
@@ -24,7 +24,6 @@
 #include "Logging.hpp"
 #include "SignalHandler.hpp"
 #include "Util.hpp"
-#include "Win32Util.hpp"
 
 #include <ccache.hpp>
 #include <core/exceptions.hpp>
@@ -32,6 +31,7 @@
 #include <util/Fd.hpp>
 #include <util/Finalizer.hpp>
 #include <util/TemporaryFile.hpp>
+#include <util/error.hpp>
 #include <util/expected.hpp>
 #include <util/file.hpp>
 #include <util/filesystem.hpp>
@@ -122,7 +122,7 @@ win32execute(const char* path,
     if (!job_success) {
       DWORD error = GetLastError();
       LOG("failed to IsProcessInJob: {} ({})",
-          Win32Util::error_message(error),
+          util::win32_error_message(error),
           error);
       return 0;
     }
@@ -137,7 +137,7 @@ win32execute(const char* path,
       if (!querySuccess) {
         DWORD error = GetLastError();
         LOG("failed to QueryInformationJobObject: {} ({})",
-            Win32Util::error_message(error),
+            util::win32_error_message(error),
             error);
         return 0;
       }
@@ -160,7 +160,7 @@ win32execute(const char* path,
     if (job == nullptr) {
       DWORD error = GetLastError();
       LOG("failed to CreateJobObject: {} ({})",
-          Win32Util::error_message(error),
+          util::win32_error_message(error),
           error);
       return -1;
     }
@@ -176,7 +176,7 @@ win32execute(const char* path,
       if (!job_success) {
         DWORD error = GetLastError();
         LOG("failed to JobObjectExtendedLimitInformation: {} ({})",
-            Win32Util::error_message(error),
+            util::win32_error_message(error),
             error);
         return -1;
       }
@@ -253,7 +253,7 @@ win32execute(const char* path,
     DWORD error = GetLastError();
     LOG("failed to execute {}: {} ({})",
         full_path,
-        Win32Util::error_message(error),
+        util::win32_error_message(error),
         error);
     return -1;
   }
@@ -265,7 +265,7 @@ win32execute(const char* path,
       DWORD error = GetLastError();
       LOG("failed to assign process to job object {}: {} ({})",
           full_path,
-          Win32Util::error_message(error),
+          util::win32_error_message(error),
           error);
       return -1;
     }
index 7665c4e00a4fd8cd10265eaa9efa0b4908e1d5f3..56ee51c3fe069f858b6045b090fd323ff08c9e8e 100644 (file)
@@ -22,7 +22,6 @@
 #include "Config.hpp"
 #include "Context.hpp"
 #include "Logging.hpp"
-#include "Win32Util.hpp"
 #include "execute.hpp"
 #include "macroskip.hpp"
 
index c22a0eec57677f1c7f2f734a77f6bd2cab6b0224..b9020bbfcd231dc642a78e6d105306c7cf9bfd42 100644 (file)
@@ -12,6 +12,7 @@ set(
   UmaskScope.cpp
   assertions.cpp
   environment.cpp
+  error.cpp
   file.cpp
   filesystem.cpp
   path.cpp
index e5cfd45b7be3502af770f62b612d355d9ad0b2f1..beeb90c2f6a0117089edd2667fcd8d1a067b870a 100644 (file)
@@ -19,7 +19,6 @@
 #include "DirEntry.hpp"
 
 #include <Logging.hpp>
-#include <Win32Util.hpp>
 #include <util/Finalizer.hpp>
 #include <util/file.hpp>
 #include <util/fmtmacros.hpp>
index c3f670e90b0f68e9b7aa54aac76ac133f821567a..f922d71c1b7f950876b7aea7c6cd4e340d989277 100644 (file)
 
 #include "Logging.hpp"
 #include "Util.hpp"
-#include "Win32Util.hpp"
 
 #include <util/DirEntry.hpp>
 #include <util/assertions.hpp>
+#include <util/error.hpp>
 #include <util/file.hpp>
 #include <util/filesystem.hpp>
 #include <util/fmtmacros.hpp>
@@ -386,7 +386,7 @@ LockFile::do_acquire(const bool blocking)
 
     LOG("Could not acquire {}: {} ({})",
         m_lock_file,
-        Win32Util::error_message(error),
+        util::win32_error_message(error),
         error);
 
     // ERROR_SHARING_VIOLATION: lock already held.
similarity index 88%
rename from src/Win32Util.cpp
rename to src/util/error.cpp
index d50a4bd63a9ae0044ce88d4235f688f2249162e5..5cc9c346b3fc44b32417eb7abdf97756060a55e8 100644 (file)
 // this program; if not, write to the Free Software Foundation, Inc., 51
 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
-#include "Win32Util.hpp"
+#include "error.hpp"
 
-#include "Util.hpp"
+#include <util/wincompat.hpp>
 
-#include <util/string.hpp>
+namespace util {
 
-#include <chrono>
-#include <thread>
-
-namespace Win32Util {
+#ifdef _WIN32
 
 std::string
-error_message(DWORD error_code)
+win32_error_message(uint32_t error_code)
 {
   LPSTR buffer;
   size_t size =
@@ -49,4 +46,6 @@ error_message(DWORD error_code)
   return message;
 }
 
-} // namespace Win32Util
+#endif
+
+} // namespace util
similarity index 80%
rename from src/Win32Util.hpp
rename to src/util/error.hpp
index b73224090db9491bc68907ac02eafef85c80df91..de77b77c78536cb4b6c137fbf7e44f1fa5521d5f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2023 Joel Rosdahl and other contributors
+// Copyright (C) 2023 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#ifdef _WIN32
-
-#  include <util/wincompat.hpp>
+#include <cstdint>
+#include <string>
 
-#  include <string>
+namespace util {
 
-namespace Win32Util {
+#ifdef _WIN32
 
 // Return the error message corresponding to `error_code`.
-std::string error_message(DWORD error_code);
-
-} // namespace Win32Util
+std::string win32_error_message(uint32_t error_code);
 
 #endif
+
+} // namespace util
index fdc211214f3b1c3b52df0352db61a36a579bd633..ff97c2398faa82997cfecccfbcc23b83fff539d9 100644 (file)
 #include "file.hpp"
 
 #include <Logging.hpp>
-#include <Win32Util.hpp>
 #include <util/Bytes.hpp>
 #include <util/DirEntry.hpp>
 #include <util/Fd.hpp>
 #include <util/Finalizer.hpp>
 #include <util/TemporaryFile.hpp>
+#include <util/error.hpp>
 #include <util/expected.hpp>
 #include <util/file.hpp>
 #include <util/filesystem.hpp>
@@ -306,7 +306,7 @@ read_file(const fs::path& path, size_t size_hint)
         return tl::unexpected(
           FMT("Failed to convert {} from UTF-16LE to UTF-8: {}",
               path,
-              Win32Util::error_message(GetLastError())));
+              util::win32_error_message(GetLastError())));
       }
 
       result = std::string(size, '\0');