From: Joel Rosdahl Date: Sun, 2 Jun 2024 08:28:25 +0000 (+0200) Subject: refactor: Use util::with_extension X-Git-Tag: v4.11~131 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa0ef4f2aad130e9dfdcd24952e6c1f41f909dd7;p=thirdparty%2Fccache.git refactor: Use util::with_extension --- diff --git a/src/ccache/argprocessing.cpp b/src/ccache/argprocessing.cpp index 876123e8..08835e60 100644 --- a/src/ccache/argprocessing.cpp +++ b/src/ccache/argprocessing.cpp @@ -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)); } diff --git a/src/ccache/ccache.cpp b/src/ccache/ccache.cpp index 7fb74df4..cc2e99d1 100644 --- a/src/ccache/ccache.cpp +++ b/src/ccache/ccache.cpp @@ -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(), '/', '#'); diff --git a/src/ccache/core/Result.cpp b/src/ccache/core/Result.cpp index 5d1819ed..82505a0c 100644 --- a/src/ccache/core/Result.cpp +++ b/src/ccache/core/Result.cpp @@ -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 data) : m_data(data) diff --git a/src/ccache/core/ResultRetriever.cpp b/src/ccache/core/ResultRetriever.cpp index 921aff5c..1069610a 100644 --- a/src/ccache/core/ResultRetriever.cpp +++ b/src/ccache/core/ResultRetriever.cpp @@ -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;