Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Go back to generating ./bin/gem_bin_stub
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Lerche committed Jul 9, 2010
1 parent 2199c87 commit ce7db1b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 52 deletions.
2 changes: 1 addition & 1 deletion lib/bundler.rb
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions lib/bundler/installer.rb
@@ -1,3 +1,4 @@
require 'erb'
require 'rubygems/dependency_installer'

module Bundler
Expand Down Expand Up @@ -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
34 changes: 10 additions & 24 deletions lib/bundler/templates/Executable
@@ -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 %>')
27 changes: 4 additions & 23 deletions spec/runtime/executable_spec.rb
@@ -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}"
Expand All @@ -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"
Expand All @@ -27,7 +27,7 @@

Dir.chdir(tmp) do
gembin "rackup"
out.should == "2.0"
out.should == "1.0.0"
end
end

Expand All @@ -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"
Expand All @@ -77,6 +58,6 @@
gem "bundler"
G

home(".bundler/bin/bundle").should_not exist
bundled_app("bin/bundle").should_not exist
end
end
2 changes: 1 addition & 1 deletion spec/support/helpers.rb
Expand Up @@ -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
Expand Down

0 comments on commit ce7db1b

Please sign in to comment.