diff options
author | Charles Lowell <cowboyd@thefrontside.net> | 2011-12-12 11:52:03 -0600 |
---|---|---|
committer | Charles Lowell <cowboyd@thefrontside.net> | 2011-12-12 12:09:46 -0600 |
commit | da6d698afc6fbe4c4585831e372ac9437f986162 (patch) | |
tree | 6e60faceeed934faea2cb50e0a24ecdaed3c5ebd | |
parent | 3562da13499f48ea88fadd7a41d39b12ee6d21be (diff) | |
download | bundler-da6d698afc6fbe4c4585831e372ac9437f986162.tar.gz |
Ensure binstubs generated when using --standalone point to the standalone bundle.
-rw-r--r-- | lib/bundler/installer.rb | 26 | ||||
-rw-r--r-- | lib/bundler/templates/Executable.standalone | 12 | ||||
-rw-r--r-- | spec/install/gems/standalone_spec.rb | 16 |
3 files changed, 50 insertions, 4 deletions
diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index c8a9e4b2a2..b00dfa6dab 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -53,7 +53,7 @@ module Bundler # the gem. Installer.post_install_messages = {} specs.each do |spec| - install_gem_from_spec(spec) + install_gem_from_spec(spec, options[:standalone]) end lock @@ -62,7 +62,7 @@ module Bundler private - def install_gem_from_spec(spec) + def install_gem_from_spec(spec, standalone = false) # Download the gem to get the spec, because some specs that are returned # by rubygems.org are broken and wrong. Bundler::Fetcher.fetch(spec) if spec.source.is_a?(Bundler::Source::Rubygems) @@ -76,7 +76,10 @@ module Bundler # newline comes after installing, some gems say "with native extensions" Bundler.ui.info "" - generate_bundler_executable_stubs(spec) if Bundler.settings[:bin] + if Bundler.settings[:bin] + standalone ? generate_standalone_bundler_executable_stubs(spec) : generate_bundler_executable_stubs(spec) + end + FileUtils.rm_rf(Bundler.tmp) rescue Exception => e # install hook failed @@ -93,7 +96,7 @@ module Bundler def generate_bundler_executable_stubs(spec) bin_path = Bundler.bin_path - template = File.read(File.expand_path('../templates/Executable', __FILE__)) + template = File.read(File.expand_path("../templates/Executable", __FILE__)) relative_gemfile_path = Bundler.default_gemfile.relative_path_from(bin_path) ruby_command = Thor::Util.ruby_command @@ -105,6 +108,21 @@ module Bundler end end + def generate_standalone_bundler_executable_stubs(spec) + bin_path = Bundler.bin_path + template = File.read(File.expand_path("../templates/Executable.standalone", __FILE__)) + ruby_command = Thor::Util.ruby_command + + spec.executables.each do |executable| + next if executable == "bundle" + standalone_path = Pathname(Bundler.settings[:path]).expand_path.relative_path_from(bin_path) + executable_path = Pathname(spec.full_gem_path).join(spec.bindir, executable).relative_path_from(Bundler.root) + File.open "#{bin_path}/#{executable}", 'w', 0755 do |f| + f.puts ERB.new(template, nil, '-').result(binding) + end + end + end + def generate_standalone(groups) standalone_path = Bundler.settings[:path] bundler_path = File.join(standalone_path, "bundler") diff --git a/lib/bundler/templates/Executable.standalone b/lib/bundler/templates/Executable.standalone new file mode 100644 index 0000000000..d9378d253f --- /dev/null +++ b/lib/bundler/templates/Executable.standalone @@ -0,0 +1,12 @@ +#!/usr/bin/env <%= Bundler.settings[:shebang] || RbConfig::CONFIG['ruby_install_name'] %> +# +# This file was generated by Bundler. +# +# The application '<%= executable %>' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +$:.unshift File.expand_path '../<%= standalone_path %>', __FILE__ + +require 'bundler/setup' +load '<%= executable_path %>' diff --git a/spec/install/gems/standalone_spec.rb b/spec/install/gems/standalone_spec.rb index 9752f47ce5..9a47f6108a 100644 --- a/spec/install/gems/standalone_spec.rb +++ b/spec/install/gems/standalone_spec.rb @@ -235,4 +235,20 @@ describe "bundle install --standalone" do end end end + + describe "with --binstubs" do + before do + install_gemfile <<-G, :standalone => true, :binstubs => true + source "file://#{gem_repo1}" + gem "rails" + G + end + + it "creates stubs that use the standalone load path" do + should_be_installed "actionpack 2.3.2", "rails 2.3.2" + Dir.chdir(bundled_app) do + `bin/rails -v`.chomp.should eql "2.3.2" + end + end + end end |