2011-01-19 00:08:49 +00:00
|
|
|
######################################################################
|
|
|
|
# This file is imported from the rubygems project.
|
|
|
|
# DO NOT make modifications in this repo. They _will_ be reverted!
|
|
|
|
# File a patch instead and assign it to Ryan Davis or Eric Hodel.
|
|
|
|
######################################################################
|
|
|
|
|
2007-11-10 07:48:56 +00:00
|
|
|
require 'rubygems/command'
|
|
|
|
require 'rubygems/builder'
|
|
|
|
|
|
|
|
class Gem::Commands::BuildCommand < Gem::Command
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super('build', 'Build a gem from a gemspec')
|
|
|
|
end
|
|
|
|
|
|
|
|
def arguments # :nodoc:
|
|
|
|
"GEMSPEC_FILE gemspec file name to build a gem for"
|
|
|
|
end
|
|
|
|
|
|
|
|
def usage # :nodoc:
|
|
|
|
"#{program_name} GEMSPEC_FILE"
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
gemspec = get_one_gem_name
|
2011-06-01 03:45:05 +00:00
|
|
|
|
|
|
|
if File.exist? gemspec
|
|
|
|
spec = load_gemspec gemspec
|
|
|
|
|
|
|
|
if spec then
|
2007-11-10 07:48:56 +00:00
|
|
|
Gem::Builder.new(spec).build
|
2011-06-01 03:45:05 +00:00
|
|
|
else
|
|
|
|
alert_error "Error loading gemspec. Aborting."
|
|
|
|
terminate_interaction 1
|
2007-11-10 07:48:56 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
alert_error "Gemspec file not found: #{gemspec}"
|
2011-06-01 03:45:05 +00:00
|
|
|
terminate_interaction 1
|
2007-11-10 07:48:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-01 03:45:05 +00:00
|
|
|
def load_gemspec filename
|
2007-11-10 07:48:56 +00:00
|
|
|
if yaml?(filename)
|
|
|
|
open(filename) do |f|
|
|
|
|
begin
|
2011-06-01 03:45:05 +00:00
|
|
|
Gem::Specification.from_yaml(f)
|
2010-11-08 20:58:42 +00:00
|
|
|
rescue Gem::EndOfYAMLException
|
2011-06-01 03:45:05 +00:00
|
|
|
nil
|
2007-11-10 07:48:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2011-06-01 03:45:05 +00:00
|
|
|
Gem::Specification.load(filename) # can return nil
|
2007-11-10 07:48:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def yaml?(filename)
|
|
|
|
line = open(filename) { |f| line = f.gets }
|
2007-12-21 08:45:07 +00:00
|
|
|
result = line =~ %r{!ruby/object:Gem::Specification}
|
2007-11-10 07:48:56 +00:00
|
|
|
result
|
|
|
|
end
|
|
|
|
end
|