]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Add and use util::pstr type alias
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 1 Jun 2024 12:00:07 +0000 (14:00 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 30 Jun 2024 15:18:48 +0000 (17:18 +0200)
Also removed less common util::PathString::operator const char* to make
some call sites unambiguous.

26 files changed:
src/ccache/Config.cpp
src/ccache/Depfile.cpp
src/ccache/Hash.hpp
src/ccache/InodeCache.cpp
src/ccache/argprocessing.cpp
src/ccache/ccache.cpp
src/ccache/core/Statistics.cpp
src/ccache/core/StatsLog.cpp
src/ccache/core/StatsLog.hpp
src/ccache/core/common.cpp
src/ccache/core/mainoptions.cpp
src/ccache/execute.cpp
src/ccache/storage/local/LocalStorage.cpp
src/ccache/storage/local/util.cpp
src/ccache/util/DirEntry.cpp
src/ccache/util/FileStream.hpp
src/ccache/util/LockFile.cpp
src/ccache/util/PathString.hpp
src/ccache/util/TemporaryFile.cpp
src/ccache/util/file.cpp
src/ccache/util/path.cpp
src/ccache/util/path.hpp
unittest/test_Depfile.cpp
unittest/test_InodeCache.cpp
unittest/test_argprocessing.cpp
unittest/test_util_path.cpp

index b4974e1e482cce61058185e5b6d32a453cad52d1..6b5835ec982f105b135e0833a9388356531ce025 100644 (file)
@@ -23,7 +23,6 @@
 #include <ccache/core/common.hpp>
 #include <ccache/core/exceptions.hpp>
 #include <ccache/util/DirEntry.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/Tokenizer.hpp>
 #include <ccache/util/UmaskScope.hpp>
 #include <ccache/util/assertions.hpp>
@@ -65,7 +64,6 @@ const char k_sysconfdir[4096 + 1] = SYSCONFDIR;
 
 namespace fs = util::filesystem;
 
-using pstr = util::PathString;
 using util::DirEntry;
 using util::make_path;
 
@@ -636,10 +634,10 @@ Config::read(const std::vector<std::string>& cmdline_config_settings)
 
   if (cache_dir().empty()) {
     if (legacy_ccache_dir_exists) {
-      set_cache_dir(pstr(legacy_ccache_dir));
+      set_cache_dir(util::pstr(legacy_ccache_dir));
 #ifdef _WIN32
     } else if (env_local_appdata) {
-      set_cache_dir(pstr(fs::path(env_local_appdata) / "ccache"));
+      set_cache_dir(util::pstr(fs::path(env_local_appdata) / "ccache"));
     } else {
       throw core::Fatal(
         "could not find cache directory and the LOCALAPPDATA environment"
@@ -688,9 +686,10 @@ bool
 Config::update_from_file(const fs::path& path)
 {
   return parse_config_file(
-    pstr(path), [&](const auto& /*line*/, const auto& key, const auto& value) {
+    util::pstr(path),
+    [&](const auto& /*line*/, const auto& key, const auto& value) {
       if (!key.empty()) {
-        set_item(key, value, std::nullopt, false, pstr(path));
+        set_item(key, value, std::nullopt, false, util::pstr(path));
       }
     });
 }
@@ -758,7 +757,7 @@ Config::get_string_value(const std::string& key) const
     return format_bool(m_absolute_paths_in_stderr);
 
   case ConfigItem::base_dir:
-    return pstr(m_base_dir).str();
+    return util::pstr(m_base_dir);
 
   case ConfigItem::cache_dir:
     return m_cache_dir;
index 36fb32b76802c7646a601d9771f2ef99fdc657fd..f69ecbcc4e89487b08c8f415960e649fdc84832c 100644 (file)
@@ -22,7 +22,6 @@
 #include <ccache/Hash.hpp>
 #include <ccache/core/common.hpp>
 #include <ccache/core/exceptions.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/Tokenizer.hpp>
 #include <ccache/util/assertions.hpp>
 #include <ccache/util/file.hpp>
@@ -35,8 +34,6 @@
 
 namespace fs = util::filesystem;
 
-using pstr = util::PathString;
-
 namespace Depfile {
 
 std::string
@@ -82,7 +79,7 @@ rewrite_source_paths(const Context& ctx, std::string_view content)
     auto rel_path = core::make_relative_path(ctx, token);
     if (rel_path != token) {
       rewritten = true;
-      token = pstr(rel_path).str();
+      token = util::pstr(rel_path);
     }
   }
 
index fc842f3bc49685d4495df886c0c8c7ea4c0e9a54..4a1b58b1081cfdedddcbd30f8ad13be20df1d82a 100644 (file)
@@ -18,8 +18,8 @@
 
 #pragma once
 
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/conversion.hpp>
+#include <ccache/util/path.hpp>
 
 #include <blake3.h>
 #include <nonstd/span.hpp>
@@ -133,6 +133,6 @@ Hash::hash(const std::string& data)
 inline Hash&
 Hash::hash(const std::filesystem::path& path)
 {
-  hash(util::PathString(path).str());
+  hash(util::pstr(path));
   return *this;
 }
index b9fe27e538343394e9c6a63ea19fe5dda20c002e..2a335a9892a4f8d93e7b4d8c80126a9b1588a615 100644 (file)
 #include <ccache/util/DirEntry.hpp>
 #include <ccache/util/Fd.hpp>
 #include <ccache/util/Finalizer.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/TemporaryFile.hpp>
 #include <ccache/util/conversion.hpp>
 #include <ccache/util/file.hpp>
 #include <ccache/util/filesystem.hpp>
 #include <ccache/util/format.hpp>
 #include <ccache/util/logging.hpp>
+#include <ccache/util/path.hpp>
 
 #include <fcntl.h>
 
@@ -54,8 +54,6 @@
 
 namespace fs = util::filesystem;
 
-using pstr = util::PathString;
-
 // The inode cache resides on a file that is mapped into shared memory by
 // running processes. It is implemented as a two level structure, where the top
 // level is a hash table consisting of buckets. Each bucket contains entries
@@ -380,7 +378,8 @@ InodeCache::create_new_file(const std::string& filename)
     return false;
   }
 
-  util::Finalizer temp_file_remover([&] { unlink(pstr(tmp_file->path)); });
+  util::Finalizer temp_file_remover(
+    [&] { unlink(util::pstr(tmp_file->path).c_str()); });
 
   if (!fd_is_on_known_to_work_file_system(*tmp_file->fd)) {
     return false;
index 491e315ca86b3556448d12059329c963b7564c0a..876123e8ecdf0938750bb8f88c512398fa6e01ef 100644 (file)
@@ -26,7 +26,6 @@
 #include <ccache/core/common.hpp>
 #include <ccache/language.hpp>
 #include <ccache/util/DirEntry.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/Tokenizer.hpp>
 #include <ccache/util/assertions.hpp>
 #include <ccache/util/filesystem.hpp>
@@ -54,7 +53,6 @@ namespace fs = util::filesystem;
 
 using core::Statistic;
 using util::DirEntry;
-using pstr = util::PathString;
 
 namespace {
 
@@ -178,7 +176,7 @@ detect_pch(const std::string& option,
       fs::path file = fs::path(arg).replace_extension(".pch");
       if (fs::is_regular_file(file)) {
         LOG("Detected use of precompiled header: {}", file);
-        pch_file = pstr(file).str();
+        pch_file = util::pstr(file);
       }
     }
   } else if (option == "-Fp") {
@@ -267,7 +265,7 @@ process_profiling_option(const Context& ctx,
       new_profile_path = ".";
     } else {
       // GCC uses $PWD/$(basename $obj).
-      new_profile_path = pstr(ctx.apparent_cwd).str();
+      new_profile_path = util::pstr(ctx.apparent_cwd);
     }
   } else if (util::starts_with(arg, "-fprofile-generate=")
              || util::starts_with(arg, "-fprofile-instr-generate=")) {
@@ -776,7 +774,7 @@ process_option_arg(const Context& ctx,
     if (state.output_dep_origin <= OutputDepOrigin::mf) {
       state.output_dep_origin = OutputDepOrigin::mf;
       args_info.output_dep =
-        pstr(core::make_relative_path(ctx, dep_file)).str();
+        util::pstr(core::make_relative_path(ctx, dep_file));
     }
     // Keep the format of the args the same.
     if (separate_argument) {
@@ -921,7 +919,7 @@ process_option_arg(const Context& ctx,
     }
     state.common_args.push_back(args[i]);
     auto relpath = core::make_relative_path(ctx, args[i + 1]);
-    state.common_args.push_back(pstr(relpath).str());
+    state.common_args.push_back(util::pstr(relpath));
     i++;
     return Statistic::none;
   }
@@ -1014,7 +1012,7 @@ process_option_arg(const Context& ctx,
     }
     args_info.generating_diagnostics = true;
     args_info.output_dia =
-      pstr(core::make_relative_path(ctx, args[i + 1])).str();
+      util::pstr(core::make_relative_path(ctx, args[i + 1]));
     i++;
     return Statistic::none;
   }
@@ -1129,7 +1127,7 @@ process_option_arg(const Context& ctx,
     if (next == 2) {
       dest_args.push_back(args[i + 1]);
     }
-    dest_args.push_back(pstr(relpath).str());
+    dest_args.push_back(util::pstr(relpath));
 
     i += next;
     return Statistic::none;
@@ -1300,7 +1298,7 @@ process_args(Context& ctx)
     if (is_link) {
       LOG_RAW("Called for link");
       return tl::unexpected(
-        pstr(state.input_files.front()).str().find("conftest.")
+        util::pstr(state.input_files.front()).str().find("conftest.")
             != std::string::npos
           ? Statistic::autoconf_test
           : Statistic::called_for_link);
@@ -1310,10 +1308,10 @@ process_args(Context& ctx)
     }
   }
 
-  args_info.orig_input_file = pstr(state.input_files.front()).str();
+  args_info.orig_input_file = util::pstr(state.input_files.front());
   // Rewrite to relative to increase hit rate.
   args_info.input_file =
-    pstr(core::make_relative_path(ctx, args_info.orig_input_file)).str();
+    util::pstr(core::make_relative_path(ctx, args_info.orig_input_file));
 
   // Bail out on too hard combinations of options.
   if (state.found_mf_opt && state.found_wp_md_or_mmd_opt) {
@@ -1359,15 +1357,13 @@ process_args(Context& ctx)
     } else {
       extension = get_default_object_file_extension(ctx.config);
     }
-    args_info.output_obj +=
-      pstr(
-        fs::path(args_info.input_file).filename().replace_extension(extension))
-        .str();
+    args_info.output_obj += util::pstr(
+      fs::path(args_info.input_file).filename().replace_extension(extension));
   }
 
   args_info.orig_output_obj = args_info.output_obj;
   args_info.output_obj =
-    pstr(core::make_relative_path(ctx, args_info.output_obj)).str();
+    util::pstr(core::make_relative_path(ctx, args_info.output_obj));
 
   // Determine a filepath for precompiled header.
   if (ctx.config.is_compiler_group_msvc() && args_info.generating_pch) {
@@ -1382,11 +1378,10 @@ process_args(Context& ctx)
     }
 
     if (included_pch_file_by_source && !args_info.input_file.empty()) {
-      args_info.included_pch_file =
-        pstr(fs::path(args_info.input_file)
-               .filename()
-               .replace_extension(get_default_pch_file_extension(ctx.config)))
-          .str();
+      args_info.included_pch_file = util::pstr(
+        fs::path(args_info.input_file)
+          .filename()
+          .replace_extension(get_default_pch_file_extension(ctx.config)));
       LOG(
         "Setting PCH filepath from the base source file (during generating): "
         "{}",
@@ -1437,7 +1432,7 @@ process_args(Context& ctx)
   }
 
   if (args_info.profile_path.empty()) {
-    args_info.profile_path = pstr(ctx.apparent_cwd).str();
+    args_info.profile_path = util::pstr(ctx.apparent_cwd);
   }
 
   if (!state.explicit_language.empty() && state.explicit_language == "none") {
@@ -1462,7 +1457,7 @@ process_args(Context& ctx)
     args_info.orig_output_obj =
       args_info.orig_input_file + get_default_pch_file_extension(config);
     args_info.output_obj =
-      pstr(core::make_relative_path(ctx, args_info.orig_output_obj)).str();
+      util::pstr(core::make_relative_path(ctx, args_info.orig_output_obj));
   }
 
   if (args_info.output_is_precompiled_header
@@ -1525,7 +1520,7 @@ process_args(Context& ctx)
       args_info.seen_split_dwarf = false;
     } else {
       args_info.output_dwo =
-        pstr(fs::path(args_info.output_obj).replace_extension(".dwo")).str();
+        util::pstr(fs::path(args_info.output_obj).replace_extension(".dwo"));
     }
   }
 
@@ -1587,7 +1582,7 @@ process_args(Context& ctx)
   if (args_info.generating_dependencies) {
     if (state.output_dep_origin == OutputDepOrigin::none) {
       args_info.output_dep =
-        pstr(fs::path(args_info.output_obj).replace_extension(".d")).str();
+        util::pstr(fs::path(args_info.output_obj).replace_extension(".d"));
       if (!config.run_second_cpp()) {
         // If we're compiling preprocessed code we're sending dep_args to the
         // preprocessor so we need to use -MF to write to the correct .d file
@@ -1642,19 +1637,19 @@ process_args(Context& ctx)
     std::string default_sufile_name =
       fs::path(args_info.output_obj).replace_extension(".su").string();
     args_info.output_su =
-      pstr(core::make_relative_path(ctx, default_sufile_name)).str();
+      util::pstr(core::make_relative_path(ctx, default_sufile_name));
   }
 
   if (args_info.generating_callgraphinfo) {
     std::string default_cifile_name =
       fs::path(args_info.output_obj).replace_extension(".ci").string();
     args_info.output_ci =
-      pstr(core::make_relative_path(ctx, default_cifile_name)).str();
+      util::pstr(core::make_relative_path(ctx, default_cifile_name));
   }
 
   if (args_info.generating_ipa_clones) {
     fs::path ipa_path(args_info.orig_input_file + ".000i.ipa-clones");
-    args_info.output_ipa = pstr(core::make_relative_path(ctx, ipa_path)).str();
+    args_info.output_ipa = util::pstr(core::make_relative_path(ctx, ipa_path));
   }
 
   Args compiler_args = state.common_args;
index e1dd3186cd85ab2f3e1b5df17298eb999d650f66..7fb74df4af05f3f019d407806b2dd464b661a22c 100644 (file)
@@ -50,7 +50,6 @@
 #include <ccache/util/Fd.hpp>
 #include <ccache/util/FileStream.hpp>
 #include <ccache/util/Finalizer.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/TemporaryFile.hpp>
 #include <ccache/util/TimePoint.hpp>
 #include <ccache/util/Tokenizer.hpp>
@@ -97,7 +96,6 @@ namespace fs = util::filesystem;
 
 using core::Statistic;
 using util::DirEntry;
-using pstr = util::PathString;
 
 // This is a string that identifies the current "version" of the hash sum
 // computed by ccache. If, for any reason, we want to force the hash sum to be
@@ -166,7 +164,7 @@ Failure::set_exit_code(const int exit_code)
 } // namespace
 
 static bool
-should_disable_ccache_for_input_file(const std::string& path)
+should_disable_ccache_for_input_file(const fs::path& path)
 {
   auto content =
     util::read_file_part<std::string>(path, 0, k_ccache_disable_search_limit);
@@ -231,7 +229,7 @@ prepare_debug_path(const fs::path& cwd,
              static_cast<long long unsigned int>(time_of_invocation.sec()));
   }
   return FMT("{}.{}_{:06}.ccache-{}",
-             pstr(prefix).str(),
+             prefix,
              timestamp,
              time_of_invocation.nsec_decimal_part() / 1000,
              suffix);
@@ -289,7 +287,7 @@ static CompilerType
 do_guess_compiler(const fs::path& path)
 {
   const auto name =
-    util::to_lowercase(pstr(path.filename().replace_extension("")).str());
+    util::to_lowercase(util::pstr(path.filename().replace_extension("")).str());
   if (name.find("clang-cl") != std::string_view::npos) {
     return CompilerType::clang_cl;
   } else if (name.find("clang") != std::string_view::npos) {
@@ -581,9 +579,9 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path)
         auto it = relative_inc_path_cache.find(inc_path);
         if (it == relative_inc_path_cache.end()) {
           std::string rel_inc_path =
-            pstr(core::make_relative_path(ctx, inc_path)).str();
+            util::pstr(core::make_relative_path(ctx, inc_path));
           relative_inc_path_cache.emplace(inc_path, rel_inc_path);
-          inc_path = pstr(rel_inc_path).str();
+          inc_path = util::pstr(rel_inc_path);
         } else {
           inc_path = it->second;
         }
@@ -641,8 +639,8 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path)
   // mention of it in the preprocessed output.
   if (!ctx.args_info.included_pch_file.empty()
       && !ctx.args_info.generating_pch) {
-    std::string pch_path =
-      pstr(core::make_relative_path(ctx, ctx.args_info.included_pch_file));
+    std::string pch_path = util::pstr(
+      core::make_relative_path(ctx, ctx.args_info.included_pch_file));
     hash.hash(pch_path);
     TRY(remember_include_file(ctx, pch_path, hash, false, nullptr));
   }
@@ -682,7 +680,7 @@ result_key_from_depfile(Context& ctx, Hash& hash)
     }
     if (seen_colon) {
       fs::path path = core::make_relative_path(ctx, token);
-      TRY(remember_include_file(ctx, pstr(path), hash, false, &hash));
+      TRY(remember_include_file(ctx, util::pstr(path), hash, false, &hash));
     } else if (token == ":") {
       seen_colon = true;
     }
@@ -695,7 +693,7 @@ result_key_from_depfile(Context& ctx, Hash& hash)
     fs::path pch_path =
       core::make_relative_path(ctx, ctx.args_info.included_pch_file);
     hash.hash(pch_path);
-    TRY(remember_include_file(ctx, pstr(pch_path), hash, false, nullptr));
+    TRY(remember_include_file(ctx, util::pstr(pch_path), hash, false, nullptr));
   }
 
   bool debug_included = getenv("CCACHE_DEBUG_INCLUDED");
@@ -721,7 +719,7 @@ get_tmp_fd(Context& ctx,
     auto tmp_stdout =
       util::value_or_throw<core::Fatal>(util::TemporaryFile::create(
         FMT("{}/{}", ctx.config.temporary_dir(), description)));
-    ctx.register_pending_tmp_file(pstr(tmp_stdout.path));
+    ctx.register_pending_tmp_file(util::pstr(tmp_stdout.path));
     return {std::move(tmp_stdout.fd), std::move(tmp_stdout.path)};
   } else {
     const auto dev_null_path = util::get_dev_null_path();
@@ -744,7 +742,7 @@ result_key_from_includes(Context& ctx, Hash& hash, std::string_view stdout_data)
   for (std::string_view include : core::MsvcShowIncludesOutput::get_includes(
          stdout_data, ctx.config.msvc_dep_prefix())) {
     const fs::path path = core::make_relative_path(ctx, include);
-    TRY(remember_include_file(ctx, pstr(path), hash, false, &hash));
+    TRY(remember_include_file(ctx, util::pstr(path), hash, false, &hash));
   }
 
   // Explicitly check the .pch file as it is not mentioned in the
@@ -754,7 +752,7 @@ result_key_from_includes(Context& ctx, Hash& hash, std::string_view stdout_data)
     fs::path pch_path =
       core::make_relative_path(ctx, ctx.args_info.included_pch_file);
     hash.hash(pch_path);
-    TRY(remember_include_file(ctx, pstr(pch_path), hash, false, nullptr));
+    TRY(remember_include_file(ctx, util::pstr(pch_path), hash, false, nullptr));
   }
 
   const bool debug_included = getenv("CCACHE_DEBUG_INCLUDED");
@@ -1051,7 +1049,7 @@ rewrite_stdout_from_compiler(const Context& ctx, util::Bytes&& stdout_data)
         abs_inc_path = util::strip_whitespace(abs_inc_path);
         fs::path rel_inc_path = core::make_relative_path(ctx, abs_inc_path);
         std::string line_with_rel_inc = util::replace_first(
-          orig_line, abs_inc_path, pstr(rel_inc_path).str());
+          orig_line, abs_inc_path, util::pstr(rel_inc_path).str());
         new_stdout_data.insert(new_stdout_data.end(),
                                line_with_rel_inc.data(),
                                line_with_rel_inc.size());
@@ -1523,7 +1521,7 @@ hash_common_info(const Context& ctx,
 
   // Possibly hash the current working directory.
   if (args_info.generating_debuginfo && ctx.config.hash_dir()) {
-    std::string dir_to_hash = pstr(ctx.apparent_cwd).str();
+    std::string dir_to_hash = util::pstr(ctx.apparent_cwd);
     for (const auto& map : args_info.debug_prefix_maps) {
       size_t sep_pos = map.find('=');
       if (sep_pos != std::string::npos) {
@@ -1533,9 +1531,10 @@ hash_common_info(const Context& ctx,
             old_path,
             new_path,
             ctx.apparent_cwd);
-        if (util::starts_with(pstr(ctx.apparent_cwd), old_path)) {
+        if (util::starts_with(util::pstr(ctx.apparent_cwd).str(), old_path)) {
           dir_to_hash =
-            new_path + pstr(ctx.apparent_cwd).str().substr(old_path.size());
+            new_path
+            + util::pstr(ctx.apparent_cwd).str().substr(old_path.size());
         }
       }
     }
@@ -1551,7 +1550,7 @@ hash_common_info(const Context& ctx,
     const std::string output_obj_dir =
       fs::path(args_info.output_obj).is_absolute()
         ? fs::path(args_info.output_obj).parent_path().string()
-        : pstr(ctx.actual_cwd);
+        : util::pstr(ctx.actual_cwd);
     LOG("Hashing object file directory {}", output_obj_dir);
     hash.hash_delimiter("source path");
     hash.hash(output_obj_dir);
@@ -1564,7 +1563,7 @@ hash_common_info(const Context& ctx,
     // base name would be enough.
     LOG_RAW("Hashing object filename due to -gsplit-dwarf");
     hash.hash_delimiter("object file");
-    hash.hash(pstr(fs::path(ctx.args_info.output_obj).filename()).str());
+    hash.hash(util::pstr(fs::path(ctx.args_info.output_obj).filename()));
   }
 
   if (ctx.args_info.profile_arcs) {
@@ -1964,8 +1963,8 @@ hash_profile_data_file(const Context& ctx, Hash& hash)
 {
   const std::string& profile_path = ctx.args_info.profile_path;
   const std::string base_name =
-    pstr(fs::path(ctx.args_info.output_obj).replace_extension("")).str();
-  std::string hashified_cwd = pstr(ctx.apparent_cwd).str();
+    util::pstr(fs::path(ctx.args_info.output_obj).replace_extension(""));
+  std::string hashified_cwd = util::pstr(ctx.apparent_cwd);
   std::replace(hashified_cwd.begin(), hashified_cwd.end(), '/', '#');
 
   std::vector<std::string> paths_to_try{
@@ -2791,7 +2790,7 @@ ccache_main(int argc, const char* const* argv)
       if (argc < 2) {
         PRINT_RAW(
           stderr,
-          core::get_usage_text(pstr(fs::path(argv[0]).filename()).str()));
+          core::get_usage_text(util::pstr(fs::path(argv[0]).filename()).str()));
         exit(EXIT_FAILURE);
       }
       // If the first argument isn't an option, then assume we are being
index ab368af876673b91820279409ced79b9805934d9..b0db5f97afed71deebe41d6bc3398aa577d0a269 100644 (file)
 #include "Statistics.hpp"
 
 #include <ccache/Config.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/TextTable.hpp>
 #include <ccache/util/format.hpp>
 #include <ccache/util/logging.hpp>
+#include <ccache/util/path.hpp>
 #include <ccache/util/string.hpp>
 #include <ccache/util/time.hpp>
 
@@ -30,7 +30,6 @@
 
 namespace core {
 
-using pstr = util::PathString;
 using core::Statistic;
 
 const unsigned FLAG_NOZERO = 1U << 0;      // don't zero with --zero-stats
@@ -392,9 +391,9 @@ Statistics::format_human_readable(const Config& config,
   if (verbosity > 0 && !from_log) {
     table.add_row({"Cache directory:", C(config.cache_dir()).colspan(4)});
     table.add_row(
-      {"Config file:", C(pstr(config.config_path()).str()).colspan(4)});
+      {"Config file:", C(util::pstr(config.config_path())).colspan(4)});
     table.add_row({"System config file:",
-                   C(pstr(config.system_config_path()).str()).colspan(4)});
+                   C(util::pstr(config.system_config_path())).colspan(4)});
     table.add_row(
       {"Stats updated:", C(format_timestamp(last_updated)).colspan(4)});
     if (verbosity > 1) {
index 487a26ee6a2678d712d17302311e866baa7885a9..31862155bee3071c284b9828975a03fd54e52843 100644 (file)
 
 #include <ccache/core/Statistics.hpp>
 #include <ccache/util/FileStream.hpp>
+#include <ccache/util/filesystem.hpp>
 #include <ccache/util/format.hpp>
 #include <ccache/util/logging.hpp>
+#include <ccache/util/path.hpp>
 
 #include <cstring>
 #include <fstream>
 
+namespace fs = util::filesystem;
+
 namespace core {
 
 StatisticsCounters
@@ -54,7 +58,7 @@ StatsLog::read() const
 }
 
 void
-StatsLog::log_result(const std::string& input_file,
+StatsLog::log_result(const fs::path& input_file,
                      const std::vector<std::string>& result_ids)
 {
   util::FileStream file(m_path, "ab");
index a8ed9b1c69c22e0657b55ec3e09aa91b68ed1310..f85652e67065b291526e1c8b39cf6250af5e2152 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2021-2023 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2024 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -20,6 +20,7 @@
 
 #include "StatisticsCounters.hpp"
 
+#include <filesystem>
 #include <string>
 #include <vector>
 
@@ -28,19 +29,19 @@ namespace core {
 class StatsLog
 {
 public:
-  explicit StatsLog(const std::string& path);
+  explicit StatsLog(const std::filesystem::path& path);
 
   StatisticsCounters read() const;
-  void log_result(const std::string& input_file,
+  void log_result(const std::filesystem::path& input_file,
                   const std::vector<std::string>& result_ids);
 
 private:
-  const std::string m_path;
+  std::filesystem::path m_path;
 };
 
 // --- Inline implementations ---
 
-inline StatsLog::StatsLog(const std::string& path) : m_path(path)
+inline StatsLog::StatsLog(const std::filesystem::path& path) : m_path(path)
 {
 }
 
index a716b54486bc7a20b79345069a565360e503b0e7..eddb7866c1a4ed3570b0e2973a438910d584126a 100644 (file)
@@ -21,7 +21,6 @@
 #include <ccache/Context.hpp>
 #include <ccache/core/exceptions.hpp>
 #include <ccache/util/Finalizer.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/Tokenizer.hpp>
 #include <ccache/util/expected.hpp>
 #include <ccache/util/file.hpp>
@@ -30,7 +29,6 @@
 #include <ccache/util/path.hpp>
 
 using IncludeDelimiter = util::Tokenizer::IncludeDelimiter;
-using pstr = util::PathString;
 
 namespace fs = util::filesystem;
 
@@ -117,7 +115,7 @@ rewrite_stderr_to_absolute_paths(std::string_view text)
       result.append(line.data(), line.length());
     } else {
       fs::path path(line.substr(0, path_end));
-      result += pstr(fs::canonical(path).value_or(path)).str();
+      result += util::pstr(fs::canonical(path).value_or(path));
       auto tail = line.substr(path_end);
       result.append(tail.data(), tail.length());
     }
index ea1845409860440b0349f2b20b2f89654da9b02b..7faaddd8dc9b1f54f421e0634f2b5fcd17621f36 100644 (file)
@@ -36,7 +36,6 @@
 #include <ccache/storage/local/LocalStorage.hpp>
 #include <ccache/util/Fd.hpp>
 #include <ccache/util/FileStream.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/TemporaryFile.hpp>
 #include <ccache/util/TextTable.hpp>
 #include <ccache/util/ThreadPool.hpp>
@@ -50,6 +49,7 @@
 #include <ccache/util/filesystem.hpp>
 #include <ccache/util/format.hpp>
 #include <ccache/util/logging.hpp>
+#include <ccache/util/path.hpp>
 #include <ccache/util/string.hpp>
 
 #include <fcntl.h>
@@ -76,7 +76,6 @@
 namespace fs = util::filesystem;
 
 using util::DirEntry;
-using pstr = util::PathString;
 
 namespace core {
 
@@ -721,7 +720,7 @@ process_main_options(int argc, const char* const* argv)
     case 'F': { // --max-files
       auto files = util::value_or_throw<Error>(util::parse_unsigned(arg));
       config.set_value_in_file(
-        pstr(config.config_path()).str(), "max_files", arg);
+        util::pstr(config.config_path()), "max_files", arg);
       if (files == 0) {
         PRINT_RAW(stdout, "Unset cache file limit\n");
       } else {
@@ -735,7 +734,7 @@ process_main_options(int argc, const char* const* argv)
         util::value_or_throw<Error>(util::parse_size(arg));
       uint64_t max_size = size;
       config.set_value_in_file(
-        pstr(config.config_path()).str(), "max_size", arg);
+        util::pstr(config.config_path()), "max_size", arg);
       if (max_size == 0) {
         PRINT_RAW(stdout, "Unset cache size limit\n");
       } else {
@@ -755,7 +754,7 @@ process_main_options(int argc, const char* const* argv)
       }
       std::string key = arg.substr(0, eq_pos);
       std::string value = arg.substr(eq_pos + 1);
-      config.set_value_in_file(pstr(config.config_path()).str(), key, value);
+      config.set_value_in_file(util::pstr(config.config_path()), key, value);
       break;
     }
 
@@ -812,7 +811,8 @@ process_main_options(int argc, const char* const* argv)
 
     case 'V': // --version
     {
-      PRINT_RAW(stdout, get_version_text(pstr(fs::path(argv[0]).stem()).str()));
+      PRINT_RAW(stdout,
+                get_version_text(util::pstr(fs::path(argv[0]).stem()).str()));
       break;
     }
 
index ac875e726c2b4d0a7dd2d0508a93c302b9e0c724..484820a8c9288bb530540dc69bbe4f92143ce2a7 100644 (file)
@@ -27,7 +27,6 @@
 #include <ccache/util/DirEntry.hpp>
 #include <ccache/util/Fd.hpp>
 #include <ccache/util/Finalizer.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/TemporaryFile.hpp>
 #include <ccache/util/error.hpp>
 #include <ccache/util/expected.hpp>
@@ -55,8 +54,6 @@
 
 namespace fs = util::filesystem;
 
-using pstr = util::PathString;
-
 #ifdef _WIN32
 static int win32execute(const char* path,
                         const char* const* argv,
@@ -92,9 +89,9 @@ win32getshell(const std::string& path)
 {
   const char* path_list = getenv("PATH");
   std::string sh;
-  if (util::to_lowercase(pstr(fs::path(path).extension()).str()) == ".sh"
+  if (util::to_lowercase(util::pstr(fs::path(path).extension()).str()) == ".sh"
       && path_list) {
-    sh = pstr(find_executable_in_path("sh.exe", path_list)).str();
+    sh = util::pstr(find_executable_in_path("sh.exe", path_list));
   }
   if (sh.empty() && getenv("CCACHE_DETECT_SHEBANG")) {
     // Detect shebang.
@@ -103,7 +100,7 @@ win32getshell(const std::string& path)
       char buf[10] = {0};
       fgets(buf, sizeof(buf) - 1, fp.get());
       if (std::string(buf) == "#!/bin/sh" && path_list) {
-        sh = pstr(find_executable_in_path("sh.exe", path_list)).str();
+        sh = util::pstr(find_executable_in_path("sh.exe", path_list));
       }
     }
   }
index a51c9001013a0f565a39d2c3cb281a0e6abf0789..867b428738277ae5c6fb66e782383c85ad7d94e7 100644 (file)
@@ -39,6 +39,7 @@
 #include <ccache/util/filesystem.hpp>
 #include <ccache/util/format.hpp>
 #include <ccache/util/logging.hpp>
+#include <ccache/util/path.hpp>
 #include <ccache/util/process.hpp>
 #include <ccache/util/string.hpp>
 #include <ccache/util/wincompat.hpp>
@@ -89,8 +90,6 @@ using core::Statistic;
 using core::StatisticsCounters;
 using util::DirEntry;
 
-using pstr = util::PathString;
-
 namespace storage::local {
 
 // How often (in seconds) to scan $CCACHE_DIR/tmp for left-over temporary
@@ -350,10 +349,10 @@ clean_dir(
     }
 
     if (namespace_ && file_type_from_path(file.path()) == FileType::raw) {
-      auto path_str = pstr(file.path());
+      util::PathString path_str(file.path());
       const auto result_filename =
         FMT("{}R", path_str.str().substr(0, path_str.str().length() - 2));
-      raw_files_map[result_filename].push_back(pstr(file.path()).str());
+      raw_files_map[result_filename].push_back(util::pstr(file.path()));
     }
 
     cache_size += file.size_on_disk();
@@ -401,7 +400,7 @@ clean_dir(
       // For namespace eviction we need to remove raw files based on result
       // filename since they don't have a header.
       if (file_type_from_path(file.path()) == FileType::result) {
-        const auto entry = raw_files_map.find(pstr(file.path()));
+        const auto entry = raw_files_map.find(util::pstr(file.path()));
         if (entry != raw_files_map.end()) {
           for (const auto& raw_file : entry->second) {
             delete_file(DirEntry(raw_file), cache_size, files_in_cache);
@@ -429,7 +428,7 @@ clean_dir(
 FileType
 file_type_from_path(const fs::path& path)
 {
-  std::string filename = pstr(path.filename()).str();
+  std::string filename = util::pstr(path.filename());
   if (util::ends_with(filename, "M")) {
     return FileType::manifest;
   } else if (util::ends_with(filename, "R")) {
index 00469e887a7c3604a055ae4f8ebec1c70ff8b271..da14b3d296770d0a1a81afc38fb17b0527d4191d 100644 (file)
 #include "util.hpp"
 
 #include <ccache/core/exceptions.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/expected.hpp>
 #include <ccache/util/file.hpp>
 #include <ccache/util/format.hpp>
+#include <ccache/util/path.hpp>
 #include <ccache/util/string.hpp>
 
 using util::DirEntry;
-using pstr = util::PathString;
 
 namespace storage::local {
 
@@ -75,7 +74,7 @@ get_cache_dir_files(const std::string& dir)
   }
   util::throw_on_error<core::Error>(
     util::traverse_directory(dir, [&](const auto& de) {
-      std::string name = pstr(de.path().filename()).str();
+      std::string name = util::pstr(de.path().filename());
       if (name == "CACHEDIR.TAG" || name == "stats"
           || util::starts_with(name, ".nfs")) {
         return;
index 967624b9cabffb02f1b1ea27982a29b27c4ce775..873a5e0228447077727fef20e17444692c8a9ce3 100644 (file)
@@ -31,8 +31,6 @@
 
 #include <cstring>
 
-using pstr = util::PathString;
-
 namespace {
 
 #ifdef _WIN32
@@ -268,8 +266,8 @@ DirEntry::do_stat() const
   } else
 #endif
   {
-    auto mpath = pstr(m_path);
-    result = lstat_func(mpath, &m_stat);
+    util::PathString mpath(m_path);
+    result = lstat_func(mpath.c_str(), &m_stat);
     if (result == 0) {
       if (S_ISLNK(m_stat.st_mode)
 #ifdef _WIN32
@@ -278,7 +276,7 @@ DirEntry::do_stat() const
       ) {
         m_is_symlink = true;
         stat_t st;
-        if (stat_func(mpath, &st) == 0) {
+        if (stat_func(mpath.c_str(), &st) == 0) {
           m_stat = st;
           m_exists = true;
         }
index d91e9c76d796db86953c15911df13757a589ee45..8045472f2cc14f13c8062e2b97652c4f4be43ee8 100644 (file)
@@ -19,9 +19,9 @@
 #pragma once
 
 #include <ccache/util/NonCopyable.hpp>
+#include <ccache/util/path.hpp>
 
 #include <cstdio>
-#include <string>
 
 namespace util {
 
@@ -30,13 +30,13 @@ class FileStream : util::NonCopyable
 public:
   FileStream() = default;
   explicit FileStream(FILE* file);
-  FileStream(const std::string& path, const char* mode);
+  FileStream(const std::filesystem::path& path, const char* mode);
   FileStream(FileStream&& other) noexcept;
   ~FileStream();
 
   FileStream& operator=(FileStream&& other) noexcept;
 
-  void open(const std::string& path, const char* mode);
+  void open(const std::filesystem::path& path, const char* mode);
   void close();
 
   operator bool() const;
@@ -52,7 +52,8 @@ inline FileStream::FileStream(FILE* const file) : m_file(file), m_owned(false)
 {
 }
 
-inline FileStream::FileStream(const std::string& path, const char* mode)
+inline FileStream::FileStream(const std::filesystem::path& path,
+                              const char* mode)
 {
   open(path, mode);
 }
@@ -81,10 +82,10 @@ FileStream::operator=(FileStream&& other) noexcept
 }
 
 inline void
-FileStream::open(const std::string& path, const char* mode)
+FileStream::open(const std::filesystem::path& path, const char* mode)
 {
   close();
-  m_file = fopen(path.c_str(), mode);
+  m_file = fopen(util::pstr(path).c_str(), mode);
   m_owned = true;
 }
 
index 2767dd0b5e7a4582ee8166a7e4bd1aa2ead60295..6d7e297d3dca050e32e09cbb70043d489f7e3877 100644 (file)
 #include "LockFile.hpp"
 
 #include <ccache/util/DirEntry.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/assertions.hpp>
 #include <ccache/util/error.hpp>
 #include <ccache/util/file.hpp>
 #include <ccache/util/filesystem.hpp>
 #include <ccache/util/format.hpp>
 #include <ccache/util/logging.hpp>
+#include <ccache/util/path.hpp>
 #include <ccache/util/process.hpp>
 #include <ccache/util/wincompat.hpp>
 
@@ -49,8 +49,6 @@ const util::Duration k_staleness_limit(2);
 
 namespace fs = util::filesystem;
 
-using pstr = util::PathString;
-
 namespace {
 
 class RandomNumberGenerator
@@ -79,9 +77,9 @@ private:
 namespace util {
 
 LockFile::LockFile(const fs::path& path)
-  : m_lock_file(pstr(path).str() + ".lock"),
+  : m_lock_file(util::pstr(path).str() + ".lock"),
 #ifndef _WIN32
-    m_alive_file(pstr(path).str() + ".alive"),
+    m_alive_file(util::pstr(path).str() + ".alive"),
     m_acquired(false)
 #else
     m_handle(INVALID_HANDLE_VALUE)
@@ -388,7 +386,7 @@ LockFile::do_acquire(const bool blocking)
 
   while (true) {
     DWORD flags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE;
-    handle = CreateFile(pstr(m_lock_file),
+    handle = CreateFile(util::pstr(m_lock_file).c_str(),
                         GENERIC_WRITE, // desired access
                         0,             // shared mode (0 = not shared)
                         nullptr,       // security attributes
index a215566d29ff780f7f01841b67e09ef76be88693..f4dc94b36f6bb86619a3363b53d3d85714117821 100644 (file)
@@ -32,7 +32,6 @@ public:
   PathString(const std::filesystem::path& path);
 
   operator const std::string&() const;
-  operator const char*() const;
 
   const std::string& str() const;
   const char* c_str() const;
@@ -59,11 +58,6 @@ inline PathString::operator const std::string&() const
   return str();
 }
 
-inline PathString::operator const char*() const
-{
-  return c_str();
-}
-
 inline const std::string&
 PathString::str() const
 {
index 80d838f39ce80e8ee0ee503d969ecf0383a03182..00d9781530f89dc4d1e1a45d5233acd8606b7ceb 100644 (file)
 
 #include "TemporaryFile.hpp"
 
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/file.hpp>
 #include <ccache/util/filesystem.hpp>
 #include <ccache/util/format.hpp>
+#include <ccache/util/path.hpp>
 #include <ccache/util/process.hpp>
 
 #include <cstdlib>
@@ -36,8 +36,6 @@
 
 namespace fs = util::filesystem;
 
-using pstr = util::PathString;
-
 namespace util {
 
 TemporaryFile::TemporaryFile(Fd&& fd_, const fs::path& path_)
@@ -84,7 +82,8 @@ TemporaryFile::create(const fs::path& path_prefix, std::string_view suffix)
 bool
 TemporaryFile::is_tmp_file(const fs::path& path)
 {
-  return pstr(path.filename()).str().find(tmp_file_infix) != std::string::npos;
+  return util::pstr(path.filename()).str().find(tmp_file_infix)
+         != std::string::npos;
 }
 
 } // namespace util
index 2af76f6c3ad713e458a1ca658ed4298f64c869b1..90aa54cb77d3c326333938b7832d052a9fd4bc08 100644 (file)
@@ -30,6 +30,7 @@
 #include <ccache/util/filesystem.hpp>
 #include <ccache/util/format.hpp>
 #include <ccache/util/logging.hpp>
+#include <ccache/util/path.hpp>
 
 #ifdef __APPLE__
 #  include <copyfile.h>
@@ -76,8 +77,6 @@
 
 namespace fs = util::filesystem;
 
-using pstr = util::PathString;
-
 namespace util {
 
 #ifdef _WIN32
@@ -97,7 +96,7 @@ copy_file_impl(const fs::path& src,
     tmp_file = std::move(temp_file->path);
     dst_cstr = tmp_file.c_str();
   }
-  unlink(pstr(dest));
+  unlink(util::pstr(dest).c_str());
   if (!CopyFileExW(src.c_str(), dst_cstr, nullptr, nullptr, nullptr, 0)) {
     return tl::unexpected(
       FMT("Failed to copy {} to {}: {}", src, dest, strerror(errno)));
@@ -121,13 +120,13 @@ copy_file_impl(const fs::path& src,
                ViaTmpFile via_tmp_file,
                fs::path& tmp_file)
 {
-  Fd src_fd(open(pstr(src), O_RDONLY | O_BINARY));
+  Fd src_fd(open(util::pstr(src).c_str(), O_RDONLY | O_BINARY));
   if (!src_fd) {
     return tl::unexpected(
       FMT("Failed to open {} for reading: {}", src, strerror(errno)));
   }
 
-  unlink(pstr(dest));
+  unlink(util::pstr(dest).c_str());
 
   Fd dst_fd;
   if (via_tmp_file == ViaTmpFile::yes) {
@@ -138,8 +137,8 @@ copy_file_impl(const fs::path& src,
     dst_fd = std::move(temp_file->fd);
     tmp_file = std::move(temp_file->path);
   } else {
-    dst_fd =
-      Fd(open(pstr(dest), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
+    dst_fd = Fd(open(
+      util::pstr(dest).c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
     if (!dst_fd) {
       return tl::unexpected(
         FMT("Failed to open {} for writing: {}", dest, strerror(errno)));
@@ -325,7 +324,7 @@ read_file(const fs::path& path, size_t size_hint)
       return O_RDONLY | O_BINARY;
     }
   }();
-  Fd fd(open(pstr(path), open_flags));
+  Fd fd(open(util::pstr(path).c_str(), open_flags));
   if (!fd) {
     return tl::unexpected(strerror(errno));
   }
@@ -436,7 +435,7 @@ read_file_part(const fs::path& path, size_t pos, size_t count)
     return result;
   }
 
-  Fd fd(open(pstr(path), O_RDONLY | O_BINARY));
+  Fd fd(open(util::pstr(path).c_str(), O_RDONLY | O_BINARY));
   if (!fd) {
     LOG("Failed to open {}: {}", path, strerror(errno));
     return tl::unexpected(strerror(errno));
@@ -541,7 +540,8 @@ set_timestamps(const fs::path& path,
     atime_mtime[0] = (atime ? *atime : *mtime).to_timespec();
     atime_mtime[1] = mtime->to_timespec();
   }
-  utimensat(AT_FDCWD, pstr(path), mtime ? atime_mtime : nullptr, 0);
+  utimensat(
+    AT_FDCWD, util::pstr(path).c_str(), mtime ? atime_mtime : nullptr, 0);
 #elif defined(HAVE_UTIMES)
   timeval atime_mtime[2];
   if (mtime) {
@@ -551,15 +551,15 @@ set_timestamps(const fs::path& path,
     atime_mtime[1].tv_sec = mtime->sec();
     atime_mtime[1].tv_usec = mtime->nsec_decimal_part() / 1000;
   }
-  utimes(pstr(path), mtime ? atime_mtime : nullptr);
+  utimes(util::pstr(path).c_str(), mtime ? atime_mtime : nullptr);
 #else
   utimbuf atime_mtime;
   if (mtime) {
     atime_mtime.actime = atime ? atime->sec() : mtime->sec();
     atime_mtime.modtime = mtime->sec();
-    utime(pstr(path), &atime_mtime);
+    utime(util::pstr(path).c_str(), &atime_mtime);
   } else {
-    utime(pstr(path), nullptr);
+    utime(util::pstr(path).c_str(), nullptr);
   }
 #endif
 }
@@ -570,7 +570,7 @@ tl::expected<void, std::string>
 traverse_directory(const fs::path& directory,
                    const TraverseDirectoryVisitor& visitor)
 {
-  DIR* dir = opendir(pstr(directory));
+  DIR* dir = opendir(util::pstr(directory).c_str());
   if (!dir) {
     return tl::unexpected(
       FMT("Failed to traverse {}: {}", directory, strerror(errno)));
@@ -671,15 +671,15 @@ write_fd(int fd, const void* data, size_t size)
 tl::expected<void, std::string>
 write_file(const fs::path& path, std::string_view data, WriteFileMode mode)
 {
-  auto path_str = pstr(path);
+  util::PathString path_str(path);
   if (mode == WriteFileMode::unlink) {
-    unlink(path_str);
+    unlink(path_str.c_str());
   }
   int flags = O_WRONLY | O_CREAT | O_TRUNC | O_TEXT;
   if (mode == WriteFileMode::exclusive) {
     flags |= O_EXCL;
   }
-  Fd fd(open(path_str, flags, 0666));
+  Fd fd(open(path_str.c_str(), flags, 0666));
   if (!fd) {
     return tl::unexpected(strerror(errno));
   }
@@ -691,15 +691,15 @@ write_file(const fs::path& path,
            nonstd::span<const uint8_t> data,
            WriteFileMode mode)
 {
-  auto path_str = pstr(path);
+  util::PathString path_str(path);
   if (mode == WriteFileMode::unlink) {
-    unlink(path_str);
+    unlink(path_str.c_str());
   }
   int flags = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY;
   if (mode == WriteFileMode::exclusive) {
     flags |= O_EXCL;
   }
-  Fd fd(open(path_str, flags, 0666));
+  Fd fd(open(path_str.c_str(), flags, 0666));
   if (!fd) {
     return tl::unexpected(strerror(errno));
   }
index 824fa17dbb22b89bfbe3cc9dd5783868c00b8a35..0e89698242523cd57e0b1e35819cc998c7b081a9 100644 (file)
@@ -19,7 +19,6 @@
 #include "path.hpp"
 
 #include <ccache/util/DirEntry.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/filesystem.hpp>
 #include <ccache/util/format.hpp>
 #include <ccache/util/string.hpp>
@@ -32,8 +31,6 @@ const char k_dev_null_path[] = "/dev/null";
 
 namespace fs = util::filesystem;
 
-using pstr = util::PathString;
-
 namespace util {
 
 std::string
@@ -110,7 +107,8 @@ make_relative_path(const fs::path& actual_cwd,
   std::sort(relpath_candidates.begin(),
             relpath_candidates.end(),
             [](const auto& path1, const auto& path2) {
-              return pstr(path1).str().length() < pstr(path2).str().length();
+              return util::pstr(path1).str().length()
+                     < util::pstr(path2).str().length();
             });
   for (const auto& relpath : relpath_candidates) {
     if (fs::equivalent(relpath, closest_existing_path)) {
index 039c58a21e47939d4998fcc3b5ac04d9ba2c71d4..9a675db4badde3af69c47df6c2168c5c3fccae23 100644 (file)
@@ -18,6 +18,8 @@
 
 #pragma once
 
+#include <ccache/util/PathString.hpp>
+
 #include <filesystem>
 #include <string>
 #include <string_view>
@@ -71,6 +73,10 @@ make_path(const T&... args)
 bool path_starts_with(const std::filesystem::path& path,
                       const std::filesystem::path& prefix);
 
+// Access the underlying path string without having to copy it if
+// std::filesystem::path::value_type is char (that is, not wchar_t).
+using pstr = PathString;
+
 // --- Inline implementations ---
 
 inline bool
index 2576b082462b500877412cb5a5aa706dddec3ba2..27ebec8e77ae99e2ee6b76036229ba385f1ded66 100644 (file)
@@ -20,9 +20,9 @@
 
 #include <ccache/Context.hpp>
 #include <ccache/Depfile.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/filesystem.hpp>
 #include <ccache/util/format.hpp>
+#include <ccache/util/path.hpp>
 
 #include <doctest/doctest.h>
 
@@ -32,7 +32,6 @@
 namespace fs = util::filesystem;
 
 using TestUtil::TestContext;
-using pstr = util::PathString;
 
 TEST_SUITE_BEGIN("Depfile");
 
@@ -60,8 +59,8 @@ TEST_CASE("Depfile::rewrite_source_paths")
     "\n"
     " {0}/bar/bar.h: \n"
     " {1}/fie.h:\n",
-    Depfile::escape_filename(pstr(cwd).str()),
-    Depfile::escape_filename(pstr(cwd.parent_path()).str()));
+    Depfile::escape_filename(util::pstr(cwd).str()),
+    Depfile::escape_filename(util::pstr(cwd.parent_path()).str()));
 
   SUBCASE("Base directory not in dep file content")
   {
@@ -88,10 +87,10 @@ TEST_CASE("Depfile::rewrite_source_paths")
       " {1}/fie.h\n"
       "{2}:\n"
       "{1}/fie.h:\n",
-      Depfile::escape_filename(pstr(cwd).str()),
-      Depfile::escape_filename(pstr(cwd.parent_path()).str()),
+      Depfile::escape_filename(util::pstr(cwd).str()),
+      Depfile::escape_filename(util::pstr(cwd.parent_path()).str()),
       Depfile::escape_filename(
-        pstr(fs::path("bar/bar.h").lexically_normal()).str()));
+        util::pstr(fs::path("bar/bar.h").lexically_normal()).str()));
     REQUIRE(actual);
     CHECK(*actual == expected);
   }
index 6607343779813c2ea796ea9231e0b7e5c49ffe2f..441ddcf18938b96f5bdeaf7cb00e7eb76aa1f58d 100644 (file)
@@ -23,7 +23,6 @@
 #include <ccache/Hash.hpp>
 #include <ccache/InodeCache.hpp>
 #include <ccache/util/Fd.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/TemporaryFile.hpp>
 #include <ccache/util/file.hpp>
 #include <ccache/util/filesystem.hpp>
@@ -38,7 +37,6 @@
 namespace fs = util::filesystem;
 
 using TestUtil::TestContext;
-using pstr = util::PathString;
 
 namespace {
 
@@ -60,7 +58,7 @@ init(Config& config)
 {
   config.set_debug(true);
   config.set_inode_cache(true);
-  config.set_temporary_dir(pstr(*fs::current_path()).str());
+  config.set_temporary_dir(util::pstr(*fs::current_path()));
 }
 
 bool
index 57ef044b2a257e89cb7e14f56ba69530941e9c05..670a25121a3ce3473be83d5874f0f958013a05c4 100644 (file)
@@ -23,7 +23,6 @@
 #include <ccache/Context.hpp>
 #include <ccache/argprocessing.hpp>
 #include <ccache/core/Statistic.hpp>
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/file.hpp>
 #include <ccache/util/filesystem.hpp>
 #include <ccache/util/format.hpp>
@@ -39,7 +38,6 @@ namespace fs = util::filesystem;
 
 using core::Statistic;
 using TestUtil::TestContext;
-using pstr = util::PathString;
 
 namespace {
 
@@ -50,7 +48,8 @@ get_root()
   return "/";
 #else
   char volume[4]; // "C:\"
-  GetVolumePathName(pstr(*fs::current_path()).c_str(), volume, sizeof(volume));
+  GetVolumePathName(
+    util::pstr(*fs::current_path()).c_str(), volume, sizeof(volume));
   return volume;
 #endif
 }
index 76738ad82de6508bd0c4842a25a469e53d8c6ecd..4e4fbf160e9b67c088f299c168e75195372bc8e5 100644 (file)
@@ -18,7 +18,6 @@
 
 #include "TestUtil.hpp"
 
-#include <ccache/util/PathString.hpp>
 #include <ccache/util/environment.hpp>
 #include <ccache/util/filesystem.hpp>
 #include <ccache/util/format.hpp>
@@ -30,7 +29,6 @@
 
 namespace fs = util::filesystem;
 
-using pstr = util::PathString;
 using TestUtil::TestContext;
 
 TEST_CASE("util::add_exe_suffix")
@@ -71,7 +69,7 @@ TEST_CASE("util::make_relative_path")
 
   const TestContext test_context;
 
-  const std::string cwd = pstr(*fs::current_path()).str();
+  const std::string cwd = util::pstr(*fs::current_path());
   const std::string actual_cwd = FMT("{}/d", cwd);
 #if defined(_WIN32) || defined(__CYGWIN__)
   const std::string apparent_cwd = actual_cwd;