Permalink
Browse files

Go back to generating ./bin/gem_bin_stub

  • Loading branch information...
1 parent 2199c87 commit ce7db1b17ffe43582258b18fb196aad0ec67bc42 Carl Lerche committed Jul 9, 2010
Showing with 23 additions and 52 deletions.
  1. +1 −1 lib/bundler.rb
  2. +7 −3 lib/bundler/installer.rb
  3. +10 −24 lib/bundler/templates/Executable
  4. +4 −23 spec/runtime/executable_spec.rb
  5. +1 −1 spec/support/helpers.rb
View
@@ -83,7 +83,7 @@ def bundle_path
def bin_path
@bin_path ||= begin
- path = settings[:bin] || "#{Gem.user_home}/.bundle/bin"
+ path = settings[:bin] || "#{root}/bin"
FileUtils.mkdir_p(path)
Pathname.new(path).expand_path
end
View
@@ -1,3 +1,4 @@
+require 'erb'
require 'rubygems/dependency_installer'
module Bundler
@@ -46,13 +47,16 @@ def run(options)
private
def generate_bundler_executable_stubs(spec)
+ bin_path = Bundler.bin_path
+ template = File.read(File.expand_path('../templates/Executable', __FILE__))
+ relative_gemfile_path = Bundler.default_gemfile.relative_path_from(bin_path)
+
spec.executables.each do |executable|
next if executable == "bundle"
- File.open "#{Bundler.bin_path}/#{executable}", 'w', 0755 do |f|
- f.puts File.read(File.expand_path('../templates/Executable', __FILE__))
+ File.open "#{bin_path}/#{executable}", 'w', 0755 do |f|
+ f.puts ERB.new(template, nil, '-').result(binding)
end
end
end
-
end
end
@@ -1,28 +1,14 @@
#!/usr/bin/env ruby
-# This is not actually required by the actual library
-# loads the bundled environment
-require 'rubygems'
-
-begin
- require 'bundler/setup'
-rescue LoadError
- # Let's not complain if bundler isn't around
-end
-
-base = File.basename($0)
-paths = ENV['PATH'].split(File::PATH_SEPARATOR)
-here = File.expand_path(File.dirname(__FILE__))
+#
+# 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.
+#
-gem_stub = paths.find do |path|
- path = File.expand_path(path)
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../<%= relative_gemfile_path %>", __FILE__)
- next if path == here
-
- File.exist?("#{path}/#{base}")
-end
+require 'rubygems'
+require 'bundler/setup'
-if gem_stub
- load "#{gem_stub}/#{base}"
-else
- abort "The gem stub #{base} could not be found"
-end
+load Gem.bin_path('<%= spec.name %>', '<%= executable %>')
@@ -1,6 +1,6 @@
require "spec_helper"
-describe "Running commands" do
+describe "Running bin/* commands" do
it "runs the bundled command when in the bundle" do
install_gemfile <<-G
source "file://#{gem_repo1}"
@@ -15,7 +15,7 @@
out.should == "1.0.0"
end
- it "runs the system command when out of the bundle" do
+ it "runs the bundled command when out of the bundle" do
install_gemfile <<-G
source "file://#{gem_repo1}"
gem "rack"
@@ -27,7 +27,7 @@
Dir.chdir(tmp) do
gembin "rackup"
- out.should == "2.0"
+ out.should == "1.0.0"
end
end
@@ -48,25 +48,6 @@
out.should == '1.0'
end
- it "blows up when running outside of the directory" do
- build_lib "rack", :path => lib_path("rack") do |s|
- s.executables = 'rackup'
- end
-
- install_gemfile <<-G
- gem "rack", :path => "#{lib_path('rack')}"
- G
-
- build_gem 'rack', '2.0', :to_system => true do |s|
- s.executables = 'rackup'
- end
-
- Dir.chdir(tmp) do
- gembin "rackup"
- out.should == '2.0'
- end
- end
-
it "don't bundle da bundla" do
build_gem "bundler", Bundler::VERSION, :to_system => true do |s|
s.executables = "bundle"
@@ -77,6 +58,6 @@
gem "bundler"
G
- home(".bundler/bin/bundle").should_not exist
+ bundled_app("bin/bundle").should_not exist
end
end
View
@@ -72,7 +72,7 @@ def ruby(ruby, options = {})
def gembin(cmd)
lib = File.expand_path("../../../lib", __FILE__)
old, ENV['RUBYOPT'] = ENV['RUBYOPT'], "#{ENV['RUBYOPT']} -I#{lib}"
- sys_exec(cmd)
+ sys_exec(bundled_app("bin/#{cmd}"))
ensure
ENV['RUBYOPT'] = old
end

0 comments on commit ce7db1b

Please sign in to comment.