Skip to content

Instantly share code, notes, and snippets.

@zdennis
Last active February 13, 2020 15:46
Show Gist options
  • Save zdennis/58265f0b7f113d9274610194dcb330fe to your computer and use it in GitHub Desktop.
Save zdennis/58265f0b7f113d9274610194dcb330fe to your computer and use it in GitHub Desktop.
bootboot-lite: dual boot without bootboot!
# Require this from your Gemfile
# - Adds support for programmatically setting the cache path
Bundler::Settings.class_eval do
attr_writer :app_cache_path
end
source "https://rubygems.org"
ruby "~> " + File.read("#{Bundler.root}/.ruby-version").strip
require_relative 'dual_boot/bootboot-lite'
if ENV['DEPENDENCIES_NEXT']
Bundler.settings.app_cache_path = "vendor/cache-rails_5.0"
# Add any gem you want here, they will be loaded only when running
# bundler command prefixed with `DEPENDENCIES_NEXT=1`.
eval_gemfile File.dirname(__FILE__) + "/gemfiles/rails5.0.gemfile"
else
eval_gemfile File.dirname(__FILE__) + "/gemfiles/rails4.2.gemfile"
end
@zdennis
Copy link
Author

zdennis commented Feb 13, 2020

The earlier revisions of this did not work consistently with bundler 1.17.x. In some cases the bundler would take a code path that let the patches take affect before it tried to read the lock file, e.g. DEPENDENCIES_NEXT=1 bundle install. However, it failed when running commands through bundle exec ... because it tried to read the lockfile before processing the Gemfile or any extensions loaded in it.

The latest revision (revision 4 at the time of this writing) essentially removes all of the bootboot patches and only leaves in the attr_writer for app_cache_path.

If you symlink Gemfile_next to Gemfile and use BUNDLE_GEMFILE=Gemfile_next then everything will work across bundler invocations.

It's possible to remove the app_cache_path writer and just rely on BUNDLE_CACHE_PATH but it's left in place as a way to not require that env var to be set and to rely on DEPENDENCIES_NEXT to always set the cache path appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment