Skip to content

Commit

Permalink
[Fix #8629] Calculate rubocop_checksum by calculating a crc32 for eac…
Browse files Browse the repository at this point in the history
…h file rather than using mtime.

File.mtime is faster, but inconsistent in CI, because in each CI build the mtime changes, which means that the rubocop cache implicitly cannot be used as-is. It's obviously slower to calculate a hash for each file, but this is still more performant (both in memory consumption and iterations per second) than the original.
  • Loading branch information
dvandersluis authored and bbatsov committed Sep 4, 2020
1 parent 533375c commit 0904a72
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -56,6 +56,7 @@
* [#8517](https://github.com/rubocop-hq/rubocop/pull/8517): Make `Style/HashTransformKeys` and `Style/HashTransformValues` aware of `to_h` with block. ([@eugeneius][])
* [#8529](https://github.com/rubocop-hq/rubocop/pull/8529): Mark `Lint/FrozenStringLiteralComment` as `Safe`, but with unsafe auto-correction. ([@marcandre][])
* [#8602](https://github.com/rubocop-hq/rubocop/pull/8602): Fix usage of `to_enum(:scan, regexp)` to work on TruffleRuby. ([@jaimerave][])
* [#8629](https://github.com/rubocop-hq/rubocop/pull/8629): Fix the cache being reusable in CI by using crc32 to calculate file hashes rather than `mtime`, which changes each CI build. ([@dvandersluis][])

## 0.89.1 (2020-08-10)

Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/result_cache.rb
Expand Up @@ -3,6 +3,7 @@
require 'digest/sha1'
require 'find'
require 'etc'
require 'zlib'

module RuboCop
# Provides functionality for caching rubocop runs.
Expand Down Expand Up @@ -171,7 +172,7 @@ def rubocop_checksum
rubocop_extra_features
.select { |path| File.file?(path) }
.sort!
.each { |path| digest << File.mtime(path).to_s }
.each { |path| digest << Zlib.crc32(IO.read(path)).to_s }
digest << RuboCop::Version::STRING << RuboCop::AST::Version::STRING
digest.hexdigest
end
Expand Down

0 comments on commit 0904a72

Please sign in to comment.