]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Improve some types
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 24 Sep 2024 18:50:23 +0000 (20:50 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 17 Oct 2024 19:56:54 +0000 (21:56 +0200)
12 files changed:
src/ccache/argprocessing.cpp
src/ccache/context.cpp
src/ccache/core/common.cpp
src/ccache/core/result.cpp
src/ccache/core/resultretriever.cpp
src/ccache/execute.cpp
src/ccache/inodecache.cpp
src/ccache/storage/local/localstorage.cpp
src/ccache/util/file.cpp
src/ccache/util/filesystem.cpp
src/ccache/util/path.cpp
src/ccache/util/string.cpp

index 10f4d7ac19b9c9365f33a1ddfc712c1f9979bc33..012ee43b1009726be270886388d8fc72290fa8bd 100644 (file)
@@ -79,7 +79,7 @@ struct ArgumentProcessingState
   bool found_fpch_preprocess = false;
   bool found_Yu = false;
   bool found_Yc = false;
-  std::filesystem::path found_Fp_file;
+  fs::path found_Fp_file;
   bool found_valid_Fp = false;
   bool found_syntax_only = false;
   ColorDiagnostics color_diagnostics = ColorDiagnostics::automatic;
@@ -157,7 +157,7 @@ detect_pch(const std::string& option,
   // If the option is an option for Clang (is_cc1_option), don't accept
   // anything just because it has a corresponding precompiled header,
   // because Clang doesn't behave that way either.
-  std::filesystem::path pch_file;
+  fs::path pch_file;
   if (option == "-Yc") {
     state.found_Yc = true;
     args_info.generating_pch = true;
@@ -236,7 +236,7 @@ detect_pch(const std::string& option,
 bool
 process_profiling_option(const Context& ctx,
                          ArgsInfo& args_info,
-                         const std::string& arg)
+                         std::string_view arg)
 {
   static const std::vector<std::string> known_simple_options = {
     "-fprofile-correction",
@@ -255,13 +255,12 @@ process_profiling_option(const Context& ctx,
   }
 
   if (util::starts_with(arg, "-fprofile-prefix-path=")) {
-    std::filesystem::path profile_prefix_path = arg.substr(arg.find('=') + 1);
-    args_info.profile_prefix_path = profile_prefix_path;
+    args_info.profile_prefix_path = arg.substr(arg.find('=') + 1);
     LOG("Set profile prefix path to {}", args_info.profile_prefix_path);
     return true;
   }
 
-  std::filesystem::path new_profile_path;
+  fs::path new_profile_path;
   bool new_profile_use = false;
 
   if (util::starts_with(arg, "-fprofile-dir=")) {
index b59cd95eee89998c965b15c7b0991c0861ef465a..0f9fe0eeacfdbaabeeac76dbb9aaf6c4c2a4dd74 100644 (file)
@@ -90,8 +90,7 @@ Context::unlink_pending_tmp_files_signal_safe()
 {
   for (auto it = m_pending_tmp_files.rbegin(); it != m_pending_tmp_files.rend();
        ++it) {
-    // Don't call util::remove or std::filesystem::remove since they are not
-    // signal safe.
+    // Don't call util::remove or fs::remove since they are not signal safe.
     unlink(util::pstr(*it).c_str());
   }
   // Don't clear m_pending_tmp_files since this method must be signal safe.
index a177296a444971b3070000c5c348982e89228785..63c399d0ea7caae1061c4dd03dec0c38e5b70345 100644 (file)
@@ -79,8 +79,8 @@ ensure_dir_exists(const fs::path& dir)
   }
 }
 
-std::filesystem::path
-make_relative_path(const Context& ctx, const std::filesystem::path& path)
+fs::path
+make_relative_path(const Context& ctx, const fs::path& path)
 {
   if (!ctx.config.base_dir().empty() && path.is_absolute()
       && util::path_starts_with(path, ctx.config.base_dir())) {
index 3599bb5221a6e141deb3b2257f9c879d7c71c7e4..66d9750a8f7575ebe6b046187699f144e52d885a 100644 (file)
@@ -250,8 +250,7 @@ Serializer::add_data(const FileType file_type, nonstd::span<const uint8_t> data)
 }
 
 bool
-Serializer::add_file(const FileType file_type,
-                     const std::filesystem::path& path)
+Serializer::add_file(const FileType file_type, const fs::path& path)
 {
   m_serialized_size += 1 + 1 + 8; // marker + file_type + file_size
   if (!should_store_raw_file(m_config, file_type)) {
index 9547109c4894bafad24212bae7ddf2645bee9741..5212016a84782c1d877e223df1b1dada29c23d35 100644 (file)
@@ -215,7 +215,7 @@ ResultRetriever::get_dest_path(FileType file_type) const
 }
 
 void
-ResultRetriever::write_dependency_file(const std::filesystem::path& path,
+ResultRetriever::write_dependency_file(const fs::path& path,
                                        nonstd::span<const uint8_t> data)
 {
   ASSERT(m_ctx.args_info.dependency_target);
index 3b5f836fd6ada7d18291a3e556dbf47d3fa75be9..7ed359cc4d474b449448f9dd9a34f4801173ef34 100644 (file)
@@ -349,8 +349,7 @@ execute(Context& ctx,
 }
 
 void
-execute_noreturn(const char* const* argv,
-                 const std::filesystem::path& /*temp_dir*/)
+execute_noreturn(const char* const* argv, const fs::path& /*temp_dir*/)
 {
   execv(argv[0], const_cast<char* const*>(argv));
 }
index 2f282fe9e907f095de880c01d04729f13bf9c8a8..d32c171241b573f59527e5aa5932a1a13020da1b 100644 (file)
@@ -254,7 +254,7 @@ struct InodeCache::SharedRegion
 };
 
 bool
-InodeCache::mmap_file(const std::filesystem::path& path)
+InodeCache::mmap_file(const fs::path& path)
 {
   m_sr = nullptr;
   m_map.unmap();
index ec59f5d5f73c41a6668e92166e553a024872735d..aa9d87dd65a16cd98d3d2a9ef5bf6b25f8c050b3 100644 (file)
@@ -240,9 +240,7 @@ delete_file(const DirEntry& dir_entry,
 // to a temporary file and then renamed to `dest`. Throws `core::Error` on
 // error.
 static void
-clone_file(const std::filesystem::path& src,
-           const std::filesystem::path& dest,
-           bool via_tmp_file)
+clone_file(const fs::path& src, const fs::path& dest, bool via_tmp_file)
 {
 #  if defined(__linux__)
   util::Fd src_fd(open(util::pstr(src).c_str(), O_RDONLY));
index 142ea5ab7128b4cf9291210c17f027e1506be50a..03f005261a3877fe95d30ae653c227f69d44b252 100644 (file)
@@ -621,7 +621,7 @@ tl::expected<void, std::string>
 traverse_directory(const fs::path& directory,
                    const TraverseDirectoryVisitor& visitor)
 {
-  // Note: Intentionally not using std::filesystem::recursive_directory_iterator
+  // Note: Intentionally not using fs::recursive_directory_iterator
   // since it visits directories in preorder.
 
   DirEntry dir_entry(directory);
@@ -633,7 +633,7 @@ traverse_directory(const fs::path& directory,
   }
 
   try {
-    for (const auto& entry : std::filesystem::directory_iterator(directory)) {
+    for (const auto& entry : fs::directory_iterator(directory)) {
       if (entry.is_directory()) {
         traverse_directory(entry.path(), visitor);
       } else {
index 22ad2cff172ae847439a2ca1e11abfe0d5eb637b..77ea074d213ad91054bd2071878f90832f91a1d3 100644 (file)
 
 namespace util::filesystem {
 
+namespace fs = std::filesystem;
+
 tl::expected<void, std::error_code>
-rename(const std::filesystem::path& old_p, const std::filesystem::path& new_p)
+rename(const fs::path& old_p, const fs::path& new_p)
 {
 #ifndef _WIN32
   std::error_code ec;
-  std::filesystem::rename(old_p, new_p, ec);
+  fs::rename(old_p, new_p, ec);
   if (ec) {
     return tl::unexpected(ec);
   }
index a6fe0128556ae757152150f4a48acb38f0549930..282cca0c98ad04e9b0a7684825cac2062111af6b 100644 (file)
@@ -67,7 +67,7 @@ get_dev_null_path()
   return k_dev_null_path;
 }
 
-std::filesystem::path
+fs::path
 make_relative_path(const fs::path& actual_cwd,
                    const fs::path& apparent_cwd,
                    const fs::path& path)
index cf4fd81eafc734f17a3ed085dd7c85cfe071eeef..1597647ec2baf1e4eabe1ca78763647238235fac 100644 (file)
 #include "string.hpp"
 
 #include <ccache/util/assertions.hpp>
+#include <ccache/util/filesystem.hpp>
 #include <ccache/util/format.hpp>
 
 #include <algorithm>
 #include <cctype>
 
+namespace fs = util::filesystem;
+
 namespace {
 
 template<typename T>
@@ -503,7 +506,7 @@ split_option_with_concat_path(std::string_view string)
   return std::make_pair(string.substr(0, split_pos), string.substr(split_pos));
 }
 
-std::vector<std::filesystem::path>
+std::vector<fs::path>
 split_path_list(std::string_view path_list)
 {
 #ifdef _WIN32
@@ -512,7 +515,7 @@ split_path_list(std::string_view path_list)
   const char path_delimiter[] = ":";
 #endif
   auto strings = split_into_views(path_list, path_delimiter);
-  std::vector<std::filesystem::path> paths;
+  std::vector<fs::path> paths;
   std::copy(strings.cbegin(), strings.cend(), std::back_inserter(paths));
   return paths;
 }