From 1571c520c7223d4eef7ac9a167683ad60048ae6f Mon Sep 17 00:00:00 2001 From: Glenn Pratt Date: Mon, 1 Feb 2016 12:50:08 -0600 Subject: Make standalone bin load path relative to Bundler.root rather than CWD. Fixes #4144 --- lib/bundler/installer.rb | 2 +- spec/install/gems/standalone_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 3a54a02151..10ba3005d1 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -130,12 +130,12 @@ module Bundler def generate_standalone_bundler_executable_stubs(spec) # double-assignment to avoid warnings about variables that will be used by ERB bin_path = Bundler.bin_path + standalone_path = standalone_path = Bundler.root.join(Bundler.settings[:path]).relative_path_from(bin_path) template = File.read(File.expand_path("../templates/Executable.standalone", __FILE__)) ruby_command = ruby_command = Thor::Util.ruby_command spec.executables.each do |executable| next if executable == "bundle" - standalone_path = standalone_path = Pathname(Bundler.settings[:path]).expand_path.relative_path_from(bin_path) executable_path = executable_path = Pathname(spec.full_gem_path).join(spec.bindir, executable).relative_path_from(bin_path) File.open "#{bin_path}/#{executable}", "w", 0755 do |f| f.puts ERB.new(template, nil, "-").result(binding) diff --git a/spec/install/gems/standalone_spec.rb b/spec/install/gems/standalone_spec.rb index 4ce5d92eb0..d0f5af709f 100644 --- a/spec/install/gems/standalone_spec.rb +++ b/spec/install/gems/standalone_spec.rb @@ -272,5 +272,35 @@ describe "bundle install --standalone" do expect(`#{bundled_app}/bin/rails -v`.chomp).to eql "2.3.2" end end + + it "creates stubs with the correct load path" do + extension_line = File.read(bundled_app("bin/rails")).each_line.find {|line| line.include? "$:.unshift" }.strip + expect(extension_line).to eq "$:.unshift File.expand_path '../../bundle', __FILE__" + end + end + + describe "with --binstubs run in a subdirectory" do + before do + FileUtils.mkdir_p("bob") + Dir.chdir("bob") do + install_gemfile <<-G, :standalone => true, :binstubs => true + source "file://#{gem_repo1}" + gem "rails" + G + end + end + + # @todo This test fails because the bundler/setup.rb is written to the + # current directory. + xit "creates stubs that use the standalone load path" do + Dir.chdir(bundled_app) do + expect(`bin/rails -v`.chomp).to eql "2.3.2" + end + end + + it "creates stubs with the correct load path" do + extension_line = File.read(bundled_app("bin/rails")).each_line.find {|line| line.include? "$:.unshift" }.strip + expect(extension_line).to eq "$:.unshift File.expand_path '../../bundle', __FILE__" + end end end -- cgit v1.2.1