aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/installer.rb
diff options
context:
space:
mode:
authorryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-19 21:23:04 +0000
committerryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-01-19 21:23:04 +0000
commit64847a9cfe467b808ca5e8148dfa85a059198963 (patch)
treeb21ca4404f92f1fe269347a8d624cf188e7fbc97 /lib/rubygems/installer.rb
parentdf2762fb1aaa82577b4e3e8df67cc56b7aefdfb8 (diff)
downloadruby-64847a9cfe467b808ca5e8148dfa85a059198963.tar.gz
Importing rubygems @ c2d4131: Deal with platforms that have DLEXT2 == nil. Fixes RF#28867
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/installer.rb')
-rw-r--r--lib/rubygems/installer.rb179
1 files changed, 112 insertions, 67 deletions
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index 3665aa3e0b..7321d2e2e5 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -24,7 +24,7 @@ require 'rubygems/require_paths_builder'
# gemspec in the specifications dir, storing the cached gem in the cache dir,
# and installing either wrappers or symlinks for executables.
#
-# The installer fires pre and post install hooks. Hooks can be added either
+# The installer invokes pre and post install hooks. Hooks can be added either
# through a rubygems_plugin.rb file in an installed gem or via a
# rubygems/defaults/#{RUBY_ENGINE}.rb or rubygems/defaults/operating_system.rb
# file. See Gem.pre_install and Gem.post_install for details.
@@ -61,6 +61,11 @@ class Gem::Installer
attr_reader :spec
+ ##
+ # The options passed when the Gem::Installer was instantiated.
+
+ attr_reader :options
+
@path_warning = false
class << self
@@ -98,49 +103,16 @@ class Gem::Installer
require 'fileutils'
@gem = gem
-
- options = {
- :bin_dir => nil,
- :env_shebang => false,
- :exec_format => false,
- :force => false,
- :install_dir => Gem.dir,
- :source_index => Gem.source_index,
- }.merge options
-
- @env_shebang = options[:env_shebang]
- @force = options[:force]
- gem_home = options[:install_dir]
- @gem_home = File.expand_path(gem_home)
- @ignore_dependencies = options[:ignore_dependencies]
- @format_executable = options[:format_executable]
- @security_policy = options[:security_policy]
- @wrappers = options[:wrappers]
- @bin_dir = options[:bin_dir]
- @development = options[:development]
- @source_index = options[:source_index]
-
- begin
- @format = Gem::Format.from_file_by_path @gem, @security_policy
- rescue Gem::Package::FormatError
- raise Gem::InstallError, "invalid gem format for #{@gem}"
- end
+ @options = options
+ process_options
+ load_gem_file
if options[:user_install] and not options[:unpack] then
@gem_home = Gem.user_dir
-
- user_bin_dir = File.join(@gem_home, 'bin')
- unless ENV['PATH'].split(File::PATH_SEPARATOR).include? user_bin_dir then
- unless self.class.path_warning then
- alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables will not run."
- self.class.path_warning = true
- end
- end
+ check_that_user_bin_dir_is_in_path
end
- FileUtils.mkdir_p @gem_home
- raise Gem::FilePermissionError, @gem_home unless
- options[:unpack] or File.writable? @gem_home
+ verify_gem_home(options[:unpack])
@spec = @format.spec
@@ -160,48 +132,48 @@ class Gem::Installer
def install
# If we're forcing the install then disable security unless the security
- # policy says that we only install singed gems.
+ # policy says that we only install signed gems.
@security_policy = nil if @force and @security_policy and
not @security_policy.only_signed
- unless @force then
- if rrv = @spec.required_ruby_version then
- unless rrv.satisfied_by? Gem.ruby_version then
- raise Gem::InstallError, "#{@spec.name} requires Ruby version #{rrv}."
- end
- end
+ unless @force
+ ensure_required_ruby_version_met
+ ensure_required_rubygems_version_met
+ ensure_dependencies_met unless @ignore_dependencies
+ end
- if rrgv = @spec.required_rubygems_version then
- unless rrgv.satisfied_by? Gem::Version.new(Gem::VERSION) then
- raise Gem::InstallError,
- "#{@spec.name} requires RubyGems version #{rrgv}. " +
- "Try 'gem update --system' to update RubyGems itself."
- end
- end
+ Gem.pre_install_hooks.each do |hook|
+ result = hook.call self
- unless @ignore_dependencies then
- deps = @spec.runtime_dependencies
- deps |= @spec.development_dependencies if @development
+ if result == false then
+ location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/
- deps.each do |dep_gem|
- ensure_dependency @spec, dep_gem
- end
+ message = "pre-install hook#{location} failed for #{@spec.full_name}"
+ raise Gem::InstallError, message
end
end
- Gem.pre_install_hooks.each do |hook|
- hook.call self
- end
-
- FileUtils.mkdir_p @gem_home unless File.directory? @gem_home
-
Gem.ensure_gem_subdirectories @gem_home
FileUtils.mkdir_p @gem_dir
extract_files
- generate_bin
build_extensions
+
+ Gem.post_build_hooks.each do |hook|
+ result = hook.call self
+
+ if result == false then
+ FileUtils.rm_rf @gem_dir
+
+ location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/
+
+ message = "post-build hook#{location} failed for #{@spec.full_name}"
+ raise Gem::InstallError, message
+ end
+ end
+
+ generate_bin
write_spec
write_require_paths_file_if_needed if QUICKLOADER_SUCKAGE
@@ -238,7 +210,6 @@ class Gem::Installer
unless installation_satisfies_dependency? dependency then
raise Gem::InstallError, "#{spec.name} requires #{dependency}"
end
-
true
end
@@ -388,6 +359,80 @@ class Gem::Installer
end
end
+ def ensure_required_ruby_version_met
+ if rrv = @spec.required_ruby_version then
+ unless rrv.satisfied_by? Gem.ruby_version then
+ raise Gem::InstallError, "#{@spec.name} requires Ruby version #{rrv}."
+ end
+ end
+ end
+
+ def ensure_required_rubygems_version_met
+ if rrgv = @spec.required_rubygems_version then
+ unless rrgv.satisfied_by? Gem::Version.new(Gem::VERSION) then
+ raise Gem::InstallError,
+ "#{@spec.name} requires RubyGems version #{rrgv}. " +
+ "Try 'gem update --system' to update RubyGems itself."
+ end
+ end
+ end
+
+ def ensure_dependencies_met
+ deps = @spec.runtime_dependencies
+ deps |= @spec.development_dependencies if @development
+
+ deps.each do |dep_gem|
+ ensure_dependency @spec, dep_gem
+ end
+ end
+
+ def process_options
+ @options = {
+ :bin_dir => nil,
+ :env_shebang => false,
+ :exec_format => false,
+ :force => false,
+ :install_dir => Gem.dir,
+ :source_index => Gem.source_index,
+ }.merge @options
+
+ @env_shebang = @options[:env_shebang]
+ @force = @options[:force]
+ gem_home = @options[:install_dir]
+ @gem_home = File.expand_path(gem_home)
+ @ignore_dependencies = @options[:ignore_dependencies]
+ @format_executable = @options[:format_executable]
+ @security_policy = @options[:security_policy]
+ @wrappers = @options[:wrappers]
+ @bin_dir = @options[:bin_dir]
+ @development = @options[:development]
+ @source_index = @options[:source_index]
+ end
+
+ def load_gem_file
+ begin
+ @format = Gem::Format.from_file_by_path @gem, @security_policy
+ rescue Gem::Package::FormatError
+ raise Gem::InstallError, "invalid gem format for #{@gem}"
+ end
+ end
+
+ def check_that_user_bin_dir_is_in_path
+ user_bin_dir = File.join(@gem_home, 'bin')
+ unless ENV['PATH'].split(File::PATH_SEPARATOR).include? user_bin_dir then
+ unless self.class.path_warning then
+ alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables will not run."
+ self.class.path_warning = true
+ end
+ end
+ end
+
+ def verify_gem_home(unpack = false)
+ FileUtils.mkdir_p @gem_home
+ raise Gem::FilePermissionError, @gem_home unless
+ unpack or File.writable? @gem_home
+ end
+
##
# Return the text for an application file.