2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/command'
|
|
|
|
require 'rubygems/install_update_options'
|
|
|
|
require 'rubygems/dependency_installer'
|
|
|
|
require 'rubygems/local_remote_options'
|
|
|
|
require 'rubygems/validator'
|
|
|
|
require 'rubygems/version_option'
|
2012-11-29 01:52:18 -05:00
|
|
|
require 'rubygems/install_message' # must come before rdoc for messaging
|
|
|
|
require 'rubygems/rdoc'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Gem installer command line tool
|
|
|
|
#
|
|
|
|
# See `gem help install`
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
class Gem::Commands::InstallCommand < Gem::Command
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
attr_reader :installed_specs # :nodoc:
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
include Gem::VersionOption
|
|
|
|
include Gem::LocalRemoteOptions
|
|
|
|
include Gem::InstallUpdateOptions
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
defaults = Gem::DependencyInstaller::DEFAULT_OPTIONS.merge({
|
2007-12-20 03:39:12 -05:00
|
|
|
:format_executable => false,
|
2009-06-09 17:38:59 -04:00
|
|
|
:version => Gem::Requirement.default,
|
2007-11-10 02:48:56 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
super 'install', 'Install a gem into the local repository', defaults
|
|
|
|
|
|
|
|
add_install_update_options
|
|
|
|
add_local_remote_options
|
|
|
|
add_platform_option
|
|
|
|
add_version_option
|
2010-02-21 21:52:35 -05:00
|
|
|
add_prerelease_option "to be installed. (Only for listed gems)"
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
add_option(:"Install/Update", '-g', '--file FILE',
|
|
|
|
'Read from a gem dependencies API file and',
|
|
|
|
'install the listed gems') do |v,o|
|
|
|
|
o[:gemdeps] = v
|
|
|
|
end
|
|
|
|
|
|
|
|
@installed_specs = nil
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def arguments # :nodoc:
|
|
|
|
"GEMNAME name of gem to install"
|
|
|
|
end
|
|
|
|
|
|
|
|
def defaults_str # :nodoc:
|
2012-12-06 00:26:46 -05:00
|
|
|
"--both --version '#{Gem::Requirement.default}' --document --no-force\n" +
|
2011-01-18 19:08:49 -05:00
|
|
|
"--install-dir #{Gem.dir}"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
def description # :nodoc:
|
|
|
|
<<-EOF
|
|
|
|
The install command installs local or remote gem into a gem repository.
|
|
|
|
|
|
|
|
For gems with executables ruby installs a wrapper file into the executable
|
2009-06-09 17:38:59 -04:00
|
|
|
directory by default. This can be overridden with the --no-wrappers option.
|
2008-09-25 06:13:50 -04:00
|
|
|
The wrapper allows you to choose among alternate gem versions using _version_.
|
|
|
|
|
|
|
|
For example `rake _0.7.3_ --version` will run rake version 0.7.3 if a newer
|
|
|
|
version is also installed.
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
If an extension fails to compile during gem installation the gem
|
|
|
|
specification is not written out, but the gem remains unpacked in the
|
|
|
|
repository. You may need to specify the path to the library's headers and
|
|
|
|
libraries to continue. You can do this by adding a -- between RubyGems'
|
|
|
|
options and the extension's build options:
|
|
|
|
|
|
|
|
$ gem install some_extension_gem
|
|
|
|
[build fails]
|
|
|
|
Gem files will remain installed in \\
|
|
|
|
/path/to/gems/some_extension_gem-1.0 for inspection.
|
|
|
|
Results logged to /path/to/gems/some_extension_gem-1.0/gem_make.out
|
|
|
|
$ gem install some_extension_gem -- --with-extension-lib=/path/to/lib
|
|
|
|
[build succeeds]
|
|
|
|
$ gem list some_extension_gem
|
|
|
|
|
|
|
|
*** LOCAL GEMS ***
|
|
|
|
|
|
|
|
some_extension_gem (1.0)
|
|
|
|
$
|
|
|
|
|
|
|
|
If you correct the compilation errors by editing the gem files you will need
|
|
|
|
to write the specification by hand. For example:
|
|
|
|
|
|
|
|
$ gem install some_extension_gem
|
|
|
|
[build fails]
|
|
|
|
Gem files will remain installed in \\
|
|
|
|
/path/to/gems/some_extension_gem-1.0 for inspection.
|
|
|
|
Results logged to /path/to/gems/some_extension_gem-1.0/gem_make.out
|
|
|
|
$ [cd /path/to/gems/some_extension_gem-1.0]
|
|
|
|
$ [edit files or what-have-you and run make]
|
|
|
|
$ gem spec ../../cache/some_extension_gem-1.0.gem --ruby > \\
|
|
|
|
../../specifications/some_extension_gem-1.0.gemspec
|
|
|
|
$ gem list some_extension_gem
|
|
|
|
|
|
|
|
*** LOCAL GEMS ***
|
|
|
|
|
|
|
|
some_extension_gem (1.0)
|
|
|
|
$
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
EOF
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def usage # :nodoc:
|
|
|
|
"#{program_name} GEMNAME [GEMNAME ...] [options] -- --build-flags"
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def install_from_gemdeps(gf)
|
|
|
|
require 'rubygems/request_set'
|
|
|
|
rs = Gem::RequestSet.new
|
|
|
|
rs.load_gemdeps gf
|
|
|
|
|
|
|
|
rs.resolve
|
|
|
|
|
|
|
|
specs = rs.install options do |req, inst|
|
|
|
|
s = req.full_spec
|
|
|
|
|
|
|
|
if inst
|
|
|
|
say "Installing #{s.name} (#{s.version})"
|
|
|
|
else
|
|
|
|
say "Using #{s.name} (#{s.version})"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@installed_specs = specs
|
|
|
|
|
|
|
|
raise Gem::SystemExitException, 0
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def execute
|
2012-11-29 01:52:18 -05:00
|
|
|
if gf = options[:gemdeps] then
|
|
|
|
install_from_gemdeps gf
|
|
|
|
return
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
@installed_specs = []
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-06-25 22:06:00 -04:00
|
|
|
ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
if options[:install_dir] and options[:user_install]
|
|
|
|
alert_error "Use --install-dir or --user-install but not both"
|
|
|
|
terminate_interaction 1
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
exit_code = 0
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
if options[:version] != Gem::Requirement.default &&
|
|
|
|
get_all_gem_names.size > 1 then
|
|
|
|
alert_error "Can't use --version w/ multiple gems. Use name:ver instead."
|
|
|
|
terminate_interaction 1
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
get_all_gem_names_and_versions.each do |gem_name, gem_version|
|
|
|
|
gem_version ||= options[:version]
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
begin
|
2011-05-31 23:45:05 -04:00
|
|
|
next if options[:conservative] and
|
2012-11-29 01:52:18 -05:00
|
|
|
not Gem::Dependency.new(gem_name, gem_version).matching_specs.empty?
|
2011-01-18 19:08:49 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
inst = Gem::DependencyInstaller.new options
|
2012-11-29 01:52:18 -05:00
|
|
|
inst.install gem_name, Gem::Requirement.create(gem_version)
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
@installed_specs.push(*inst.installed_gems)
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
next unless errs = inst.errors
|
|
|
|
|
|
|
|
errs.each do |x|
|
|
|
|
next unless Gem::SourceFetchProblem === x
|
|
|
|
|
|
|
|
msg = "Unable to pull data from '#{x.source.uri}': #{x.error.message}"
|
|
|
|
|
|
|
|
alert_warning msg
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
rescue Gem::InstallError => e
|
|
|
|
alert_error "Error installing #{gem_name}:\n\t#{e.message}"
|
2008-03-31 18:40:06 -04:00
|
|
|
exit_code |= 1
|
2007-11-10 02:48:56 -05:00
|
|
|
rescue Gem::GemNotFoundException => e
|
2011-01-18 19:08:49 -05:00
|
|
|
show_lookup_failure e.name, e.version, e.errors, options[:domain]
|
2010-04-22 04:24:42 -04:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
exit_code |= 2
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
unless @installed_specs.empty? then
|
|
|
|
gems = @installed_specs.length == 1 ? 'gem' : 'gems'
|
|
|
|
say "#{@installed_specs.length} #{gems} installed"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
raise Gem::SystemExitException, exit_code
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|