Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't hash shared libraries for cache key #10841

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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