class Gem::Commands::RebuildCommand

Public Class Methods

new ()
Calls superclass method Gem::Command::new
# File lib/rubygems/commands/rebuild_command.rb, line 13
def initialize
  super "rebuild", "Attempt to reproduce a build of a gem."

  add_option "--diff", "If the files don't match, compare them using diffoscope." do |_value, options|
    options[:diff] = true
  end

  add_option "--force", "Skip validation of the spec." do |_value, options|
    options[:force] = true
  end

  add_option "--strict", "Consider warnings as errors when validating the spec." do |_value, options|
    options[:strict] = true
  end

  add_option "--source GEM_SOURCE", "Specify the source to download the gem from." do |value, options|
    options[:source] = value
  end

  add_option "--original GEM_FILE", "Specify a local file to compare against (instead of downloading it)." do |value, options|
    options[:original_gem_file] = value
  end

  add_option "--gemspec GEMSPEC_FILE", "Specify the name of the gemspec file." do |value, options|
    options[:gemspec_file] = value
  end

  add_option "-C PATH", "Run as if gem build was started in <PATH> instead of the current working directory." do |value, options|
    options[:build_path] = value
  end
end

Public Instance Methods

execute ()
# File lib/rubygems/commands/rebuild_command.rb, line 72
  def execute
    gem_name, gem_version = get_gem_name_and_version

    old_dir, new_dir = prep_dirs

    gem_filename = "#{gem_name}-#{gem_version}.gem"
    old_file = File.join(old_dir, gem_filename)
    new_file = File.join(new_dir, gem_filename)

    if options[:original_gem_file]
      FileUtils.copy_file(options[:original_gem_file], old_file)
    else
      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]
      Dir.chdir(build_path) { build_gem(gem_name, source_date_epoch, new_file) }
    else
      build_gem(gem_name, source_date_epoch, new_file)
    end

    compare(source_date_epoch, old_file, new_file)
  end