diff options
author | Terin Stock <terinjokes@gmail.com> | 2016-07-13 17:47:35 -0700 |
---|---|---|
committer | Terin Stock <terinjokes@gmail.com> | 2016-08-12 18:38:53 -0700 |
commit | a14c2fb4b900e6ba83513034ab33c22d592620f6 (patch) | |
tree | 7f1975e97e918415b2486381254a4c2b2570f75c | |
parent | 1873fa56790c582bbc744e558224b94d64184267 (diff) | |
download | bundler-a14c2fb4b900e6ba83513034ab33c22d592620f6.tar.gz |
fix standalone executable when dest of symlink
When an executable is the destination of a symlink `__FILE__` contains
the path to the symlink, rather than the actual path of the current
file.
Pathname#realpath resolves symlinks to get the actual location on disk.
-rw-r--r-- | lib/bundler/templates/Executable.standalone | 6 | ||||
-rw-r--r-- | spec/commands/binstubs_spec.rb | 2 | ||||
-rw-r--r-- | spec/install/gems/standalone_spec.rb | 17 |
3 files changed, 20 insertions, 5 deletions
diff --git a/lib/bundler/templates/Executable.standalone b/lib/bundler/templates/Executable.standalone index c4f2703495..c114afe337 100644 --- a/lib/bundler/templates/Executable.standalone +++ b/lib/bundler/templates/Executable.standalone @@ -6,7 +6,9 @@ # this file is here to facilitate running it. # -$:.unshift File.expand_path '../<%= standalone_path %>', __FILE__ +require 'pathname' +path = Pathname.new(__FILE__) +$:.unshift File.expand_path '../<%= standalone_path %>', path.realpath require 'bundler/setup' -load File.expand_path '../<%= executable_path %>', __FILE__ +load File.expand_path '../<%= executable_path %>', path.realpath diff --git a/spec/commands/binstubs_spec.rb b/spec/commands/binstubs_spec.rb index 35c9d187a0..0f8c5af391 100644 --- a/spec/commands/binstubs_spec.rb +++ b/spec/commands/binstubs_spec.rb @@ -157,7 +157,7 @@ describe "bundle binstubs <gem>" do it "includes the standalone path" do bundle "binstubs rack --standalone" standalone_line = File.read(bundled_app("bin/rackup")).each_line.find {|line| line.include? "$:.unshift" }.strip - expect(standalone_line).to eq "$:.unshift File.expand_path '../../bundle', __FILE__" + expect(standalone_line).to eq "$:.unshift File.expand_path '../../bundle', path.realpath" end end diff --git a/spec/install/gems/standalone_spec.rb b/spec/install/gems/standalone_spec.rb index 64e01a7495..7a6749dea9 100644 --- a/spec/install/gems/standalone_spec.rb +++ b/spec/install/gems/standalone_spec.rb @@ -279,13 +279,26 @@ shared_examples "bundle install --standalone" do it "creates stubs that can be executed from anywhere" do require "tmpdir" Dir.chdir(Dir.tmpdir) do - expect(`#{bundled_app("bin/rails")} -v`.chomp).to eql "2.3.2" + sys_exec!(%(#{bundled_app("bin/rails")} -v)) + expect(out).to eq("2.3.2") end end + it "creates stubs that can be symlinked" do + pending "File.symlink is unsupported on Windows" if Bundler::WINDOWS + + symlink_dir = tmp("symlink") + FileUtils.mkdir_p(symlink_dir) + symlink = File.join(symlink_dir, "rails") + + File.symlink(bundled_app("bin/rails"), symlink) + sys_exec!("#{symlink} -v") + expect(out).to eq("2.3.2") + 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__" + expect(extension_line).to eq "$:.unshift File.expand_path '../../bundle', path.realpath" end end end |