]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Add sloppiness for .incbin handling (#1423)
authorRaihaan Shouhell <raihaanhimself@gmail.com>
Sun, 14 Apr 2024 07:44:40 +0000 (15:44 +0800)
committerGitHub <noreply@github.com>
Sun, 14 Apr 2024 07:44:40 +0000 (09:44 +0200)
Code to address some issues in #1421.

doc/MANUAL.adoc
src/ccache/Config.cpp
src/ccache/ccache.cpp
src/ccache/core/Sloppiness.hpp

index 3372187f14fd611b87cf50cfc165426a493ae7e3..9e74030cb3744bb513efacc772bc9bd694a67ab2 100644 (file)
@@ -1045,6 +1045,11 @@ preprocessing first.
     different directories, with the tradeoff of potentially getting an incorrect
     directory in the `.gcno` file. *gcno_cwd* also disables hashing of the
     current working directory if `-fprofile-abs-path` is used.
+*incbin*::
+    By default, ccache will ignore all files containing an `.incbin` directive.
+    While this is the correct behaviour as ccache does not detect incbin changes,
+    this restriction can make some projects difficult to cache. This sloppiness
+    will pretend the `.incbin` directive doesn't exist and simply allow caching.
 *include_file_ctime*::
     By default, ccache will disable caching if a source code file has a status
     change time (ctime) after the start of the ccache invocation. This
index 5d99f8d9083543183042e3e2a526f6d7a852dd7c..bb2c4ac2ddf977fb5b278beef0e40634542eba6e 100644 (file)
@@ -293,6 +293,8 @@ parse_sloppiness(const std::string& value)
       result.insert(core::Sloppy::file_stat_matches_ctime);
     } else if (token == "gcno_cwd") {
       result.insert(core::Sloppy::gcno_cwd);
+    } else if (token == "incbin") {
+      result.insert(core::Sloppy::incbin);
     } else if (token == "include_file_ctime") {
       result.insert(core::Sloppy::include_file_ctime);
     } else if (token == "include_file_mtime") {
@@ -333,6 +335,9 @@ format_sloppiness(core::Sloppiness sloppiness)
   if (sloppiness.contains(core::Sloppy::gcno_cwd)) {
     result += "gcno_cwd, ";
   }
+  if (sloppiness.contains(core::Sloppy::incbin)) {
+    result += "incbin, ";
+  }
   if (sloppiness.contains(core::Sloppy::include_file_ctime)) {
     result += "include_file_ctime, ";
   }
index 6a3a4fbbb9cc325310d23cd9d67857256d03f3d4..60bb154e41bc41bb1025fbf685bdde7b17a87ce2 100644 (file)
@@ -570,6 +570,16 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path)
                && ((q[7] == ' '
                     && (q[8] == '"' || (q[8] == '\\' && q[9] == '"')))
                    || q[7] == '"')) {
+      // Instead of bailing we ignore changes as sloppy incbin handling is
+      // enabled
+      if (ctx.config.sloppiness().contains(core::Sloppy::incbin)) {
+        LOG_RAW(
+          "Found potential unsupported .inc"
+          "bin directive in source code "
+          "but continuing due to enabled sloppy incbin handling");
+        q += sizeof(incbin_directive);
+        continue;
+      }
       // An assembler .inc bin (without the space) statement, which could be
       // part of inline assembly, refers to an external file. If the file
       // changes, the hash should change as well, but finding out what file to
index 9afc08a52e031287873b5c0b66b6429f9f289b80..98f0fe4be9f1d924d9bcae85572b88224b485fab 100644 (file)
@@ -53,6 +53,8 @@ enum class Sloppy : uint32_t {
   gcno_cwd = 1U << 11,
   // Ignore -frandom-seed=*string*.
   random_seed = 1U << 12,
+  // Enables sloppy handling of incbin
+  incbin = 1U << 13,
 };
 
 using Sloppiness = util::BitSet<Sloppy>;