From dfe83df03e1a9a056070ef37999f150bcf5a6fc0 Mon Sep 17 00:00:00 2001 From: Ellen Marie Dash Date: Wed, 31 Jan 2024 13:07:07 -0500 Subject: [PATCH] [rubygems/rubygems] [rebuild_command] Bail early if the RubyGems version doesn't match. https://github.com/rubygems/rubygems/commit/a691170dc7 --- lib/rubygems/commands/rebuild_command.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/rubygems/commands/rebuild_command.rb b/lib/rubygems/commands/rebuild_command.rb index 4a4f76678d..5386354f10 100644 --- a/lib/rubygems/commands/rebuild_command.rb +++ b/lib/rubygems/commands/rebuild_command.rb @@ -83,6 +83,22 @@ matched versions of Ruby and/or Bundler to be used. download_gem(gem_name, gem_version, old_file) end + rg_version = rubygems_version(old_file) + unless rg_version == Gem::VERSION + alert_error <<-EOF +You need to use the same RubyGems version #{gem_name} v#{gem_version} was built with. + +#{gem_name} v#{gem_version} was built using RubyGems v#{rg_version}. +Gem files include the version of RubyGems used to build them. +This means in order to reproduce #{gem_filename}, you must also use RubyGems v#{rg_version}. + +You're using RubyGems v#{Gem::VERSION}. + +Please install RubyGems v#{rg_version} and try again. + EOF + terminate_interaction 1 + end + source_date_epoch = get_timestamp(old_file).to_s if build_path = options[:build_path] @@ -247,4 +263,8 @@ matched versions of Ruby and/or Bundler to be used. say "Downloaded #{gem_name} version #{gem_version} as #{old_file}." end + + def rubygems_version(gem_file) + Gem::Package.new(gem_file).spec.rubygems_version + end end