diff options
author | Nick LaMuro <nicklamuro@gmail.com> | 2017-08-07 17:32:58 -0500 |
---|---|---|
committer | Nick LaMuro <nicklamuro@gmail.com> | 2017-08-14 16:00:41 -0500 |
commit | 4bc46ea111ddd8b124ec0c75a288040dd46416cc (patch) | |
tree | f03c18e8bd9dc80015122b281df548535266d7ef | |
parent | 0d84c9c5156df8f722e91e961a63849b51a4ed11 (diff) | |
download | bundler-4bc46ea111ddd8b124ec0c75a288040dd46416cc.tar.gz |
Use Bundler::Installer for bundle pristine
Using a combination of Bundler::Installer and Bundler::GemInstaller to
install the gems in `bundle pristine` allows the code for making use of
bundler config being respected to be reused when installing a gem.
Makes use of the compiled Makefile for c-extensions to confirm that the
args are passed properly (honestly... a little hacky, but no real other
way to do this on older versions of rubygems).
-rw-r--r-- | lib/bundler/cli/pristine.rb | 8 | ||||
-rw-r--r-- | spec/commands/pristine_spec.rb | 19 | ||||
-rw-r--r-- | spec/support/builders.rb | 9 |
3 files changed, 33 insertions, 3 deletions
diff --git a/lib/bundler/cli/pristine.rb b/lib/bundler/cli/pristine.rb index cfd90da34b..0c412b6c07 100644 --- a/lib/bundler/cli/pristine.rb +++ b/lib/bundler/cli/pristine.rb @@ -9,6 +9,9 @@ module Bundler def run CLI::Common.ensure_all_gems_in_lockfile!(@gems) + definition = Bundler.definition + definition.validate_runtime! + installer = Bundler::Installer.new(Bundler.root, definition) Bundler.load.specs.each do |spec| next if spec.name == "bundler" # Source::Rubygems doesn't install bundler @@ -26,14 +29,15 @@ module Bundler end FileUtils.rm_rf spec.full_gem_path - source.install(spec, :force => true) when Source::Git source.remote! FileUtils.rm_rf spec.full_gem_path - source.install(spec, :force => true) else Bundler.ui.warn("Cannot pristine #{gem_name}. Gem is sourced from local path.") + next end + + Bundler::GemInstaller.new(spec, installer, false, 0, true).install_from_spec end end end diff --git a/spec/commands/pristine_spec.rb b/spec/commands/pristine_spec.rb index 56496a0a27..5320ce2d97 100644 --- a/spec/commands/pristine_spec.rb +++ b/spec/commands/pristine_spec.rb @@ -11,6 +11,7 @@ RSpec.describe "bundle pristine" do build_repo2 do build_gem "weakling" build_gem "baz-dev", "1.0.0" + build_gem "very_simple_binary", &:add_c_extension build_git "foo", :path => lib_path("foo") build_lib "bar", :path => lib_path("bar") end @@ -18,6 +19,7 @@ RSpec.describe "bundle pristine" do install_gemfile! <<-G source "file://#{gem_repo2}" gem "weakling" + gem "very_simple_binary" gem "foo", :git => "#{lib_path("foo")}" gem "bar", :path => "#{lib_path("bar")}" @@ -142,4 +144,21 @@ RSpec.describe "bundle pristine" do expect(out).to include("Could not find gem 'abcabcabc'.") end end + + context "when a build config exists for one of the gems" do + let(:very_simple_binary) { Bundler.definition.specs["very_simple_binary"].first } + let(:c_ext_dir) { Pathname.new(very_simple_binary.full_gem_path).join("ext") } + let(:build_opt) { "--with-ext-lib=#{c_ext_dir}" } + before { bundle "config build.very_simple_binary -- #{build_opt}" } + + # This just verifies that the generated Makefile from the c_ext gem makes + # use of the build_args from the bundle config + it "applies the config when installing the gem" do + bundle! "pristine" + + makefile_contents = File.read(c_ext_dir.join("Makefile").to_s) + expect(makefile_contents).to match(/libpath =.*#{c_ext_dir}/) + expect(makefile_contents).to match(/LIBPATH =.*-L#{c_ext_dir}/) + end + end end diff --git a/spec/support/builders.rb b/spec/support/builders.rb index df731adf14..b5a567bc17 100644 --- a/spec/support/builders.rb +++ b/spec/support/builders.rb @@ -562,10 +562,17 @@ module Spec write "ext/extconf.rb", <<-RUBY require "mkmf" + # exit 1 unless with_config("simple") extension_name = "very_simple_binary_c" - dir_config extension_name + if extra_lib_dir = with_config("ext-lib") + # add extra libpath if --with-ext-lib is + # passed in as a build_arg + dir_config extension_name, nil, extra_lib_dir + else + dir_config extension_name + end create_makefile extension_name RUBY write "ext/very_simple_binary.c", <<-C |