]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Ignore SOURCE_DATE_EPOCH under time_macros sloppiness (#755)
authorAzat Khuzhin <a3at.mail@gmail.com>
Sat, 9 Jan 2021 18:44:30 +0000 (21:44 +0300)
committerGitHub <noreply@github.com>
Sat, 9 Jan 2021 18:44:30 +0000 (19:44 +0100)
SOURCE_DATE_EPOCH will be passed from debhelpers, by extracting last
entry from d/changelog (or current time if there is entries)
And this will not allow to use cache.

doc/MANUAL.adoc
src/ccache.cpp
test/suites/base.bash

index 1862985617b69cd7083b330e1dc27e73a9d52f5d..dbdbd0d7d7596578528b183c883d21007b973a7c 100644 (file)
@@ -839,7 +839,8 @@ still has to do _some_ preprocessing (like macros).
     hash but not add the system header files to the list of include files.
 *time_macros*::
     Ignore `__DATE__`, `__TIME__` and `__TIMESTAMP__` being present in the
-    source code.
+    source code. It will also ignore `SOURCE_DATE_EPOCH`
+    https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html[environment variable]
 --
 +
 See the discussion under _<<_troubleshooting,Troubleshooting>>_ for more
index d18ba0f91616556ee360f7646b5dc83dcf201040..6522a8de053c10b3b7f35718c84e331e250e2d11 100644 (file)
@@ -1288,17 +1288,24 @@ hash_common_info(const Context& ctx,
   hash.hash(Util::base_name(args[0]));
 
   // Hash variables that may affect the compilation.
-  const char* always_hash_env_vars[] = {
+  struct
+  {
+    const char* name;
+    uint32_t sloppiness;
+  } hash_env_vars[] = {
     // From <https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html>:
-    "COMPILER_PATH",
-    "GCC_COMPARE_DEBUG",
-    "GCC_EXEC_PREFIX",
-    "SOURCE_DATE_EPOCH",
+    {"COMPILER_PATH", 0},
+    {"GCC_COMPARE_DEBUG", 0},
+    {"GCC_EXEC_PREFIX", 0},
+    {"SOURCE_DATE_EPOCH", SLOPPY_TIME_MACROS},
   };
-  for (const char* name : always_hash_env_vars) {
-    const char* value = getenv(name);
+  for (const auto& env : hash_env_vars) {
+    if (env.sloppiness && (ctx.config.sloppiness() & env.sloppiness)) {
+      continue;
+    }
+    const char* value = getenv(env.name);
     if (value) {
-      hash.hash_delimiter(name);
+      hash.hash_delimiter(env.name);
       hash.hash(value);
     }
   }
index 2131ac92a8d697adf6c7c26ba0119864579ccb98..d0143009e671e3286c0e5337e2eff8906ea45733 100644 (file)
@@ -292,6 +292,24 @@ base_tests() {
     expect_stat 'cache miss' 1
     expect_stat 'files in cache' 1
 
+    # -------------------------------------------------------------------------
+    TEST "SOURCE_DATE_EPOCH with time_macros sloppiness"
+
+    CCACHE_SLOPPINESS=time_macros SOURCE_DATE_EPOCH=1 $CCACHE_COMPILE -c test1.c
+    expect_stat 'cache hit (preprocessed)' 0
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 1
+
+    CCACHE_SLOPPINESS=time_macros SOURCE_DATE_EPOCH=2 $CCACHE_COMPILE -c test1.c
+    expect_stat 'cache hit (preprocessed)' 1
+    expect_stat 'cache miss' 1
+    expect_stat 'files in cache' 1
+
+    SOURCE_DATE_EPOCH=1 $CCACHE_COMPILE -c test1.c
+    expect_stat 'cache hit (preprocessed)' 1
+    expect_stat 'cache miss' 2
+    expect_stat 'files in cache' 2
+
     # -------------------------------------------------------------------------
     TEST "Result file is compressed"