summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-08-18 03:46:33 +0000
committerSamuel Giddins <segiddins@segiddins.me>2017-08-19 11:52:54 -0400
commit76aa287eed961376c17c0611fe41902c035452f7 (patch)
tree8fc10c1bc4933bcf6baa87ed24bfc3494bb4a3a6
parent4da4649c579aa0b922442966dde50af2210d263f (diff)
downloadbundler-76aa287eed961376c17c0611fe41902c035452f7.tar.gz
Auto merge of #5933 - NickLaMuro:bundle-pristine-respect-bundler-config, r=segiddins
Use Bundler::Installer for bundle pristine Fixes bundler pristine to respect the `bundle config` options for particular gems. In my particular case, on OSX I have a keg version of `pg` and a bundle config with the following entry: ```console $ bundle config ... build.pg Set for the current user (/Users/nicklamuro/.bundle/config): "--with-pg-config=/usr/local/Cellar/postgresql@9.5/9.5.6/bin/pg_config" ``` This would not be respected What was the end-user problem that led to this PR? -------------------------------------------------- See above, but steps to reproduce (requires `bundler` >= 1.15): 1. Install postgres on your machine if it is not already there (OS dependent) 2. Add the following bundler build arg for `pg`: ```console $ bundle config build.pg -- --with-pg-config=$(which pg_config) ``` 2. Make sure `pg_config` is not in your `$PATH`: ```console $ export PATH=$(echo "$PATH" | sed "s|:$(dirname $(which pg_conf)))||") ``` * Create a simple project with `pg` as a single gem in your Gemfile: ``` # Gemfile gem "pg" ``` * Bundle: ```console $ bundle install ``` * Attempt to `bundle pristine` (you should get an error): ```console $ bundle pristine ``` What was your diagnosis of the problem? --------------------------------------- The newly added `bundle pristine` did no use the same code that was used by `bundle install` to execute the re-installation of the gem. What is your fix for the problem, implemented in this PR? --------------------------------------------------------- By making use of the `Bundler::Installer` and `Bundler::Installer::GemInstaller` code that is already used with `bundle install`, we can reuse the code that injects the `bundle config` options into each gem that is being installed. Why did you choose this fix out of the possible options? -------------------------------------------------------- Didn't want to repeat code that was already being used elsewhere. Caused a few lines of code to be added that weren't there previously, but nothing obscene. (cherry picked from commit da6a52a9b255147b389d29e2b22ce397bbb8377b) # Conflicts: # lib/bundler/cli/pristine.rb # spec/commands/pristine_spec.rb
-rw-r--r--lib/bundler/cli/pristine.rb17
-rw-r--r--spec/commands/pristine_spec.rb19
-rw-r--r--spec/support/builders.rb9
3 files changed, 37 insertions, 8 deletions
diff --git a/lib/bundler/cli/pristine.rb b/lib/bundler/cli/pristine.rb
index 30542b583e..10d03b4b41 100644
--- a/lib/bundler/cli/pristine.rb
+++ b/lib/bundler/cli/pristine.rb
@@ -4,29 +4,32 @@ require "bundler/cli/common"
module Bundler
class CLI::Pristine
def run
+ 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
gem_name = "#{spec.name} (#{spec.version}#{spec.git_version})"
gem_name += " (#{spec.platform})" if !spec.platform.nil? && spec.platform != Gem::Platform::RUBY
- case spec.source
+ case source = spec.source
when Source::Rubygems
cached_gem = spec.cache_file
unless File.exist?(cached_gem)
Bundler.ui.error("Failed to pristine #{gem_name}. Cached gem #{cached_gem} does not exist.")
next
end
-
- FileUtils.rm_rf spec.full_gem_path
- spec.source.install(spec, :force => true)
when Source::Git
- git_source = spec.source
- git_source.remote!
- git_source.install(spec, :force => true)
+ source.remote!
else
Bundler.ui.warn("Cannot pristine #{gem_name}. Gem is sourced from local path.")
+ next
end
+ FileUtils.rm_rf spec.full_gem_path
+
+ 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 a6f991bb4a..5f5e694bc3 100644
--- a/spec/commands/pristine_spec.rb
+++ b/spec/commands/pristine_spec.rb
@@ -12,6 +12,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
@@ -19,6 +20,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")}"
@@ -99,4 +101,21 @@ RSpec.describe "bundle pristine" do
expect(changes_txt).to be_file
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 28a271998e..db128d497b 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