From a4b39be0226f0405df63de87b55e53d6e803d8de Mon Sep 17 00:00:00 2001 From: Daniel Vandersluis Date: Wed, 2 Sep 2020 10:30:54 -0400 Subject: [PATCH] [Fix #8629] Calculate rubocop_checksum by calculating a crc32 for each 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. --- CHANGELOG.md | 1 + lib/rubocop/result_cache.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07a5b4ad50e..c22223beff7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,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) diff --git a/lib/rubocop/result_cache.rb b/lib/rubocop/result_cache.rb index 2dda0c8a6fc..ebc8d7ab925 100644 --- a/lib/rubocop/result_cache.rb +++ b/lib/rubocop/result_cache.rb @@ -3,6 +3,7 @@ require 'digest/sha1' require 'find' require 'etc' +require 'zlib' module RuboCop # Provides functionality for caching rubocop runs. @@ -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