From 6e66ee423532c38287ebc656dd4bb24a5d42cbd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 30 May 2022 21:46:47 +0200 Subject: [PATCH 1/2] Remove code that seems unnecessary This change was never covered with a spec, and we have recently covered the case of partially deleted gems with specs and it works fine (installation is "auto-healed"). --- bundler/lib/bundler/stub_specification.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bundler/lib/bundler/stub_specification.rb b/bundler/lib/bundler/stub_specification.rb index fa071901e587..4a23b2cfe8ad 100644 --- a/bundler/lib/bundler/stub_specification.rb +++ b/bundler/lib/bundler/stub_specification.rb @@ -64,9 +64,7 @@ def default_gem? end def full_gem_path - # deleted gems can have their stubs return nil, so in that case grab the - # expired path from the full spec - stub.full_gem_path || method_missing(:full_gem_path) + stub.full_gem_path end def full_require_paths From efa41babfa5ef2f6a3263a63104643eb3a4c74c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 30 May 2022 21:48:49 +0200 Subject: [PATCH 2/2] Fix generated standalone script for default gems The installer is actually rewriting the spec's full gem path to be the one of the newly installed gem, however the accessor was not properly working for `StubSpecification` instances, and default gems are always of this type, because they are always present locally. Fix the accessor to properly update the underlying full specification. --- bundler/lib/bundler/stub_specification.rb | 4 ++++ bundler/spec/install/gems/standalone_spec.rb | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/bundler/lib/bundler/stub_specification.rb b/bundler/lib/bundler/stub_specification.rb index 4a23b2cfe8ad..88a4257fa452 100644 --- a/bundler/lib/bundler/stub_specification.rb +++ b/bundler/lib/bundler/stub_specification.rb @@ -67,6 +67,10 @@ def full_gem_path stub.full_gem_path end + def full_gem_path=(path) + stub.full_gem_path = path + end + def full_require_paths stub.full_require_paths end diff --git a/bundler/spec/install/gems/standalone_spec.rb b/bundler/spec/install/gems/standalone_spec.rb index 5cbb484c682c..0bbd8291485f 100644 --- a/bundler/spec/install/gems/standalone_spec.rb +++ b/bundler/spec/install/gems/standalone_spec.rb @@ -147,9 +147,16 @@ bundle "lock", :dir => cwd, :artifice => "compact_index" end - it "works" do + it "works and points to the vendored copies, not to the default copies" do bundle "config set --local path #{bundled_app("bundle")}" bundle :install, :standalone => true, :dir => cwd, :artifice => "compact_index", :env => { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s } + + load_path_lines = bundled_app("bundle/bundler/setup.rb").read.split("\n").select {|line| line.start_with?("$:.unshift") } + + expect(load_path_lines).to eq [ + '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{RbConfig::CONFIG["ruby_version"]}/gems/bar-1.0.0/lib")', + '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{RbConfig::CONFIG["ruby_version"]}/gems/foo-1.0.0/lib")', + ] end end