Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edge case resulting in a crash when using zeitwerk inside a nested bundle exec invocation #4062

Merged
merged 2 commits into from Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions bundler/lib/bundler.rb
Expand Up @@ -602,6 +602,10 @@ def reset!
reset_rubygems!
end

def reset_settings!
@settings = nil
end

def reset_paths!
@bin_path = nil
@bundler_major_version = nil
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/cli.rb
Expand Up @@ -57,7 +57,7 @@ def initialize(*args)
custom_gemfile = options[:gemfile] || Bundler.settings[:gemfile]
if custom_gemfile && !custom_gemfile.empty?
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", File.expand_path(custom_gemfile)
Bundler.reset_paths!
Bundler.reset_settings!
end

Bundler.settings.set_command_option_if_given :retry, options[:retry]
Expand Down
47 changes: 45 additions & 2 deletions bundler/spec/commands/exec_spec.rb
Expand Up @@ -865,6 +865,8 @@ def bin_path(a,b,c)
context "nested bundle exec" do
context "when bundle in a local path" do
before do
skip "https://github.com/rubygems/rubygems/issues/3351" if Gem.win_platform?

gemfile <<-G
source "#{file_uri_for(gem_repo1)}"
gem "rack"
Expand All @@ -874,8 +876,6 @@ def bin_path(a,b,c)
end

it "correctly shells out" do
skip "https://github.com/rubygems/rubygems/issues/3351" if Gem.win_platform?

file = bundled_app("file_that_bundle_execs.rb")
create_file(file, <<-RUBY)
#!#{Gem.ruby}
Expand All @@ -887,6 +887,49 @@ def bin_path(a,b,c)
end
end

context "when Kernel.require uses extra monkeypatches" do
before do
skip "https://github.com/rubygems/rubygems/issues/3351" if Gem.win_platform?

install_gemfile ""
end

it "does not undo the monkeypatches" do
karafka = bundled_app("bin/karafka")
create_file(karafka, <<~RUBY)
#!#{Gem.ruby}

module Kernel
module_function

alias_method :require_before_extra_monkeypatches, :require

def require(path)
puts "requiring \#{path} used the monkeypatch"

require_before_extra_monkeypatches(path)
end
end

Bundler.setup(:default)

require "foo"
RUBY
karafka.chmod(0o777)

foreman = bundled_app("bin/foreman")
create_file(foreman, <<~RUBY)
#!#{Gem.ruby}

puts `bundle exec bin/karafka`
RUBY
foreman.chmod(0o777)

bundle "exec #{foreman}"
expect(out).to eq("requiring foo used the monkeypatch")
end
end

context "with a system gem that shadows a default gem" do
let(:openssl_version) { "99.9.9" }
let(:expected) { ruby "gem 'openssl', '< 999999'; require 'openssl'; puts OpenSSL::VERSION", :artifice => nil, :raise_on_error => false }
Expand Down