From: Joel Rosdahl Date: Fri, 7 Jun 2024 14:24:21 +0000 (+0200) Subject: refactor: Improve handling of ignore_header_paths matching X-Git-Tag: v4.11~111 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02b8f69827bf6e95d5c5e3e78dea26595181265f;p=thirdparty%2Fccache.git refactor: Improve handling of ignore_header_paths matching --- diff --git a/src/ccache/ccache.cpp b/src/ccache/ccache.cpp index 627c6d3d..33efd3f3 100644 --- a/src/ccache/ccache.cpp +++ b/src/ccache/ccache.cpp @@ -335,10 +335,9 @@ remember_include_file(Context& ctx, return {}; } - std::string path_str = util::pstr(path); - - if (path_str.length() >= 2 && path_str[0] == '<' - && path_str[path_str.length() - 1] == '>') { + util::PathString path_str(path); + if (path_str.str().length() >= 2 && path_str.str()[0] == '<' + && path_str.str()[path_str.str().length() - 1] == '>') { // Typically or . return {}; } @@ -349,11 +348,6 @@ remember_include_file(Context& ctx, return {}; } - // Canonicalize path for comparison; Clang uses ./header.h. - if (util::starts_with(path_str, "./")) { - path_str.erase(0, 2); - } - if (ctx.included_files.find(path_str) != ctx.included_files.end()) { // Already known include file. return {}; @@ -389,9 +383,16 @@ remember_include_file(Context& ctx, return tl::unexpected(Statistic::bad_input_file); } - for (const auto& ignore_header_path : ctx.ignore_header_paths) { - if (file_path_matches_dir_prefix_or_file(ignore_header_path, path_str)) { - return {}; + if (!ctx.ignore_header_paths.empty()) { + // Canonicalize path for comparison; Clang uses ./header.h. + const std::string& canonical_path_str = + util::starts_with(path_str.str(), "./") ? path_str.str().substr(2) + : path_str; + for (const auto& ignore_header_path : ctx.ignore_header_paths) { + if (file_path_matches_dir_prefix_or_file(ignore_header_path, + canonical_path_str)) { + return {}; + } } }