From: Joel Rosdahl Date: Wed, 21 Jun 2023 19:22:44 +0000 (+0200) Subject: feat: Let ignore_options/CCACHE_IGNOREOPTIONS also skip option X-Git-Tag: v4.9~163 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2737d79e282de72d1b29128f437173e4892ced5e;p=thirdparty%2Fccache.git feat: Let ignore_options/CCACHE_IGNOREOPTIONS also skip option The ignore_options (CCACHE_IGNOREOPTIONS) configuration makes ccache exclude matching compiler options from the input hash. This commit also makes ccache skip matching compiler options from any special processing, similar to how --ccache-skip works. As discussed in #1284 and #1301. --- diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index 28922e089..722c9d9a3 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -306,6 +306,8 @@ Another case where `--ccache-skip` can be useful is if ccache interprets an option specially but shouldn't, since the option has another meaning for your compiler than what ccache thinks. +See also <>. + == Configuration @@ -780,12 +782,13 @@ might be incorrect. *ignore_options* (*CCACHE_IGNOREOPTIONS*):: This option is a space-delimited list of compiler options that ccache will - exclude from the hash. Excluding a compiler option from the hash can be - useful when you know it doesn't affect the result (but ccache doesn't know - that), or when it does and you don't care. If a compiler option in the list - is suffixed with an asterisk (`*`) it will be matched as a prefix. For - example, `+-fmessage-length=*+` will match both `-fmessage-length=20` and - `-fmessage-length=70`. + ignore. Entries in the list can optionally end with an asterisk (`*`) to + matching any option suffix. For example, `+-fmessage-length=*+` will match + both `-fmessage-length=20` and `-fmessage-length=70`. A matching compiler + option will neither be interpreted specially nor be part of the input hash. + Ignoring a compiler option from the hash can be useful when you know it + doesn't affect the result (and ccache doesn't know that), or when it does + and you don't care. See also _<>_. [#config_inode_cache] *inode_cache* (*CCACHE_INODECACHE* or *CCACHE_NOINODECACHE*, see _<>_ above):: diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index 3303ca14d..7558d0a6b 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -296,7 +296,13 @@ process_option_arg(const Context& ctx, ArgumentProcessingState& state) { size_t& i = args_index; - // The user knows best: just swallow the next arg. + + if (option_should_be_ignored(args[i], ctx.ignore_options())) { + LOG("Not processing ignored option: {}", args[i]); + state.common_args.push_back(args[i]); + return Statistic::none; + } + if (args[i] == "--ccache-skip") { i++; if (i == args.size()) { @@ -1572,3 +1578,17 @@ process_args(Context& ctx) state.hash_actual_cwd, }; } + +bool +option_should_be_ignored(const std::string& arg, + const std::vector& patterns) +{ + return std::any_of( + patterns.cbegin(), patterns.cend(), [&arg](const auto& pattern) { + const auto& prefix = + std::string_view(pattern).substr(0, pattern.length() - 1); + return ( + pattern == arg + || (util::ends_with(pattern, "*") && util::starts_with(arg, prefix))); + }); +} diff --git a/src/argprocessing.hpp b/src/argprocessing.hpp index 2f5c2f7e0..8375b361e 100644 --- a/src/argprocessing.hpp +++ b/src/argprocessing.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020-2022 Joel Rosdahl and other contributors +// Copyright (C) 2020-2023 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -23,6 +23,8 @@ #include #include +#include +#include class Context; @@ -68,3 +70,6 @@ inline ProcessArgsResult::ProcessArgsResult(const Args& preprocessor_args_, } ProcessArgsResult process_args(Context& ctx); + +bool option_should_be_ignored(const std::string& arg, + const std::vector& patterns); diff --git a/src/ccache.cpp b/src/ccache.cpp index 58edac98f..fa388445c 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1559,20 +1559,6 @@ hash_common_info(const Context& ctx, return {}; } -static bool -option_should_be_ignored(const std::string& arg, - const std::vector& patterns) -{ - return std::any_of( - patterns.cbegin(), patterns.cend(), [&arg](const auto& pattern) { - const auto& prefix = - std::string_view(pattern).substr(0, pattern.length() - 1); - return ( - pattern == arg - || (util::ends_with(pattern, "*") && util::starts_with(arg, prefix))); - }); -} - static std::tuple, std::optional> get_option_and_value(std::string_view option, const Args& args, size_t& i)