From 31c94ffeb5f09d09ac2c86fc9e6614e38251a43d Mon Sep 17 00:00:00 2001 From: drbrain Date: Tue, 9 Jun 2009 21:38:59 +0000 Subject: Update to RubyGems 1.3.4 r2223 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/installer.rb | 58 ++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 23 deletions(-) (limited to 'lib/rubygems/installer.rb') diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 44bf2f8903..e9910876f3 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -13,16 +13,27 @@ require 'rubygems/ext' require 'rubygems/require_paths_builder' ## -# The installer class processes RubyGem .gem files and installs the -# files contained in the .gem into the Gem.path. +# The installer class processes RubyGem .gem files and installs the files +# contained in the .gem into the Gem.path. # # Gem::Installer does the work of putting files in all the right places on the # filesystem including unpacking the gem into its gem dir, installing the # 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 +# 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. class Gem::Installer + ## + # Paths where env(1) might live. Some systems are broken and have it in + # /bin + + ENV_PATHS = %w[/usr/bin/env /bin/env] + ## # Raised when there is an error while building extensions. # @@ -71,8 +82,6 @@ class Gem::Installer end - ENV_PATHS = %w[/usr/bin/env /bin/env] - ## # Constructs an Installer instance that will install the gem located at # +gem+. +options+ is a Hash with the following keys: @@ -100,17 +109,17 @@ class Gem::Installer :source_index => Gem.source_index, }.merge options - @env_shebang = options[:env_shebang] - @force = options[:force] - gem_home = options[:install_dir] - @gem_home = Pathname.new(gem_home).expand_path + @env_shebang = options[:env_shebang] + @force = options[:force] + gem_home = options[:install_dir] + @gem_home = Pathname.new(gem_home).expand_path @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] + @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 @@ -121,7 +130,7 @@ class Gem::Installer begin FileUtils.mkdir_p @gem_home rescue Errno::EACCES, Errno::ENOTDIR - # We'll divert to ~/.gem below + # We'll divert to ~/.gems below end if not File.writable? @gem_home or @@ -131,7 +140,7 @@ class Gem::Installer if options[:user_install] == false then # You don't want to use ~ raise Gem::FilePermissionError, @gem_home elsif options[:user_install].nil? then - unless self.class.home_install_warning then + unless self.class.home_install_warning or options[:unpack] then alert_warning "Installing to ~/.gem since #{@gem_home} and\n\t #{Gem.bindir} aren't both writable." self.class.home_install_warning = true end @@ -392,19 +401,21 @@ class Gem::Installer ruby_name = Gem::ConfigMap[:ruby_install_name] if @env_shebang path = File.join @gem_dir, @spec.bindir, bin_file_name first_line = File.open(path, "rb") {|file| file.gets} + if /\A#!/ =~ first_line then # Preserve extra words on shebang line, like "-w". Thanks RPA. shebang = first_line.sub(/\A\#!.*?ruby\S*(?=(\s+\S+))/, "#!#{Gem.ruby}") opts = $1 shebang.strip! # Avoid nasty ^M issues. end - if !ruby_name + + if not ruby_name then "#!#{Gem.ruby}#{opts}" - elsif opts - %{#!/bin/sh\n'exec' #{ruby_name.dump} '-x' "$0" "$@"\n#{shebang}} + elsif opts then + "#!/bin/sh\n'exec' #{ruby_name.dump} '-x' \"$0\" \"$@\"\n#{shebang}" else # Create a plain shebang line. - @env_path ||= ENV_PATHS.find {|path| File.executable?(path)} + @env_path ||= ENV_PATHS.find {|env_path| File.executable? env_path } "#!#{@env_path} #{ruby_name}" end end @@ -432,7 +443,7 @@ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then end gem '#{@spec.name}', version -load '#{bin_file_name}' +load Gem.bin_path('#{@spec.name}', '#{bin_file_name}', version) TEXT end @@ -443,10 +454,10 @@ TEXT <<-TEXT @ECHO OFF IF NOT "%~f0" == "~f0" GOTO :WinNT -@"#{File.basename(Gem.ruby)}" "#{File.join(bindir, bin_file_name)}" %1 %2 %3 %4 %5 %6 %7 %8 %9 +@"#{File.basename(Gem.ruby).chomp('"')}" "#{File.join(bindir, bin_file_name)}" %1 %2 %3 %4 %5 %6 %7 %8 %9 GOTO :EOF :WinNT -@"#{File.basename(Gem.ruby)}" "%~dpn0" %* +@"#{File.basename(Gem.ruby).chomp('"')}" "%~dpn0" %* TEXT end @@ -531,6 +542,7 @@ Results logged to #{File.join(Dir.pwd, 'gem_make.out')} raise Gem::InstallError, msg end + FileUtils.rm_rf(path) if File.exists?(path) FileUtils.mkdir_p File.dirname(path) File.open(path, "wb") do |out| -- cgit v1.2.3