Rubygems with native dependencies are being reinstalled after cache restore

When restoring cached Rubygems from a previous build, my VM is always reinstalling & rebuilding gems that have native extensions, even when they were restored from the cache. I am running a macOS VM with Xcode 10.2, Ruby 2.5.3p105, and Bundler 1.17.3.

Here is my cache restore step:

- restore_cache:
    key: 1-gems-{{ checksum "Gemfile.lock" }}

Here is how I install gems:

bundle check --path vendor/bundle || bundle install --path vendor/bundle

And here is my cache save step:

- save_cache:
    key: 1-gems-{{ checksum "Gemfile.lock" }}
    paths:
      - vendor/bundle

When I run, here are the relevant logs:

The following gems are missing
 * unf_ext (0.0.7.5)
 * json (2.2.0)
 * sqlite3 (1.4.0)
Install missing gems with `bundle install`
Ignoring json-2.2.0 because its extensions are not built. Try: gem pristine json --version 2.2.0
Ignoring sqlite3-1.4.0 because its extensions are not built. Try: gem pristine sqlite3 --version 1.4.0
Ignoring unf_ext-0.0.7.5 because its extensions are not built. Try: gem pristine unf_ext --version 0.0.7.5

bundle install then runs and succeeds, rebuilding the gems that have native extensions.

It seems that these three gems must have components outside of vendor/bundle but I don’t know what those would be.

Anyone have an idea what’s happening and how to fix it?

I think I figured this out on my own…
This cache pre-dated a change in my build tools, so the cached native extensions must not have been in the same place as with my new tools. I changed my cache keys so that my gems were re-cached on the new tools, and this no longer happens.

In the future, when I change build tools, I’ll change the cache keys as well to “flush” all my caches, I guess.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.