diff --git a/changelog/change_dont_hash_shared_libraries_for_cache_key.md b/changelog/change_dont_hash_shared_libraries_for_cache_key.md new file mode 100644 index 00000000000..5b33dc66b71 --- /dev/null +++ b/changelog/change_dont_hash_shared_libraries_for_cache_key.md @@ -0,0 +1 @@ +* [#10841](https://github.com/rubocop/rubocop/pull/10841): Don't hash shared libraries for cache key. ([@ChrisBr][]) diff --git a/lib/rubocop/result_cache.rb b/lib/rubocop/result_cache.rb index 36dd86f3651..b28a657b4ab 100644 --- a/lib/rubocop/result_cache.rb +++ b/lib/rubocop/result_cache.rb @@ -14,6 +14,12 @@ class ResultCache fix_layout autocorrect safe_autocorrect autocorrect_all cache fail_fast stdin parallel].freeze + DL_EXTENSIONS = ::RbConfig::CONFIG + .values_at('DLEXT', 'DLEXT2') + .reject { |ext| !ext || ext.empty? } + .map { |ext| ".#{ext}" } + .freeze + # Remove old files so that the cache doesn't grow too big. When the # threshold MaxFilesInCache has been exceeded, the oldest 50% of all the # files in the cache are removed. The reason for removing so much is that @@ -174,14 +180,24 @@ def rubocop_checksum .select { |path| File.file?(path) } .sort! .each do |path| - content = File.binread(path) - digest << Zlib.crc32(content).to_s # mtime not reliable + digest << digest(path) end digest << RuboCop::Version::STRING << RuboCop::AST::Version::STRING digest.hexdigest end end + def digest(path) + content = if path.end_with?(*DL_EXTENSIONS) + # Shared libraries often contain timestamps of when + # they were compiled and other non-stable data. + File.basename(path) + else + File.binread(path) # mtime not reliable + end + Zlib.crc32(content).to_s + end + def rubocop_extra_features lib_root = File.join(File.dirname(__FILE__), '..') exe_root = File.join(lib_root, '..', 'exe')