From: Joel Rosdahl Date: Tue, 24 Sep 2024 18:50:23 +0000 (+0200) Subject: refactor: Improve some types X-Git-Tag: v4.11~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7c94f782637cd439c90f7518e73b7c100c5ffe1;p=thirdparty%2Fccache.git refactor: Improve some types --- diff --git a/src/ccache/argprocessing.cpp b/src/ccache/argprocessing.cpp index 10f4d7ac..012ee43b 100644 --- a/src/ccache/argprocessing.cpp +++ b/src/ccache/argprocessing.cpp @@ -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 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=")) { diff --git a/src/ccache/context.cpp b/src/ccache/context.cpp index b59cd95e..0f9fe0ee 100644 --- a/src/ccache/context.cpp +++ b/src/ccache/context.cpp @@ -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. diff --git a/src/ccache/core/common.cpp b/src/ccache/core/common.cpp index a177296a..63c399d0 100644 --- a/src/ccache/core/common.cpp +++ b/src/ccache/core/common.cpp @@ -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())) { diff --git a/src/ccache/core/result.cpp b/src/ccache/core/result.cpp index 3599bb52..66d9750a 100644 --- a/src/ccache/core/result.cpp +++ b/src/ccache/core/result.cpp @@ -250,8 +250,7 @@ Serializer::add_data(const FileType file_type, nonstd::span 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)) { diff --git a/src/ccache/core/resultretriever.cpp b/src/ccache/core/resultretriever.cpp index 9547109c..5212016a 100644 --- a/src/ccache/core/resultretriever.cpp +++ b/src/ccache/core/resultretriever.cpp @@ -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 data) { ASSERT(m_ctx.args_info.dependency_target); diff --git a/src/ccache/execute.cpp b/src/ccache/execute.cpp index 3b5f836f..7ed359cc 100644 --- a/src/ccache/execute.cpp +++ b/src/ccache/execute.cpp @@ -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(argv)); } diff --git a/src/ccache/inodecache.cpp b/src/ccache/inodecache.cpp index 2f282fe9..d32c1712 100644 --- a/src/ccache/inodecache.cpp +++ b/src/ccache/inodecache.cpp @@ -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(); diff --git a/src/ccache/storage/local/localstorage.cpp b/src/ccache/storage/local/localstorage.cpp index ec59f5d5..aa9d87dd 100644 --- a/src/ccache/storage/local/localstorage.cpp +++ b/src/ccache/storage/local/localstorage.cpp @@ -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)); diff --git a/src/ccache/util/file.cpp b/src/ccache/util/file.cpp index 142ea5ab..03f00526 100644 --- a/src/ccache/util/file.cpp +++ b/src/ccache/util/file.cpp @@ -621,7 +621,7 @@ tl::expected 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 { diff --git a/src/ccache/util/filesystem.cpp b/src/ccache/util/filesystem.cpp index 22ad2cff..77ea074d 100644 --- a/src/ccache/util/filesystem.cpp +++ b/src/ccache/util/filesystem.cpp @@ -26,12 +26,14 @@ namespace util::filesystem { +namespace fs = std::filesystem; + tl::expected -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); } diff --git a/src/ccache/util/path.cpp b/src/ccache/util/path.cpp index a6fe0128..282cca0c 100644 --- a/src/ccache/util/path.cpp +++ b/src/ccache/util/path.cpp @@ -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) diff --git a/src/ccache/util/string.cpp b/src/ccache/util/string.cpp index cf4fd81e..1597647e 100644 --- a/src/ccache/util/string.cpp +++ b/src/ccache/util/string.cpp @@ -19,11 +19,14 @@ #include "string.hpp" #include +#include #include #include #include +namespace fs = util::filesystem; + namespace { template @@ -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::vector 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 paths; + std::vector paths; std::copy(strings.cbegin(), strings.cend(), std::back_inserter(paths)); return paths; }