diff options
author | The Bundler Bot <bot@bundler.io> | 2017-08-18 03:46:33 +0000 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2017-08-19 11:52:54 -0400 |
commit | 76aa287eed961376c17c0611fe41902c035452f7 (patch) | |
tree | 8fc10c1bc4933bcf6baa87ed24bfc3494bb4a3a6 /lib | |
parent | 4da4649c579aa0b922442966dde50af2210d263f (diff) | |
download | bundler-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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/cli/pristine.rb | 17 |
1 files changed, 10 insertions, 7 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 |