1
  /   ˆ{‹„„-i[D<†ªoZƒ›Ù«Â568_‘I|¥‰ÓMdœv ©ƒ†ü+=ÂÁ 8    ‹      Õ–ßoÚ0ÇßûWx~Ø„nRÛ�©#HCkQ¦iš&dbC,;²/Pö×Ï!™H;Ð6í‡”'ß]¾öÝçì$ö_„“ÁüÓtHÞÍïïÈôÃÛ»Ñ€ÐÀÇÞ  œ‡åƒËv§0SBcÄì`·Ûµw½¶6k˜Ï Æ4¹‹FFØæÈipá±à‚ø±`Ü�ÄG‰‰FŠ‹G¢WtŽVráæí-p±•‘°…�"…T¤Úì«áÊ¥¹èTn·ëA¦wÂøP.é’@•Å_j¾/’wÿn"·Þ�-ù
Ó>ÆdË¹V}Š:£�/Ó5±&êS�‘V–	S›öZ®(a	öéçÑ`òÅé ãbvà3±êÓ7ƒþøfÒi0f©ð��ÖÜ;Í-î˜E’j.WRð³â‡Rü ¿ž_0,5¡°‘‘J­ŽRpˆuÔH'6cŽõ•#ˆM]UJøÏºÁ¢'Í˜ÞÎ†ãy8š•-áÅÇêþhÛh0eF($¡4"B­¸Ê$/ÕÒf7ß]RUmä:FÒ"'•¿�š«�Ò;U§u�<ÉÉì^E48õ"ŸUåu¼×­n·å]‘NïÚó9#tïêûÿY~ŽÚæ6Š/¸HØ~‘ZGs"Ú@8§G£TFL®P¦bÁ"”[±ØHî¶çD°ùh…ýZa7M¨â�Ã�XU ÁHæµ3XúM*¿s‚?;�OãÌ-[×¸î¿ÇùÅ›Tw2W?Ê{ç7Œ~Ú
       ˆÀ¿Ã573¾ÂÁ =    ‹      Õ–moÚ0Çß÷Sx~±wp<tÓÚ&™:‚44
ˆ2MÓ4!b‘Ø‘}�±O?‡d"í@ë´�W¾»üí»ßÙIì=Ç½ÙÇIŸ¼�ÝÉäý›á GhàC·ÎÂòÁe³Õè�(¡1bv°Ýn›ÛnS›Ì¦cš\‚E##lrä4¸ðŠXpA¼X0îFâ¡ÄDÅÅ¢—tŽVráæí,p±‘‘°…�"…T¤Úìª¡û
”æ¢U¹W]ÈôVÊ]¨’xÍwEîöÍã–Û°Å>]ašÀÃ˜lX"WÊ§¨3x2]k"Ÿ‚Œ´²°H˜Z7WrI	KÐ§Ÿ½ñg§Œ‹Ù�ÇHlÄÒ§¯{þèfì‡4±TxÀŽkîœæ–Cf‘¤šË¥ü¤ø¾ßË¯§KM(ldd†R«ƒb5Ò‰Í˜c}ábSW•þ³n°èA3&·Óþh¦eKx±Ä¡ºßÙ5L˜
I(�ˆÐ+¬2Çsµ°ÙÍw—TE¹Š‘„4ÈQå/�æj­ôVÕa]#�b2»SöC½ÈGUuZ�—�v»Ñ¹"­îu»MÈ	¡{QßýËòsÔ6·™P|ÎEÂvóÔ:š#Ñ'Ãu:ÿœÓ£Ñ	*ãL®P¦bÎ"”1_Kî¶çHðüÑ
û´Â>c4¡Š?`U�3F²È0¯�ÁÒ?g ò;'ø£ø0~Æ€¹e«×Þýû8O¼x@u%ó`ñó ¼t~_ì ¦×
    D   ˆl–Ãa¾”ÊC]Šm@ãm\ªbÑ¿�þcŒK8Ë d‘ˆ®H@?ÅƒïµÄ_�uÐb&=LyZËcõÄÃ ²    # frozen_string_literal: true
require_relative '../command'
require_relative '../package'
require_relative '../version_option'

class Gem::Commands::BuildCommand < Gem::Command
  include Gem::VersionOption

  def initialize
    super 'build', 'Build a gem from a gemspec'

    add_platform_option

    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 '-o', '--output FILE', 'output gem with the given filename' do |value, options|
      options[:output] = 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

  def arguments # :nodoc:
    "GEMSPEC_FILE  gemspec file name to build a gem for"
  end

  def description # :nodoc:
    <<-EOF
The build command allows you to create a gem from a ruby gemspec.

The best way to build a gem is to use a Rakefile and the Gem::PackageTask
which ships with RubyGems.

The gemspec can either be created by hand or extracted from an existing gem
with gem spec:

  $ gem unpack my_gem-1.0.gem
  Unpacked gem: '.../my_gem-1.0'
  $ gem spec my_gem-1.0.gem --ruby > my_gem-1.0/my_gem-1.0.gemspec
  $ cd my_gem-1.0
  [edit gem contents]
  $ gem build my_gem-1.0.gemspec

Gems can be saved to a specified filename with the output option:

  $ gem build my_gem-1.0.gemspec --output=release.gem

    EOF
  end

  def usage # :nodoc:
    "#{program_name} GEMSPEC_FILE"
  end

  def execute
    if build_path = options[:build_path]
      Dir.chdir(build_path) { build_gem }
      return
    end

    build_gem
  end

  private

  def find_gemspec(glob = "*.gemspec")
    gemspecs = Dir.glob(glob).sort

    if gemspecs.size > 1
      alert_error "Multiple gemspecs found: #{gemspecs}, please specify one"
      terminate_interaction(1)
    end

    gemspecs.first
  end

  def build_gem
    gemspec = resolve_gem_name

    if gemspec
      build_package(gemspec)
    else
      alert_error error_message
      terminate_interaction(1)
    end
  end

  def build_package(gemspec)
    spec = Gem::Specification.load(gemspec)
    if spec
      Gem::Package.build(
        spec,
        options[:force],
        options[:strict],
        options[:output]
      )
    else
      alert_error "Error loading gemspec. Aborting."
      terminate_interaction 1
    end
  end

  def resolve_gem_name
    return find_gemspec unless gem_name

    if File.exist?(gem_name)
      gem_name
    else
      find_gemspec("#{gem_name}.gemspec") || find_gemspec(gem_name)
    end
  end

  def error_messa