Skip to content

Commit

Permalink
Don't hash shared libraries for cache key
Browse files Browse the repository at this point in the history
Shared libraries often contain timestamps of when they were compiled and other non-stable data
hence would often produce different hashes on different machines
  • Loading branch information
ChrisBr committed Aug 3, 2022
1 parent 6b6d554 commit 1839d17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#10841](https://github.com/rubocop/rubocop/pull/10841): Don't hash shared libraries for cache key. ([@ChrisBr][])
20 changes: 18 additions & 2 deletions lib/rubocop/result_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 1839d17

Please sign in to comment.