]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Use util::with_extension
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 2 Jun 2024 08:28:25 +0000 (10:28 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 30 Jun 2024 15:18:49 +0000 (17:18 +0200)
src/ccache/argprocessing.cpp
src/ccache/ccache.cpp
src/ccache/core/Result.cpp
src/ccache/core/ResultRetriever.cpp

index 876123e8ecdf0938750bb8f88c512398fa6e01ef..08835e609cb248b706258f375b40410db75163d8 100644 (file)
@@ -173,7 +173,7 @@ detect_pch(const std::string& option,
       pch_file = included_pch_file;
       included_pch_file.clear(); // reset pch file set from /Fp
     } else {
-      fs::path file = fs::path(arg).replace_extension(".pch");
+      fs::path file = util::with_extension(arg, ".pch");
       if (fs::is_regular_file(file)) {
         LOG("Detected use of precompiled header: {}", file);
         pch_file = util::pstr(file);
@@ -1357,8 +1357,8 @@ process_args(Context& ctx)
     } else {
       extension = get_default_object_file_extension(ctx.config);
     }
-    args_info.output_obj += util::pstr(
-      fs::path(args_info.input_file).filename().replace_extension(extension));
+    args_info.output_obj += util::pstr(util::with_extension(
+      fs::path(args_info.input_file).filename()extension));
   }
 
   args_info.orig_output_obj = args_info.output_obj;
@@ -1379,9 +1379,8 @@ process_args(Context& ctx)
 
     if (included_pch_file_by_source && !args_info.input_file.empty()) {
       args_info.included_pch_file = util::pstr(
-        fs::path(args_info.input_file)
-          .filename()
-          .replace_extension(get_default_pch_file_extension(ctx.config)));
+        util::with_extension(fs::path(args_info.input_file).filename(),
+                             get_default_pch_file_extension(ctx.config)));
       LOG(
         "Setting PCH filepath from the base source file (during generating): "
         "{}",
@@ -1520,7 +1519,7 @@ process_args(Context& ctx)
       args_info.seen_split_dwarf = false;
     } else {
       args_info.output_dwo =
-        util::pstr(fs::path(args_info.output_obj).replace_extension(".dwo"));
+        util::pstr(util::with_extension(args_info.output_obj, ".dwo"));
     }
   }
 
@@ -1582,7 +1581,7 @@ process_args(Context& ctx)
   if (args_info.generating_dependencies) {
     if (state.output_dep_origin == OutputDepOrigin::none) {
       args_info.output_dep =
-        util::pstr(fs::path(args_info.output_obj).replace_extension(".d"));
+        util::pstr(util::with_extension(args_info.output_obj, ".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
@@ -1615,11 +1614,9 @@ process_args(Context& ctx)
         } else if (config.compiler_type() == CompilerType::gcc) {
           // GCC strangely uses the base name of the source file but with a .o
           // extension.
-          dep_target =
-            fs::path(args_info.orig_input_file)
-              .filename()
-              .replace_extension(get_default_object_file_extension(ctx.config))
-              .string();
+          dep_target = util::pstr(util::with_extension(
+            fs::path(args_info.orig_input_file).filename(),
+            get_default_object_file_extension(ctx.config)));
         } else {
           // How other compilers behave is currently unknown, so bail out.
           LOG_RAW(
@@ -1634,15 +1631,15 @@ process_args(Context& ctx)
   }
 
   if (args_info.generating_stackusage) {
-    std::string default_sufile_name =
-      fs::path(args_info.output_obj).replace_extension(".su").string();
+    fs::path default_sufile_name =
+      util::with_extension(args_info.output_obj, ".su");
     args_info.output_su =
       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();
+    fs::path default_cifile_name =
+      util::with_extension(args_info.output_obj, ".ci");
     args_info.output_ci =
       util::pstr(core::make_relative_path(ctx, default_cifile_name));
   }
index 7fb74df4af05f3f019d407806b2dd464b661a22c..cc2e99d1ff0fc79ac761b8b006823a685db325de 100644 (file)
@@ -286,8 +286,8 @@ follow_symlinks(const fs::path& path)
 static CompilerType
 do_guess_compiler(const fs::path& path)
 {
-  const auto name =
-    util::to_lowercase(util::pstr(path.filename().replace_extension("")).str());
+  const auto name = util::to_lowercase(
+    util::pstr(util::with_extension(path.filename(), "")).str());
   if (name.find("clang-cl") != std::string_view::npos) {
     return CompilerType::clang_cl;
   } else if (name.find("clang") != std::string_view::npos) {
@@ -1963,7 +1963,7 @@ hash_profile_data_file(const Context& ctx, Hash& hash)
 {
   const std::string& profile_path = ctx.args_info.profile_path;
   const std::string base_name =
-    util::pstr(fs::path(ctx.args_info.output_obj).replace_extension(""));
+    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(), '/', '#');
 
index 5d1819edc5d5e80e514c88a63b51e82d46fb11f8..82505a0c670cd0543a5e6428bda0b666fb5ded7f 100644 (file)
@@ -171,13 +171,13 @@ gcno_file_in_mangled_form(const Context& ctx)
       : FMT("{}/{}", ctx.apparent_cwd, output_obj);
   std::string hashified_obj = abs_output_obj;
   std::replace(hashified_obj.begin(), hashified_obj.end(), '/', '#');
-  return fs::path(hashified_obj).replace_extension(".gcno").string();
+  return util::pstr(util::with_extension(hashified_obj, ".gcno"));
 }
 
 std::string
 gcno_file_in_unmangled_form(const Context& ctx)
 {
-  return fs::path(ctx.args_info.output_obj).replace_extension(".gcno").string();
+  return util::pstr(util::with_extension(ctx.args_info.output_obj, ".gcno"));
 }
 
 Deserializer::Deserializer(nonstd::span<const uint8_t> data) : m_data(data)
index 921aff5c773a51aa5a5570017ca806c788329606..1069610a6cb137a067ba4a53fa44729107a803f1 100644 (file)
@@ -164,9 +164,8 @@ ResultRetriever::get_dest_path(FileType file_type) const
 
   case FileType::coverage_unmangled:
     if (m_ctx.args_info.generating_coverage) {
-      return fs::path(m_ctx.args_info.output_obj)
-        .replace_extension(".gcno")
-        .string();
+      return util::pstr(
+        util::with_extension(m_ctx.args_info.output_obj, ".gcno"));
     }
     break;