diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2021-07-27 19:43:01 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-08-31 19:06:14 +0900 |
commit | f1c072912813f9fc226e819f9c3a770869d005c7 (patch) | |
tree | 38669ef232ecb3b69f85215afcba2825ac21ff2a | |
parent | 7465b94f8a4c2849498bf36b98be8da99c0504c2 (diff) | |
download | ruby-f1c072912813f9fc226e819f9c3a770869d005c7.tar.gz |
[rubygems/rubygems] Fix standalone generated script to deal with path sources
In the case of path sources, the path the source is pointing to should
be added directly to the `$LOAD_PATH` without any modifications.
https://github.com/rubygems/rubygems/commit/d3bba936f0
Co-authored-by: Daniel Niknam <mhmd.niknam@gmail.com>
-rw-r--r-- | lib/bundler/installer/standalone.rb | 12 | ||||
-rw-r--r-- | spec/bundler/install/gems/standalone_spec.rb | 30 |
2 files changed, 40 insertions, 2 deletions
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")}" |