diff options
author | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-08-18 15:41:12 -0700 |
---|---|---|
committer | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-08-18 15:41:12 -0700 |
commit | dc7016a7ef4c53ef3aeba6bfb58af0f67a763e0e (patch) | |
tree | 8c29fa48fd1de1d290221dee61119d5043e460f3 | |
parent | 894161cd7bb4625a07897f5e45838eac8bd13fb0 (diff) | |
download | bundler-dc7016a7ef4c53ef3aeba6bfb58af0f67a763e0e.tar.gz |
Make all paths relative
-rw-r--r-- | lib/bundler/gem_ext.rb | 4 | ||||
-rw-r--r-- | lib/bundler/manifest.rb | 23 | ||||
-rw-r--r-- | lib/bundler/templates/app_script.erb | 3 | ||||
-rw-r--r-- | lib/bundler/templates/app_script.rb | 3 | ||||
-rw-r--r-- | lib/bundler/templates/environment.erb (renamed from lib/bundler/templates/environment.rb) | 48 | ||||
-rw-r--r-- | spec/bundler/cli_spec.rb | 5 |
6 files changed, 48 insertions, 38 deletions
diff --git a/lib/bundler/gem_ext.rb b/lib/bundler/gem_ext.rb index 6ca7286441..f8ad250fa6 100644 --- a/lib/bundler/gem_ext.rb +++ b/lib/bundler/gem_ext.rb @@ -2,8 +2,8 @@ module Gem class Installer def app_script_text(bin_file_name) path = @gem_home - template = File.read(File.join(File.dirname(__FILE__), "templates", "app_script.rb")) - erb = ERB.new(template) + template = File.read(File.join(File.dirname(__FILE__), "templates", "app_script.erb")) + erb = ERB.new(template, nil, '-') erb.result(binding) end end diff --git a/lib/bundler/manifest.rb b/lib/bundler/manifest.rb index df99aeeff0..22d3cacb4e 100644 --- a/lib/bundler/manifest.rb +++ b/lib/bundler/manifest.rb @@ -10,7 +10,7 @@ module Bundler @filename = filename @sources = sources @dependencies = dependencies - @bindir = bindir + @bindir = bindir || repository.path.join("bin") @path = path @rubygems = rubygems @system_gems = system_gems @@ -18,7 +18,7 @@ module Bundler def install(update) fetch(update) - repository.install_cached_gems(:bin_dir => @bindir || repository.path.join("bin")) + repository.install_cached_gems(:bin_dir => @bindir) # Cleanup incase fetch was a no-op repository.cleanup(gems) create_environment_file(repository.path) @@ -83,13 +83,16 @@ module Bundler def create_environment_file(path) FileUtils.mkdir_p(path) - specs = gems + + specs = gems spec_files = spec_files_for_specs(specs, path) load_paths = load_paths_for_specs(specs) + bindir = @bindir.relative_path_from(path).to_s + filename = @filename.relative_path_from(path).to_s File.open(path.join("environment.rb"), "w") do |file| - template = File.read(File.join(File.dirname(__FILE__), "templates", "environment.rb")) - erb = ERB.new(template) + template = File.read(File.join(File.dirname(__FILE__), "templates", "environment.erb")) + erb = ERB.new(template, nil, '-') file.puts erb.result(binding) end end @@ -97,9 +100,13 @@ module Bundler def load_paths_for_specs(specs) load_paths = [] specs.each do |spec| - load_paths << File.join(spec.full_gem_path, spec.bindir) if spec.bindir + gem_path = Pathname.new(spec.full_gem_path) + + if spec.bindir + load_paths << gem_path.join(spec.bindir).relative_path_from(@path).to_s + end spec.require_paths.each do |path| - load_paths << File.join(spec.full_gem_path, path) + load_paths << gem_path.join(path).relative_path_from(@path).to_s end end load_paths @@ -108,7 +115,7 @@ module Bundler def spec_files_for_specs(specs, path) files = {} specs.each do |s| - files[s.name] = path.join("specifications", "#{s.full_name}.gemspec").expand_path + files[s.name] = File.join("specifications", "#{s.full_name}.gemspec") end files end diff --git a/lib/bundler/templates/app_script.erb b/lib/bundler/templates/app_script.erb new file mode 100644 index 0000000000..3e47a53ca8 --- /dev/null +++ b/lib/bundler/templates/app_script.erb @@ -0,0 +1,3 @@ +<%= shebang bin_file_name %> +require File.join(File.dirname(__FILE__), "<%= path.join("environment").relative_path_from(Pathname.new(bin_dir)) %>") +load File.join(File.dirname(__FILE__), "<%= path.join("gems", @spec.full_name, @spec.bindir, bin_file_name).relative_path_from(Pathname.new(bin_dir)) %>")
\ No newline at end of file diff --git a/lib/bundler/templates/app_script.rb b/lib/bundler/templates/app_script.rb deleted file mode 100644 index 91f37510ae..0000000000 --- a/lib/bundler/templates/app_script.rb +++ /dev/null @@ -1,3 +0,0 @@ -<%= shebang bin_file_name %> -require "<%= path.join("environments", "default") %>" -load "<%= path.join("gems", @spec.full_name, @spec.bindir, bin_file_name) %>"
\ No newline at end of file diff --git a/lib/bundler/templates/environment.rb b/lib/bundler/templates/environment.erb index 6aeec99267..2c538e9273 100644 --- a/lib/bundler/templates/environment.rb +++ b/lib/bundler/templates/environment.erb @@ -1,32 +1,30 @@ -<% unless @system_gems %> -ENV["GEM_HOME"] = "<%= @repository.path %>" -ENV["GEM_PATH"] = "<%= @repository.path %>" -<% end %> -ENV["PATH"] = "<%= @bindir %>:#{ENV["PATH"]}" -ENV["RUBYOPT"] = "-r#{__FILE__} #{ENV["RUBYOPT"]}" +module Bundler + dir = File.dirname(__FILE__) -<% load_paths.each do |load_path| %> -$LOAD_PATH.unshift "<%= load_path %>" -<% end %> +<% unless @system_gems -%> + ENV["GEM_HOME"] = dir + ENV["GEM_PATH"] = dir +<% end -%> + ENV["PATH"] = "#{dir}/<%= bindir %>:#{ENV["PATH"]}" + ENV["RUBYOPT"] = "-r#{__FILE__} #{ENV["RUBYOPT"]}" -<% if @rubygems %> -require "rubygems" +<% load_paths.each do |load_path| -%> + $LOAD_PATH.unshift "#{dir}/<%= load_path %>" +<% end -%> -module Bundler + @gemfile = "#{dir}/<%= filename %>" - @gemfile = "<%= @filename %>" +<% if @rubygems -%> + require "rubygems" @bundled_specs = {} - <% spec_files.each do |name, path| %> - @bundled_specs["<%= name %>"] = eval(File.read("<%= path %>")) - @bundled_specs["<%= name %>"].loaded_from = "<%= path %>" - <% end %> +<% spec_files.each do |name, path| -%> + @bundled_specs["<%= name %>"] = eval(File.read("#{dir}/<%= path %>")) + @bundled_specs["<%= name %>"].loaded_from = "#{dir}/<%= path %>" +<% end -%> def self.add_specs_to_loaded_specs Gem.loaded_specs.merge! @bundled_specs - if Gem.respond_to?(:loaded_stacks) - @bundled_specs.keys.each { |name| Gem.loaded_stacks[name] = [] } - end end def self.add_specs_to_index @@ -37,18 +35,19 @@ module Bundler add_specs_to_loaded_specs add_specs_to_index +<% end -%> end +<% if @rubygems -%> module Gem def source_index.refresh! super Bundler.add_specs_to_index end end - -<% else %> - +<% else -%> $" << "rubygems.rb" + module Kernel def gem(*) # Silently ignore calls to gem, since, in theory, everything @@ -80,7 +79,6 @@ module Gem class VerificationError < Exception; end class SystemExitException < SystemExit; end end - -<% end %> +<% end -%> require "bundler/runtime"
\ No newline at end of file diff --git a/spec/bundler/cli_spec.rb b/spec/bundler/cli_spec.rb index 2f486729ca..2e36741074 100644 --- a/spec/bundler/cli_spec.rb +++ b/spec/bundler/cli_spec.rb @@ -41,6 +41,11 @@ describe "Bundler::CLI" do out.should include(tmp_file("vendor", "gems", "gems", "rack-0.9.1").to_s) end + it "creates valid executables" do + out = `#{tmp_file("bin", "rake")} -e 'require "extlib" ; puts Extlib'`.strip + out.should == "Extlib" + end + it "maintains the correct environment when shelling out" do out = run_in_context "exec %{#{Gem.ruby} -e 'require %{very-simple} ; puts VerySimpleForTests'}" out.should == "VerySimpleForTests" |