diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2017-04-07 12:02:47 -0500 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2017-04-07 12:03:15 -0500 |
commit | 7c1549eaa091211cca355a0452a348e8b2052582 (patch) | |
tree | 3cb16e9c89466d71f54d7e05ac4e0485c0463912 | |
parent | 7cb108d62bad5448a7e7b3b9c12717747ad41ca5 (diff) | |
download | bundler-7c1549eaa091211cca355a0452a348e8b2052582.tar.gz |
[StubSpecification] Move availability logic to RubygemsIntegration
-rw-r--r-- | lib/bundler/rubygems_integration.rb | 20 | ||||
-rw-r--r-- | lib/bundler/source/git.rb | 5 | ||||
-rw-r--r-- | lib/bundler/stub_specification.rb | 8 | ||||
-rw-r--r-- | spec/runtime/require_spec.rb | 4 |
4 files changed, 27 insertions, 10 deletions
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 5b753618cb..66497add02 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -80,6 +80,10 @@ module Bundler default end + def stub_set_spec(stub, spec) + stub.instance_variable_set(:@spec, spec) + end + def path(obj) obj.to_s end @@ -324,14 +328,19 @@ module Bundler true end + def stubs_provide_full_functionality? + false + end + def replace_gem(specs, specs_by_name) reverse_rubygems_kernel_mixin - executables = specs.map(&:executables).flatten if binstubs_call_gem? + executables = nil kernel = (class << ::Kernel; self; end) [kernel, ::Kernel].each do |kernel_class| redefine_method(kernel_class, :gem) do |dep, *reqs| + executables ||= specs.map(&:executables).flatten if ::Bundler.rubygems.binstubs_call_gem? if executables && executables.include?(File.basename(caller.first.split(":").first)) break end @@ -804,9 +813,18 @@ module Bundler end if provides?(">= 2.5.2") + # RubyGems-generated binstubs call Kernel#gem def binstubs_call_gem? false end + + # only 2.5.2+ has all of the stub methods we want to use, and since this + # is a performance optimization _only_, + # we'll restrict ourselves to the most + # recent RG versions instead of all versions that have stubs + def stubs_provide_full_functionality? + true + end end end end diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 1ddb30e715..f6efd588f9 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -304,10 +304,7 @@ module Bundler # no-op, since we validate when re-serializing the gemspec def validate_spec(_spec); end - # only 2.5.1+ has this method for stub creation, and since this is a - # performance optimization _only_, we'll restrict ourselves to the most - # recent RG versions instead of all versions that have stubs - if Bundler.rubygems.provides?(">= 2.5.1") + if Bundler.rubygems.stubs_provide_full_functionality? def load_gemspec(file) stub = Gem::StubSpecification.gemspec_stub(file, install_path.parent, install_path.parent) stub.full_gem_path = Pathname.new(file).dirname.expand_path(root).to_s.untaint diff --git a/lib/bundler/stub_specification.rb b/lib/bundler/stub_specification.rb index a9c79a03f5..6f94de7b10 100644 --- a/lib/bundler/stub_specification.rb +++ b/lib/bundler/stub_specification.rb @@ -48,8 +48,10 @@ module Bundler stub.loaded_from end - def matches_for_glob(glob) - stub.matches_for_glob(glob) + if Bundler.rubygems.stubs_provide_full_functionality? + def matches_for_glob(glob) + stub.matches_for_glob(glob) + end end def raw_require_paths @@ -69,7 +71,7 @@ module Bundler rs = stub.to_spec if rs.equal?(self) # happens when to_spec gets the spec from Gem.loaded_specs rs = Gem::Specification.load(loaded_from) - stub.instance_variable_set(:@spec, rs) + Bundler.rubygems.stub_set_spec(stub, rs) end unless rs diff --git a/spec/runtime/require_spec.rb b/spec/runtime/require_spec.rb index 59d65bab24..b68313726b 100644 --- a/spec/runtime/require_spec.rb +++ b/spec/runtime/require_spec.rb @@ -361,7 +361,7 @@ RSpec.describe "Bundler.require" do end end - it "does not load rubygems gemspecs that are used", :rubygems => ">= 2.3" do + it "does not load rubygems gemspecs that are used", :rubygems => ">= 2.5.2" do install_gemfile! <<-G source "file://#{gem_repo1}" gem "rack" @@ -384,7 +384,7 @@ RSpec.describe "Bundler.require" do expect(out).to eq("WIN") end - it "does not load git gemspecs that are used", :rubygems => ">= 2.5.1" do + it "does not load git gemspecs that are used", :rubygems => ">= 2.5.2" do build_git "foo" install_gemfile! <<-G |