2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/command'
|
2012-11-29 01:52:18 -05:00
|
|
|
require 'rubygems/package'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
class Gem::Commands::BuildCommand < Gem::Command
|
|
|
|
|
|
|
|
def initialize
|
2012-04-17 20:04:12 -04:00
|
|
|
super 'build', 'Build a gem from a gemspec'
|
|
|
|
|
|
|
|
add_option '--force', 'skip validation of the spec' do |value, options|
|
|
|
|
options[:force] = true
|
|
|
|
end
|
2018-08-27 06:05:04 -04:00
|
|
|
|
|
|
|
add_option '--strict', 'consider warnings as errors when validating the spec' do |value, options|
|
|
|
|
options[:strict] = true
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def arguments # :nodoc:
|
|
|
|
"GEMSPEC_FILE gemspec file name to build a gem for"
|
|
|
|
end
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
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
|
|
|
|
EOF
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def usage # :nodoc:
|
|
|
|
"#{program_name} GEMSPEC_FILE"
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
gemspec = get_one_gem_name
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
unless File.exist? gemspec
|
|
|
|
gemspec += '.gemspec' if File.exist? gemspec + '.gemspec'
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
if File.exist? gemspec then
|
2018-05-30 09:01:35 -04:00
|
|
|
Dir.chdir(File.dirname(gemspec)) do
|
|
|
|
spec = Gem::Specification.load File.basename(gemspec)
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
if spec then
|
2018-08-27 06:05:04 -04:00
|
|
|
Gem::Package.build spec, options[:force], options[:strict]
|
2018-05-30 09:01:35 -04:00
|
|
|
else
|
|
|
|
alert_error "Error loading gemspec. Aborting."
|
|
|
|
terminate_interaction 1
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
else
|
|
|
|
alert_error "Gemspec file not found: #{gemspec}"
|
2011-05-31 23:45:05 -04:00
|
|
|
terminate_interaction 1
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|