From f89567aa222a12a625bf7f9f812b4f334975c638 Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Wed, 3 Feb 2016 20:22:31 -0800 Subject: use our own ivar to memoize this guarantees that even if rubygems somehow memoizes a value from the original method, we will use our own value instead. --- lib/bundler/rubygems_ext.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/bundler') diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 22c22a2d..2f36c29c 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -53,7 +53,7 @@ module Gem if method_defined?(:extension_dir) alias_method :rg_extension_dir, :extension_dir def extension_dir - @extension_dir ||= if source.respond_to?(:extension_dir_name) + @bundler_extension_dir ||= if source.respond_to?(:extension_dir_name) File.expand_path(File.join(extensions_dir, source.extension_dir_name)) else rg_extension_dir -- cgit v1.2.3 From c761d649688479e4f5bcb182c495ff360fd3e57e Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Wed, 3 Feb 2016 21:08:39 -0800 Subject: wait to validate so git gems always have sources --- lib/bundler/source/path.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/bundler') diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index 6bfd2e88..10f19f48 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -135,9 +135,12 @@ 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, :validate) + next unless spec = Bundler.load_gemspec(file) spec.loaded_from = file.to_s spec.source = self + # Validation causes extension_dir to be calculated, which depends + # on #source, so we validate here instead of load_gemspec + Bundler.rubygems.validate(spec) index << spec end -- cgit v1.2.3 From 8584d5969a42d9027ef4faecddd90f492bd3e7dc Mon Sep 17 00:00:00 2001 From: Andre Arko Date: Wed, 3 Feb 2016 21:57:49 -0800 Subject: don’t rebuild already-built git gem extensions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #4082 --- lib/bundler/source/git.rb | 4 ++++ lib/bundler/source/path.rb | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/bundler') diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 90bbd13d..51fcd44d 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -222,6 +222,10 @@ module Bundler private + def build_extensions(installer) + super if installer.spec.missing_extensions? + end + def serialize_gemspecs_in(destination) expanded_path = destination.expand_path(Bundler.root) Dir["#{expanded_path}/#{@glob}"].each do |spec_path| diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index 10f19f48..c5cf005c 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -197,8 +197,7 @@ module Bundler SharedHelpers.chdir(gem_dir) do installer = Path::Installer.new(spec, :env_shebang => false) run_hooks(:pre_install, installer) - installer.build_extensions unless disable_extensions - run_hooks(:post_build, installer) + build_extensions(installer) unless disable_extensions installer.generate_bin run_hooks(:post_install, installer) end @@ -216,6 +215,11 @@ module Bundler Bundler.ui.warn "The validation message from Rubygems was:\n #{e.message}" end + def build_extensions(installer) + installer.build_extensions + run_hooks(:post_build, installer) + end + def run_hooks(type, installer) hooks_meth = "#{type}_hooks" return unless Gem.respond_to?(hooks_meth) -- cgit v1.2.3 From cb6e8891c6320210861dfc106b4adb80368def1a Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Wed, 17 Feb 2016 21:42:27 -0600 Subject: Move validation exception messages to the rubygems integration helper --- lib/bundler.rb | 14 ++++++-------- lib/bundler/rubygems_integration.rb | 8 ++++++++ lib/bundler/source/path.rb | 1 - spec/bundler/bundler_spec.rb | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) (limited to 'lib/bundler') diff --git a/lib/bundler.rb b/lib/bundler.rb index 5cfff3d5..a90bc548 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -355,18 +355,16 @@ module Bundler # depend on "./" relative paths. SharedHelpers.chdir(path.dirname.to_s) do contents = path.read - if contents[0..2] == "---" # YAML header - spec = eval_yaml_gemspec(path, contents) + spec = if contents[0..2] == "---" # YAML header + eval_yaml_gemspec(path, contents) else - spec = eval_gemspec(path, contents) + eval_gemspec(path, contents) end - Bundler.rubygems.validate(spec) if spec && validate + return unless spec + spec.loaded_from = file + Bundler.rubygems.validate(spec) if validate spec end - rescue Gem::InvalidSpecificationException => e - error_message = "The gemspec at #{file} is not valid. Please fix this gemspec.\n" \ - "The validation error was '#{e.message}'\n" - raise Gem::InvalidSpecificationException.new(error_message) end def clear_gemspec_cache diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 0f567db1..609205e0 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -54,6 +54,10 @@ module Bundler def validate(spec) Bundler.ui.silence { spec.validate(false) } + rescue Gem::InvalidSpecificationException => e + error_message = "The gemspec at #{spec.loaded_from} is not valid. Please fix this gemspec.\n" \ + "The validation error was '#{e.message}'\n" + raise Gem::InvalidSpecificationException.new(error_message) rescue Errno::ENOENT nil end @@ -504,6 +508,10 @@ module Bundler # so we set it to an empty string to prevent an exception here. spec.summary ||= "" Bundler.ui.silence { spec.validate(false) } + rescue Gem::InvalidSpecificationException => e + error_message = "The gemspec at #{spec.loaded_from} is not valid. Please fix this gemspec.\n" \ + "The validation error was '#{e.message}'\n" + raise Gem::InvalidSpecificationException.new(error_message) rescue Errno::ENOENT nil end diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index c5cf005c..0bb5f1b8 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -136,7 +136,6 @@ module Bundler # 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) - spec.loaded_from = file.to_s spec.source = self # Validation causes extension_dir to be calculated, which depends # on #source, so we validate here instead of load_gemspec diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb index 9d4353f7..828a6825 100644 --- a/spec/bundler/bundler_spec.rb +++ b/spec/bundler/bundler_spec.rb @@ -83,7 +83,7 @@ describe Bundler do before do allow(Bundler::UI::Shell).to receive(:new).and_return(ui_shell) - allow(Bundler.rubygems).to receive(:validate) { + allow_any_instance_of(Gem::Specification).to receive(:validate) { raise Gem::InvalidSpecificationException.new("TODO is not an author") } end -- cgit v1.2.3 From 700aabb26dc04587c3d90d26b913bd70cb7c2f63 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Wed, 17 Feb 2016 22:20:47 -0600 Subject: [Path] Set spec installed_by_version so RubyGems will know it has an extensions dir --- lib/bundler/source/path.rb | 1 + spec/commands/clean_spec.rb | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/bundler') diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index 0bb5f1b8..0e00837b 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -137,6 +137,7 @@ module Bundler Dir["#{expanded_path}/#{@glob}"].sort_by {|p| -p.split(File::SEPARATOR).size }.each do |file| next unless spec = Bundler.load_gemspec(file) spec.source = self + spec.installed_by_version = Gem::Version.create(Gem::VERSION) # Validation causes extension_dir to be calculated, which depends # on #source, so we validate here instead of load_gemspec Bundler.rubygems.validate(spec) diff --git a/spec/commands/clean_spec.rb b/spec/commands/clean_spec.rb index 95035555..37f569b2 100644 --- a/spec/commands/clean_spec.rb +++ b/spec/commands/clean_spec.rb @@ -660,9 +660,11 @@ describe "bundle clean" do gem "very_simple_git_binary", :git => "#{lib_path("very_simple_git_binary-1.0")}", :ref => "#{revision}" G - bundle "install --path vendor/bundle" - bundle :clean + bundle! "install --path vendor/bundle" + expect(vendored_gems("bundler/gems/extensions")).to exist + expect(vendored_gems("bundler/gems/very_simple_git_binary-1.0-#{revision[0..11]}")).to exist + bundle! :clean expect(out).to eq("") expect(vendored_gems("bundler/gems/extensions")).to exist -- cgit v1.2.3 From 8bcb7d09f9c7dff79865be7af496be175d45f4a6 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Wed, 17 Feb 2016 22:36:20 -0600 Subject: [RubyGemsIntegration] Reduce code duplication for #validate --- lib/bundler/rubygems_integration.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'lib/bundler') diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 609205e0..b00f3dea 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -507,13 +507,7 @@ module Bundler # Missing summary is downgraded to a warning in later versions, # so we set it to an empty string to prevent an exception here. spec.summary ||= "" - Bundler.ui.silence { spec.validate(false) } - rescue Gem::InvalidSpecificationException => e - error_message = "The gemspec at #{spec.loaded_from} is not valid. Please fix this gemspec.\n" \ - "The validation error was '#{e.message}'\n" - raise Gem::InvalidSpecificationException.new(error_message) - rescue Errno::ENOENT - nil + RubygemsIntegration.instance_method(:validate).bind(self).call(spec) end end -- cgit v1.2.3 From 86453c17fbaed0e4fce9980c42139dcfee202f30 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Wed, 17 Feb 2016 23:55:59 -0600 Subject: Ensure rubygems functionality is done in rubygemsintegration --- lib/bundler/rubygems_integration.rb | 9 +++++++++ lib/bundler/source/git.rb | 2 +- lib/bundler/source/path.rb | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/bundler') diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index b00f3dea..4e5ca7d1 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -62,6 +62,15 @@ module Bundler nil end + def set_installed_by_version(spec, installed_by_version = Gem::VERSION) + return unless spec.respond_to?(:installed_by_version=) + spec.installed_by_version = Gem::Version.create(installed_by_version) + end + + def spec_missing_extensions?(spec) + !spec.respond_to?(:missing_extensions?) || spec.missing_extensions? + end + def path(obj) obj.to_s end diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 51fcd44d..228ab61a 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -223,7 +223,7 @@ module Bundler private def build_extensions(installer) - super if installer.spec.missing_extensions? + super if Bundler.rubygems.spec_missing_extensions?(installer.spec) end def serialize_gemspecs_in(destination) diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index 0e00837b..9790ba51 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -137,7 +137,7 @@ module Bundler Dir["#{expanded_path}/#{@glob}"].sort_by {|p| -p.split(File::SEPARATOR).size }.each do |file| next unless spec = Bundler.load_gemspec(file) spec.source = self - spec.installed_by_version = Gem::Version.create(Gem::VERSION) + 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 Bundler.rubygems.validate(spec) -- cgit v1.2.3