summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Arko <andre@arko.net>2011-09-24 15:37:06 -0700
committerAndre Arko <andre@arko.net>2011-09-24 16:32:09 -0700
commitaf6badf5080ac55c1d5f83795f44a261dc8779bf (patch)
treeb2e26c16adff798f337b4aa04ef56d2d85103dde
parentd02fa2740f75b088409d721e08b675a683f0f5e8 (diff)
downloadbundler-af6badf5080ac55c1d5f83795f44a261dc8779bf.tar.gz
Add Bundler.system_bindir, defaulted to Gem.bindir
This allows users to tell Bundler where to put the binstubs for system gems, much like the -n option in ~/.gemrc for Rubygems. If you set one, it probably makes sense to set the other. If you don't set system_bindir, though, Bundler will install system binstubs into Gem.bindir, regardless of what Rubygems does. refs #1417
-rw-r--r--lib/bundler.rb11
-rw-r--r--lib/bundler/rubygems_integration.rb7
-rw-r--r--lib/bundler/source.rb6
-rw-r--r--spec/install/gems/simple_case_spec.rb14
4 files changed, 21 insertions, 17 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index c70344c2bc..dfb7ebb0b8 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -219,13 +219,22 @@ module Bundler
SharedHelpers.default_lockfile
end
+ def system_bindir
+ # Gem.bindir doesn't always return the location that Rubygems will install
+ # system binaries. If you add a '-n foo' option to your .gemrc, Rubygems will
+ # install binstubs there instead. Unfortunately, Rubygems doesn't expose
+ # that directory at all, so rather than parse .gemrc ourselves, we allow
+ # the directory to be set as well, via `bundle config bindir foo`.
+ Bundler.settings[:system_bindir] || Gem.bindir
+ end
+
def requires_sudo?
return @requires_sudo if defined?(@checked_for_sudo)
path = bundle_path
path = path.parent until path.exist?
sudo_present = !(`which sudo` rescue '').empty?
- bin_dir = Pathname.new(Bundler.rubygems.gem_bindir)
+ bin_dir = Pathname.new(Bundler.system_bindir)
bin_dir = bin_dir.parent until bin_dir.exist?
@checked_for_sudo = true
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index 8ffbb3ec6e..7357f4ae51 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -50,12 +50,7 @@ module Bundler
end
def gem_bindir
- # We use Gem.dir/bin because on OS X, Gem.bindir is hardcoded to return
- # /usr/bin, a directory owned by root. Users who chown Gem.dir need bins
- # to be installed where they have permissions. Furthermore, the official
- # solution to change the bindir is adding -n to .gemrc, but Rubygems does
- # not honor the -n option in either Gem.bindir or Installer.new.bindir.
- File.join Gem.dir, "bin"
+ Gem.bindir
end
def user_home
diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb
index ff4240cca4..f9baad4259 100644
--- a/lib/bundler/source.rb
+++ b/lib/bundler/source.rb
@@ -86,7 +86,7 @@ module Bundler
:ignore_dependencies => true,
:wrappers => true,
:env_shebang => true,
- :bin_dir => "#{install_path}/bin"
+ :bin_dir => Bundler.system_bindir
).install
end
@@ -100,8 +100,8 @@ module Bundler
Bundler.sudo "cp -R #{Bundler.tmp}/gems/#{spec.full_name} #{Bundler.rubygems.gem_dir}/gems/"
Bundler.sudo "cp -R #{Bundler.tmp}/specifications/#{spec.full_name}.gemspec #{Bundler.rubygems.gem_dir}/specifications/"
spec.executables.each do |exe|
- Bundler.sudo "mkdir -p #{Bundler.rubygems.gem_bindir}"
- Bundler.sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Bundler.rubygems.gem_bindir}"
+ Bundler.sudo "mkdir -p #{Bundler.system_bindir}"
+ Bundler.sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Bundler.system_bindir}"
end
end
diff --git a/spec/install/gems/simple_case_spec.rb b/spec/install/gems/simple_case_spec.rb
index 86bdf5a8da..162eda35f4 100644
--- a/spec/install/gems/simple_case_spec.rb
+++ b/spec/install/gems/simple_case_spec.rb
@@ -733,22 +733,22 @@ describe "bundle install with gem sources" do
end
end
- describe "when Gem.bindir is hardcoded to a root-owned directory" do
- # On OS X, Gem.bindir is hardcoded to /usr/bin. :(
- it "installs binstubs into Gem.dir+'/bin' instead" do
+ describe "when system_bindir is set" do
+ # On OS X, Gem.bindir defaults to /usr/bin, so system_bindir is useful if
+ # you want to avoid sudo installs for system gems with OS X's default ruby
+ it "overrides Gem.bindir" do
Pathname.new("/usr/bin").should_not be_writable
-
gemfile <<-G
require 'rubygems'
- def Gem.bindir(dir=Gem.dir); "/usr/bin"; end
-
+ def Gem.bindir; "/usr/bin"; end
source "file://#{gem_repo1}"
gem "rack"
G
+ config "BUNDLE_SYSTEM_BINDIR" => system_gem_path('altbin').to_s
bundle :install
should_be_installed "rack 1.0.0"
- system_gem_path("bin/rackup").should exist
+ system_gem_path("altbin/rackup").should exist
end
end