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

Commit

Permalink
Auto merge of #4782 - terinjokes:terin/symlink-standalone-binstub, r=…
Browse files Browse the repository at this point in the history
…indirect

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.
  • Loading branch information
homu committed Aug 15, 2016
2 parents 9ab10d6 + a14c2fb commit fccf3f9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/bundler/templates/Executable.standalone
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/commands/binstubs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
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

Expand Down
17 changes: 15 additions & 2 deletions spec/install/gems/standalone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,26 @@
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
Expand Down

0 comments on commit fccf3f9

Please sign in to comment.