From 226ec115fe503bcc93bffdf5cd3e8a668890b4d8 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Tue, 7 Aug 2018 00:15:10 -0700 Subject: [PATCH] Always avoid loading the full spec when checking extensions By explicitly defining a couple more methods, we can avoid loading the full specification in all cases, including pathological ones that currently lead to stackoverflow errors. --- bundler/lib/bundler/stub_specification.rb | 14 +++++++++++++- bundler/spec/commands/exec_spec.rb | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/bundler/lib/bundler/stub_specification.rb b/bundler/lib/bundler/stub_specification.rb index 54a40c1c78da..c87b66ee19b0 100644 --- a/bundler/lib/bundler/stub_specification.rb +++ b/bundler/lib/bundler/stub_specification.rb @@ -30,7 +30,11 @@ def to_yaml # This is defined directly to avoid having to loading the full spec def missing_extensions? - stub.missing_extensions? + return false if default_gem? + return false if extensions.empty? + return false if File.exist? gem_build_complete_path + + true end def activated @@ -41,6 +45,14 @@ def activated=(activated) stub.instance_variable_set(:@activated, activated) end + def extensions + stub.extensions + end + + def gem_build_complete_path + File.join(extension_dir, "gem.build_complete") + end + def default_gem? stub.default_gem? end diff --git a/bundler/spec/commands/exec_spec.rb b/bundler/spec/commands/exec_spec.rb index bee832e4029c..f22963ed8e13 100644 --- a/bundler/spec/commands/exec_spec.rb +++ b/bundler/spec/commands/exec_spec.rb @@ -928,5 +928,24 @@ def bin_path(a,b,c) expect(err).to include("custom openssl should not be loaded") end end + + context "with a git gem that includes extensions" do + before do + build_git "simple_git_binary", &:add_c_extension + bundle! "config set --local path .bundle" + install_gemfile! <<-G + gem "simple_git_binary", :git => '#{lib_path("simple_git_binary-1.0")}' + G + end + + it "allows calling bundle install" do + bundle! "exec bundle install" + end + + it "allows calling bundle install after removing gem.build_complete" do + FileUtils.rm_rf Dir[bundled_app(".bundle/**/gem.build_complete")] + bundle! "exec #{Gem.ruby} -S bundle install" + end + end end end