From 1b333a6768ce8708c7d01bffc27a46952e5b6011 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Thu, 6 Apr 2017 19:25:25 -0500 Subject: [Git] Avoid loading full gemspecs in -rbundler/setup when stubs are available --- lib/bundler/source/git.rb | 8 ++++++++ lib/bundler/source/path.rb | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'lib/bundler/source') diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index c95c94583f..d92b741202 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -234,6 +234,7 @@ module Bundler # The gemspecs we cache should already be evaluated. spec = Bundler.load_gemspec(spec_path) next unless spec + Bundler.rubygems.set_installed_by_version(spec) Bundler.rubygems.validate(spec) File.open(spec_path, "wb") {|file| file.write(spec.to_ruby) } end @@ -302,6 +303,13 @@ module Bundler # no-op, since we validate when re-serializing the gemspec def validate_spec(_spec); end + + if defined?(::Gem::StubSpecification) + def load_gemspec(file) + stub = Gem::StubSpecification.gemspec_stub(file, install_path.parent, install_path.parent) + StubSpecification.from_stub(stub) + end + end end end end diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index 4b01496aac..0ad0a029f0 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -144,6 +144,12 @@ module Bundler SharedHelpers.in_bundle? && app_cache_path.exist? end + def load_gemspec(file) + return unless spec = Bundler.load_gemspec(file) + Bundler.rubygems.set_installed_by_version(spec) + spec + end + def validate_spec(spec) Bundler.rubygems.validate(spec) end @@ -154,9 +160,9 @@ module Bundler if File.directory?(expanded_path) # We sort depth-first since `<<` will override the earlier-found specs Dir["#{expanded_path}/#{@glob}"].sort_by {|p| -p.split(File::SEPARATOR).size }.each do |file| - next unless spec = Bundler.load_gemspec(file) + next unless spec = load_gemspec(file) spec.source = self - Bundler.rubygems.set_installed_by_version(spec) + # Validation causes extension_dir to be calculated, which depends # on #source, so we validate here instead of load_gemspec validate_spec(spec) -- cgit v1.2.1