]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Let ignore_options/CCACHE_IGNOREOPTIONS also skip option
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 21 Jun 2023 19:22:44 +0000 (21:22 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 21 Jun 2023 19:35:48 +0000 (21:35 +0200)
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.

doc/MANUAL.adoc
src/argprocessing.cpp
src/argprocessing.hpp
src/ccache.cpp

index 28922e08951f96e924c23fc1210ccf094db11fc8..722c9d9a3c521eb5abd2d761f70a086aff3495c9 100644 (file)
@@ -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 <<config_ignore_options,*ignore_options*>>.
+
 
 == 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 _<<Extra options>>_.
 
 [#config_inode_cache]
 *inode_cache* (*CCACHE_INODECACHE* or *CCACHE_NOINODECACHE*, see _<<Boolean values>>_ above)::
index 3303ca14d401a15648ab864a9ae7e51e074a0e8e..7558d0a6b4385f7f9f80db07e708e336f3a609c2 100644 (file)
@@ -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<std::string>& 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)));
+    });
+}
index 2f5c2f7e074ceb231ca53ccdbc6ab05b3b9cc23d..8375b361eeb5447f4cbe220b2d245039e29bd005 100644 (file)
@@ -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 <core/Statistic.hpp>
 
 #include <optional>
+#include <string>
+#include <vector>
 
 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<std::string>& patterns);
index 58edac98ff26bc14fe5651a225bdd55cb15b1736..fa388445cd875054befd6c263642181b0ac36ed5 100644 (file)
@@ -1559,20 +1559,6 @@ hash_common_info(const Context& ctx,
   return {};
 }
 
-static bool
-option_should_be_ignored(const std::string& arg,
-                         const std::vector<std::string>& 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<std::string_view>,
                   std::optional<std::string_view>>
 get_option_and_value(std::string_view option, const Args& args, size_t& i)