From be1ed7749cce3fdb4b3321d4c88749afd2a790a2 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sat, 9 Jan 2021 21:44:30 +0300 Subject: [PATCH] Ignore SOURCE_DATE_EPOCH under time_macros sloppiness (#755) 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 | 3 ++- src/ccache.cpp | 23 +++++++++++++++-------- test/suites/base.bash | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index 1862985617..dbdbd0d7d7 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -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 diff --git a/src/ccache.cpp b/src/ccache.cpp index d18ba0f916..6522a8de05 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -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 : - "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); } } diff --git a/test/suites/base.bash b/test/suites/base.bash index 2131ac92a8..d0143009e6 100644 --- a/test/suites/base.bash +++ b/test/suites/base.bash @@ -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"