]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Add sloppiness for -frandom-seed (#1168)
authorRaihaan Shouhell <raihaanhimself@gmail.com>
Tue, 4 Oct 2022 19:21:42 +0000 (03:21 +0800)
committerGitHub <noreply@github.com>
Tue, 4 Oct 2022 19:21:42 +0000 (21:21 +0200)
doc/MANUAL.adoc
src/Config.cpp
src/ccache.cpp
src/core/Sloppiness.hpp

index 8577ac1f251b1ca8c52dd5c3cfe333d1b0bc7e34..d979818e0c63c91929ab5090b88f13ed32fb1ae3 100644 (file)
@@ -1002,6 +1002,9 @@ preprocessing first.
 *time_macros*::
     Ignore `+__DATE__+`, `+__TIME__+` and `+__TIMESTAMP__+` being present in the
     source code.
+*random_seed*::
+    By default, ccache will respect argument changes with `-frandom-seed`. This
+    sloppiness will allow cache hits even if the seed value is different.
 --
 +
 See the discussion under _<<Troubleshooting>>_ for more information.
index 9d2b3ae44646f0c3d03118d6d10475933d9fecb6..520557e10a83b241a580d4dc2639f4608ba44fe8 100644 (file)
@@ -304,6 +304,8 @@ parse_sloppiness(const std::string& value)
       result.enable(core::Sloppy::modules);
     } else if (token == "pch_defines") {
       result.enable(core::Sloppy::pch_defines);
+    } else if (token == "random_seed") {
+      result.enable(core::Sloppy::random_seed);
     } else if (token == "system_headers" || token == "no_system_headers") {
       result.enable(core::Sloppy::system_headers);
     } else if (token == "time_macros") {
@@ -348,6 +350,9 @@ format_sloppiness(core::Sloppiness sloppiness)
   if (sloppiness.is_enabled(core::Sloppy::pch_defines)) {
     result += "pch_defines, ";
   }
+  if (sloppiness.is_enabled(core::Sloppy::random_seed)) {
+    result += "random_seed, ";
+  }
   if (sloppiness.is_enabled(core::Sloppy::system_headers)) {
     result += "system_headers, ";
   }
index 2ae8093271c1d5c7f05867c1324a05e8dafc797b..29e90de7b1e8b9ae6685a00f37ed06b2ed515aca 100644 (file)
@@ -1555,6 +1555,15 @@ hash_argument(const Context& ctx,
     return {};
   }
 
+  // If we treat random_seed sloppily we ignore the argument when
+  // hashing.
+  if (util::starts_with(args[i], "-frandom-seed=")
+      && ctx.config.sloppiness().is_enabled(core::Sloppy::random_seed)) {
+    hash.hash_delimiter("arg");
+    hash.hash("-frandom-seed=");
+    return {};
+  }
+
   // When using the preprocessor, some arguments don't contribute to the hash.
   // The theory is that these arguments will change the output of -E if they are
   // going to have any effect at all. For precompiled headers this might not be
index 69d3dfacecc5e15079b04d42d159d5abeec71ef8..a7aa08eead6ae880d3c5e7c9290aa13c3d25b1cf 100644 (file)
@@ -49,6 +49,8 @@ enum class Sloppy : uint32_t {
   ivfsoverlay = 1U << 10,
   // Allow us to include incorrect working directory in .gcno files.
   gcno_cwd = 1U << 11,
+  // Ignore changes in -frandom-seed
+  random_seed = 1U << 12,
 };
 
 class Sloppiness