diff --git a/lib/bundler/installer/standalone.rb b/lib/bundler/installer/standalone.rb index 4bd9b2e5ac..e8494b4bcd 100644 --- a/lib/bundler/installer/standalone.rb +++ b/lib/bundler/installer/standalone.rb @@ -14,7 +14,11 @@ module Bundler file.puts "require 'rbconfig'" file.puts reverse_rubygems_kernel_mixin paths.each do |path| - file.puts %($:.unshift File.expand_path("\#{__dir__}/#{path}")) + if Pathname.new(path).absolute? + file.puts %($:.unshift "#{path}") + else + file.puts %($:.unshift File.expand_path("\#{__dir__}/#{path}")) + end end end end @@ -41,7 +45,11 @@ module Bundler def gem_path(path, spec) full_path = Pathname.new(path).absolute? ? path : File.join(spec.full_gem_path, path) - Pathname.new(full_path).relative_path_from(Bundler.root.join(bundler_path)).to_s + if spec.source.instance_of?(Source::Path) + full_path + else + Pathname.new(full_path).relative_path_from(Bundler.root.join(bundler_path)).to_s + end rescue TypeError error_message = "#{spec.name} #{spec.version} has an invalid gemspec" raise Gem::InvalidSpecificationException.new(error_message) diff --git a/spec/bundler/install/gems/standalone_spec.rb b/spec/bundler/install/gems/standalone_spec.rb index fc8e24f9f5..15ffc80e69 100644 --- a/spec/bundler/install/gems/standalone_spec.rb +++ b/spec/bundler/install/gems/standalone_spec.rb @@ -147,6 +147,36 @@ RSpec.shared_examples "bundle install --standalone" do end end + describe "with Gemfiles using path sources and resulting bundle moved to a folder hierarchy with different nesting" do + before do + build_lib "minitest", "1.0.0", :path => lib_path("minitest") + + Dir.mkdir bundled_app("app") + + gemfile bundled_app("app/Gemfile"), <<-G + source "#{file_uri_for(gem_repo1)}" + gem "minitest", :path => "#{lib_path("minitest")}" + G + + bundle "install", :standalone => true, :dir => bundled_app("app") + + Dir.mkdir tmp("one_more_level") + FileUtils.mv bundled_app, tmp("one_more_level") + end + + it "also works" do + ruby <<-RUBY, :dir => tmp("one_more_level/bundled_app/app") + require "./bundle/bundler/setup" + + require "minitest" + puts MINITEST + RUBY + + expect(out).to eq("1.0.0") + expect(err).to be_empty + end + end + describe "with gems with native extension", :ruby_repo do before do bundle "config set --local path #{bundled_app("bundle")}"