aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/installer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/installer.rb')
-rw-r--r--lib/rubygems/installer.rb47
1 files changed, 35 insertions, 12 deletions
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index 9dbbca8d08..ae699a90a0 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -56,6 +56,7 @@ class Gem::Installer
# foo_exec18.
# :security_policy:: Use the specified security policy. See Gem::Security
# :wrappers:: Install wrappers if true, symlinks if false.
+
def initialize(gem, options={})
@gem = gem
@@ -76,6 +77,7 @@ class Gem::Installer
@security_policy = options[:security_policy]
@wrappers = options[:wrappers]
@bin_dir = options[:bin_dir]
+ @development = options[:development]
begin
@format = Gem::Format.from_file_by_path @gem, @security_policy
@@ -98,6 +100,7 @@ class Gem::Installer
# cache/<gem-version>.gem #=> a cached copy of the installed gem
# gems/<gem-version>/... #=> extracted files
# specifications/<gem-version>.gemspec #=> the Gem::Specification
+
def install
# If we're forcing the install then disable security unless the security
# policy says that we only install singed gems.
@@ -119,7 +122,10 @@ class Gem::Installer
end
unless @ignore_dependencies then
- @spec.dependencies.each do |dep_gem|
+ deps = @spec.runtime_dependencies
+ deps |= @spec.development_dependencies if @development
+
+ deps.each do |dep_gem|
ensure_dependency @spec, dep_gem
end
end
@@ -150,6 +156,8 @@ class Gem::Installer
@spec.loaded_from = File.join(@gem_home, 'specifications',
"#{@spec.full_name}.gemspec")
+ Gem.source_index.add_spec @spec
+
return @spec
rescue Zlib::GzipFile::Error
raise Gem::InstallError, "gzip error installing #{@gem}"
@@ -161,6 +169,7 @@ class Gem::Installer
#
# spec :: Gem::Specification
# dependency :: Gem::Dependency
+
def ensure_dependency(spec, dependency)
unless installation_satisfies_dependency? dependency then
raise Gem::InstallError, "#{spec.name} requires #{dependency}"
@@ -170,17 +179,15 @@ class Gem::Installer
end
##
- # True if the current installed gems satisfy the given dependency.
- #
- # dependency :: Gem::Dependency
+ # True if the gems in Gem.source_index satisfy +dependency+.
+
def installation_satisfies_dependency?(dependency)
- current_index = Gem::SourceIndex.from_installed_gems
- current_index.find_name(dependency.name, dependency.version_requirements).size > 0
+ Gem.source_index.find_name(dependency.name, dependency.version_requirements).size > 0
end
##
# Unpacks the gem into the given directory.
- #
+
def unpack(directory)
@gem_dir = directory
@format = Gem::Format.from_file_by_path @gem, @security_policy
@@ -193,7 +200,7 @@ class Gem::Installer
#
# spec:: [Gem::Specification] The Gem specification to output
# spec_path:: [String] The location (path) to write the gemspec to
- #
+
def write_spec
rubycode = @spec.to_ruby
@@ -208,7 +215,7 @@ class Gem::Installer
##
# Creates windows .bat files for easy running of commands
- #
+
def generate_windows_script(bindir, filename)
if Gem.win_platform? then
script_name = filename + ".bat"
@@ -227,7 +234,7 @@ class Gem::Installer
# If the user has asked for the gem to be installed in a directory that is
# the system gem directory, then use the system bin directory, else create
# (or use) a new bin dir under the gem_home.
- bindir = @bin_dir ? @bin_dir : (Gem.bindir @gem_home)
+ bindir = @bin_dir ? @bin_dir : Gem.bindir(@gem_home)
Dir.mkdir bindir unless File.exist? bindir
raise Gem::FilePermissionError.new(bindir) unless File.writable? bindir
@@ -252,7 +259,7 @@ class Gem::Installer
# The Windows script is generated in addition to the regular one due to a
# bug or misfeature in the Windows shell's pipe. See
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/193379
- #
+
def generate_bin_script(filename, bindir)
bin_script_path = File.join bindir, formatted_program_filename(filename)
@@ -260,6 +267,8 @@ class Gem::Installer
# HACK some gems don't have #! in their executables, restore 2008/06
#if File.read(exec_path, 2) == '#!' then
+ FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers
+
File.open bin_script_path, 'w', 0755 do |file|
file.print app_script_text(filename)
end
@@ -277,7 +286,7 @@ class Gem::Installer
##
# Creates the symlinks to run the applications in the gem. Moves
# the symlink if the gem being installed has a newer version.
- #
+
def generate_bin_symlink(filename, bindir)
if Gem.win_platform? then
alert_warning "Unable to use symlinks on Windows, installing wrapper"
@@ -303,6 +312,7 @@ class Gem::Installer
##
# Generates a #! line for +bin_file_name+'s wrapper copying arguments if
# necessary.
+
def shebang(bin_file_name)
if @env_shebang then
"#!/usr/bin/env " + Gem::ConfigMap[:ruby_install_name]
@@ -324,7 +334,9 @@ class Gem::Installer
end
end
+ ##
# Return the text for an application file.
+
def app_script_text(bin_file_name)
<<-TEXT
#{shebang bin_file_name}
@@ -349,7 +361,9 @@ load '#{bin_file_name}'
TEXT
end
+ ##
# return the stub script text used to launch the true ruby script
+
def windows_stub_script(bindir, bin_file_name)
<<-TEXT
@ECHO OFF
@@ -361,8 +375,10 @@ GOTO :EOF
TEXT
end
+ ##
# Builds extensions. Valid types of extensions are extconf.rb files,
# configure scripts and rakefiles or mkrf_conf files.
+
def build_extensions
return if @spec.extensions.empty?
say "Building native extensions. This could take a while..."
@@ -418,6 +434,7 @@ Results logged to #{File.join(Dir.pwd, 'gem_make.out')}
# Reads the file index and extracts each file into the gem directory.
#
# Ensures that files can't be installed outside the gem directory.
+
def extract_files
expand_and_validate_gem_dir
@@ -445,11 +462,15 @@ Results logged to #{File.join(Dir.pwd, 'gem_make.out')}
out.write file_data
end
+ FileUtils.chmod entry['mode'], path
+
say path if Gem.configuration.really_verbose
end
end
+ ##
# Prefix and suffix the program filename the same as ruby.
+
def formatted_program_filename(filename)
if @format_executable then
self.class.exec_format % File.basename(filename)
@@ -460,7 +481,9 @@ Results logged to #{File.join(Dir.pwd, 'gem_make.out')}
private
+ ##
# HACK Pathname is broken on windows.
+
def absolute_path? pathname
pathname.absolute? or (Gem.win_platform? and pathname.to_s =~ /\A[a-z]:/i)
end