]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Convert ArgsInfo::profile_path to fs::path
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 6 Jun 2024 15:04:50 +0000 (17:04 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 30 Jun 2024 15:18:51 +0000 (17:18 +0200)
src/ccache/ArgsInfo.hpp
src/ccache/argprocessing.cpp
src/ccache/ccache.cpp

index d093982721f23d44a20a7b8733037d2adb45e390..64710658486ece4920985d1d84413bc3664101ff 100644 (file)
@@ -129,7 +129,7 @@ struct ArgsInfo
   bool profile_arcs = false;
 
   // Name of the custom profile directory or file.
-  std::string profile_path;
+  std::filesystem::path profile_path;
 
   // Profile generation / usage information.
   bool profile_use = false;
index 2473c9dc63c21d7e32a08cb01e817839d11ddee2..be335d1f3f050e015723bb550ac348bc06e41fe5 100644 (file)
@@ -254,7 +254,7 @@ process_profiling_option(const Context& ctx,
     return true;
   }
 
-  std::string new_profile_path;
+  std::filesystem::path new_profile_path;
   bool new_profile_use = false;
 
   if (util::starts_with(arg, "-fprofile-dir=")) {
@@ -265,7 +265,7 @@ process_profiling_option(const Context& ctx,
       new_profile_path = ".";
     } else {
       // GCC uses $PWD/$(basename $obj).
-      new_profile_path = util::pstr(ctx.apparent_cwd);
+      new_profile_path = ctx.apparent_cwd;
     }
   } else if (util::starts_with(arg, "-fprofile-generate=")
              || util::starts_with(arg, "-fprofile-instr-generate=")) {
@@ -1427,7 +1427,7 @@ process_args(Context& ctx)
   }
 
   if (args_info.profile_path.empty()) {
-    args_info.profile_path = util::pstr(ctx.apparent_cwd);
+    args_info.profile_path = ctx.apparent_cwd;
   }
 
   if (!state.explicit_language.empty() && state.explicit_language == "none") {
index 4f6a4cf9cc586e70d0da283b460ebb3755ea6926..627c6d3de2c26d16a25a2cfd95afd530d21e7601 100644 (file)
@@ -1592,15 +1592,14 @@ hash_common_info(const Context& ctx,
 
   // Possibly hash the coverage data file path.
   if (ctx.args_info.generating_coverage && ctx.args_info.profile_arcs) {
-    std::string dir;
+    fs::path dir;
     if (!ctx.args_info.profile_path.empty()) {
       dir = ctx.args_info.profile_path;
     } else {
       const auto output_dir = ctx.args_info.output_obj.parent_path();
-      dir = fs::canonical(output_dir).value_or(output_dir).string();
+      dir = fs::canonical(output_dir).value_or(output_dir);
     }
-    std::string gcda_path =
-      FMT("{}/{}.gcda", dir, ctx.args_info.output_obj.stem());
+    fs::path gcda_path = dir / FMT("{}.gcda", ctx.args_info.output_obj.stem());
     LOG("Hashing coverage path {}", gcda_path);
     hash.hash_delimiter("gcda");
     hash.hash(gcda_path);
@@ -1966,27 +1965,27 @@ get_manifest_key(Context& ctx, Hash& hash)
 static bool
 hash_profile_data_file(const Context& ctx, Hash& hash)
 {
-  const std::string& profile_path = ctx.args_info.profile_path;
+  const fs::path& profile_path = ctx.args_info.profile_path;
   const std::string base_name =
     util::pstr(util::with_extension(ctx.args_info.output_obj, ""));
   std::string hashified_cwd = util::pstr(ctx.apparent_cwd);
   std::replace(hashified_cwd.begin(), hashified_cwd.end(), '/', '#');
 
-  std::vector<std::string> paths_to_try{
+  std::vector<fs::path> paths_to_try{
     // -fprofile-use[=dir]/-fbranch-probabilities (GCC <9)
-    FMT("{}/{}.gcda", profile_path, base_name),
+    profile_path / FMT("{}.gcda", base_name),
     // -fprofile-use[=dir]/-fbranch-probabilities (GCC >=9)
-    FMT("{}/{}#{}.gcda", profile_path, hashified_cwd, base_name),
+    profile_path / FMT("{}#{}.gcda", hashified_cwd, base_name),
     // -fprofile(-instr|-sample)-use=file (Clang), -fauto-profile=file (GCC >=5)
     profile_path,
     // -fprofile(-instr|-sample)-use=dir (Clang)
-    FMT("{}/default.profdata", profile_path),
+    profile_path / "default.profdata",
     // -fauto-profile (GCC >=5)
     "fbdata.afdo", // -fprofile-dir is not used
   };
 
   bool found = false;
-  for (const std::string& p : paths_to_try) {
+  for (const fs::path& p : paths_to_try) {
     LOG("Checking for profile data file {}", p);
     if (DirEntry(p).is_regular_file()) {
       LOG("Adding profile data {} to the hash", p);
@@ -2022,10 +2021,10 @@ hash_profiling_related_data(const Context& ctx, Hash& hash)
     // For a relative profile directory D the compiler stores $PWD/D as part of
     // the profile filename so we need to include the same information in the
     // hash.
-    const std::string profile_path =
-      fs::path(ctx.args_info.profile_path).is_absolute()
+    const fs::path profile_path =
+      ctx.args_info.profile_path.is_absolute()
         ? ctx.args_info.profile_path
-        : FMT("{}/{}", ctx.apparent_cwd, ctx.args_info.profile_path);
+        : ctx.apparent_cwd / ctx.args_info.profile_path;
     LOG("Adding profile directory {} to our hash", profile_path);
     hash.hash_delimiter("-fprofile-dir");
     hash.hash(profile_path);