[前][次][番号順一覧][スレッド一覧]

ruby-changes:67431

From: David <ko1@a...>
Date: Tue, 31 Aug 2021 19:07:12 +0900 (JST)
Subject: [ruby-changes:67431] f1c0729128 (master): [rubygems/rubygems] Fix standalone generated script to deal with path sources

https://git.ruby-lang.org/ruby.git/commit/?id=f1c0729128

From f1c072912813f9fc226e819f9c3a770869d005c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Tue, 27 Jul 2021 19:43:01 +0200
Subject: [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@g...>
---
 lib/bundler/installer/standalone.rb          | 12 +++++++++--
 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 4bd9b2e..e8494b4 100644
--- a/lib/bundler/installer/standalone.rb
+++ b/lib/bundler/installer/standalone.rb
@@ -14,7 +14,11 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/installer/standalone.rb#L14
         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 https://github.com/ruby/ruby/blob/trunk/lib/bundler/installer/standalone.rb#L45
 
     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 fc8e24f..15ffc80 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 https://github.com/ruby/ruby/blob/trunk/spec/bundler/install/gems/standalone_spec.rb#L147
     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")}"
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]