2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2007-11-10 02:48:56 -05:00
|
|
|
#--
|
|
|
|
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
|
|
|
# All rights reserved.
|
|
|
|
# See LICENSE.txt for permissions.
|
|
|
|
#++
|
|
|
|
|
2013-10-16 18:37:39 -04:00
|
|
|
require 'rubygems/command'
|
2011-01-18 19:08:49 -05:00
|
|
|
require 'rubygems/exceptions'
|
2012-11-29 01:52:18 -05:00
|
|
|
require 'rubygems/package'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/ext'
|
2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/user_interaction'
|
2013-02-21 17:05:09 -05:00
|
|
|
require 'fileutils'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
##
|
2012-11-29 01:52:18 -05:00
|
|
|
# The installer installs the files contained in the .gem into the Gem.home.
|
2007-11-10 02:48:56 -05:00
|
|
|
#
|
|
|
|
# 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.
|
2009-06-09 17:38:59 -04:00
|
|
|
#
|
2011-01-19 16:23:04 -05:00
|
|
|
# The installer invokes pre and post install hooks. Hooks can be added either
|
2009-06-09 17:38:59 -04:00
|
|
|
# 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.
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
class Gem::Installer
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Paths where env(1) might live. Some systems are broken and have it in
|
|
|
|
# /bin
|
|
|
|
|
|
|
|
ENV_PATHS = %w[/usr/bin/env /bin/env]
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
##
|
2013-10-15 20:14:16 -04:00
|
|
|
# Deprecated in favor of Gem::Ext::BuildError
|
|
|
|
|
|
|
|
ExtensionBuildError = Gem::Ext::BuildError # :nodoc:
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
include Gem::UserInteraction
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
##
|
|
|
|
# Filename of the gem being installed.
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
attr_reader :gem
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# The directory a gem's executables will be installed into
|
|
|
|
|
|
|
|
attr_reader :bin_dir
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
attr_reader :build_root # :nodoc:
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# The gem repository the gem will be installed into
|
|
|
|
|
|
|
|
attr_reader :gem_home
|
|
|
|
|
2011-01-19 16:23:04 -05:00
|
|
|
##
|
|
|
|
# The options passed when the Gem::Installer was instantiated.
|
|
|
|
|
|
|
|
attr_reader :options
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
@path_warning = false
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
@install_lock = Mutex.new
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
class << self
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
|
|
|
# True if we've warned about PATH not including Gem.bindir
|
|
|
|
|
|
|
|
attr_accessor :path_warning
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
##
|
|
|
|
# Certain aspects of the install process are not thread-safe. This lock is
|
|
|
|
# used to allow multiple threads to install Gems at the same time.
|
|
|
|
|
|
|
|
attr_reader :install_lock
|
|
|
|
|
|
|
|
##
|
|
|
|
# Overrides the executable format.
|
|
|
|
#
|
|
|
|
# This is a sprintf format with a "%s" which will be replaced with the
|
|
|
|
# executable name. It is based off the ruby executable name's difference
|
|
|
|
# from "ruby".
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
attr_writer :exec_format
|
|
|
|
|
|
|
|
# Defaults to use Ruby's program prefix and suffix.
|
|
|
|
def exec_format
|
|
|
|
@exec_format ||= Gem.default_exec_format
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
##
|
|
|
|
# Construct an installer object for the gem file located at +path+
|
|
|
|
|
|
|
|
def self.at path, options = {}
|
|
|
|
security_policy = options[:security_policy]
|
|
|
|
package = Gem::Package.new path, security_policy
|
|
|
|
new package, options
|
|
|
|
end
|
|
|
|
|
|
|
|
class FakePackage
|
|
|
|
attr_accessor :spec
|
|
|
|
|
|
|
|
def initialize(spec)
|
|
|
|
@spec = spec
|
|
|
|
end
|
|
|
|
|
|
|
|
def extract_files destination_dir, pattern = '*'
|
|
|
|
FileUtils.mkdir_p destination_dir
|
|
|
|
|
|
|
|
spec.files.each do |file|
|
|
|
|
file = File.join destination_dir, file
|
|
|
|
next if File.exist? file
|
|
|
|
FileUtils.mkdir_p File.dirname(file)
|
|
|
|
File.open file, 'w' do |fp| fp.puts "# #{file}" end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def copy_to path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Construct an installer object for an ephemeral gem (one where we don't
|
|
|
|
# actually have a .gem file, just a spec)
|
|
|
|
|
|
|
|
def self.for_spec spec, options = {}
|
|
|
|
# FIXME: we should have a real Package class for this
|
|
|
|
new FakePackage.new(spec), options
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
##
|
|
|
|
# Constructs an Installer instance that will install the gem located at
|
|
|
|
# +gem+. +options+ is a Hash with the following keys:
|
|
|
|
#
|
2012-11-29 01:52:18 -05:00
|
|
|
# :bin_dir:: Where to put a bin wrapper if needed.
|
|
|
|
# :development:: Whether or not development dependencies should be installed.
|
2007-11-10 02:48:56 -05:00
|
|
|
# :env_shebang:: Use /usr/bin/env in bin wrappers.
|
|
|
|
# :force:: Overrides all version checks and security policy checks, except
|
|
|
|
# for a signed-gems-only policy.
|
2013-09-14 04:59:02 -04:00
|
|
|
# :format_executable:: Format the executable the same as the Ruby executable.
|
|
|
|
# If your Ruby is ruby18, foo_exec will be installed as
|
2007-12-20 03:39:12 -05:00
|
|
|
# foo_exec18.
|
2012-11-29 01:52:18 -05:00
|
|
|
# :ignore_dependencies:: Don't raise if a dependency is missing.
|
|
|
|
# :install_dir:: The directory to install the gem into.
|
2007-11-10 02:48:56 -05:00
|
|
|
# :security_policy:: Use the specified security policy. See Gem::Security
|
2012-11-29 01:52:18 -05:00
|
|
|
# :user_install:: Indicate that the gem should be unpacked into the users
|
|
|
|
# personal gem directory.
|
|
|
|
# :only_install_dir:: Only validate dependencies against what is in the
|
|
|
|
# install_dir
|
2007-11-10 02:48:56 -05:00
|
|
|
# :wrappers:: Install wrappers if true, symlinks if false.
|
2012-11-29 01:52:18 -05:00
|
|
|
# :build_args:: An Array of arguments to pass to the extension builder
|
|
|
|
# process. If not set, then Gem::Command.build_args is used
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
def initialize(package, options={})
|
2011-01-18 19:08:49 -05:00
|
|
|
require 'fileutils'
|
|
|
|
|
2011-01-19 16:23:04 -05:00
|
|
|
@options = options
|
2015-07-01 17:50:14 -04:00
|
|
|
if package.is_a? String
|
|
|
|
security_policy = options[:security_policy]
|
|
|
|
@package = Gem::Package.new package, security_policy
|
|
|
|
if $VERBOSE
|
|
|
|
warn "constructing an Installer object with a string is deprecated. Please use Gem::Installer.at (called from: #{caller.first})"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@package = package
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2011-01-19 16:23:04 -05:00
|
|
|
process_options
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
if options[:user_install] and not options[:unpack] then
|
2008-09-25 06:13:50 -04:00
|
|
|
@gem_home = Gem.user_dir
|
2013-02-18 18:15:49 -05:00
|
|
|
@bin_dir = Gem.bindir gem_home unless options[:bin_dir]
|
2011-01-19 16:23:04 -05:00
|
|
|
check_that_user_bin_dir_is_in_path
|
2008-06-25 22:06:00 -04:00
|
|
|
end
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
2008-06-25 22:06:00 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
##
|
2012-11-29 01:52:18 -05:00
|
|
|
# Checks if +filename+ exists in +@bin_dir+.
|
|
|
|
#
|
|
|
|
# If +@force+ is set +filename+ is overwritten.
|
|
|
|
#
|
|
|
|
# If +filename+ exists and is a RubyGems wrapper for different gem the user
|
|
|
|
# is consulted.
|
|
|
|
#
|
|
|
|
# If +filename+ exists and +@bin_dir+ is Gem.default_bindir (/usr/local) the
|
|
|
|
# user is consulted.
|
|
|
|
#
|
|
|
|
# Otherwise +filename+ is overwritten.
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def check_executable_overwrite filename # :nodoc:
|
|
|
|
return if @force
|
|
|
|
|
2013-02-27 18:20:57 -05:00
|
|
|
generated_bin = File.join @bin_dir, formatted_program_filename(filename)
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
return unless File.exist? generated_bin
|
|
|
|
|
|
|
|
ruby_executable = false
|
|
|
|
existing = nil
|
|
|
|
|
|
|
|
open generated_bin, 'rb' do |io|
|
|
|
|
next unless io.gets =~ /^#!/ # shebang
|
|
|
|
io.gets # blankline
|
|
|
|
|
|
|
|
# TODO detect a specially formatted comment instead of trying
|
2013-09-14 04:59:02 -04:00
|
|
|
# to run a regexp against Ruby code.
|
2012-11-29 01:52:18 -05:00
|
|
|
next unless io.gets =~ /This file was generated by RubyGems/
|
|
|
|
|
|
|
|
ruby_executable = true
|
2016-02-01 07:43:26 -05:00
|
|
|
existing = io.read.slice(%r{
|
|
|
|
^(
|
|
|
|
gem \s |
|
|
|
|
load \s Gem\.bin_path\(
|
|
|
|
)
|
|
|
|
(['"])(.*?)(\2),
|
|
|
|
}x, 3)
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
return if spec.name == existing
|
|
|
|
|
|
|
|
# somebody has written to RubyGems' directory, overwrite, too bad
|
|
|
|
return if Gem.default_bindir != @bin_dir and not ruby_executable
|
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
question = "#{spec.name}'s executable \"#{filename}\" conflicts with ".dup
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
if ruby_executable then
|
|
|
|
question << existing
|
|
|
|
|
|
|
|
return if ask_yes_no "#{question}\nOverwrite the executable?", false
|
|
|
|
|
|
|
|
conflict = "installed executable from #{existing}"
|
|
|
|
else
|
|
|
|
question << generated_bin
|
|
|
|
|
|
|
|
return if ask_yes_no "#{question}\nOverwrite the executable?", false
|
|
|
|
|
|
|
|
conflict = generated_bin
|
|
|
|
end
|
|
|
|
|
|
|
|
raise Gem::InstallError,
|
|
|
|
"\"#{filename}\" from #{spec.name} conflicts with #{conflict}"
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2012-11-29 01:52:18 -05:00
|
|
|
# Lazy accessor for the spec's gem directory.
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def gem_dir
|
|
|
|
@gem_dir ||= File.join(gem_home, "gems", spec.full_name)
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
2010-02-21 21:52:35 -05:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
##
|
|
|
|
# Lazy accessor for the installer's spec.
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def spec
|
2015-07-01 17:50:14 -04:00
|
|
|
@package.spec
|
2012-11-29 01:52:18 -05:00
|
|
|
rescue Gem::Package::Error => e
|
|
|
|
raise Gem::InstallError, "invalid gem: #{e.message}"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Installs the gem and returns a loaded Gem::Specification for the installed
|
|
|
|
# gem.
|
|
|
|
#
|
|
|
|
# The gem will be installed with the following structure:
|
|
|
|
#
|
|
|
|
# @gem_home/
|
|
|
|
# cache/<gem-version>.gem #=> a cached copy of the installed gem
|
|
|
|
# gems/<gem-version>/... #=> extracted files
|
|
|
|
# specifications/<gem-version>.gemspec #=> the Gem::Specification
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def install
|
2012-12-22 19:35:09 -05:00
|
|
|
pre_install_checks
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
FileUtils.rm_f File.join gem_home, 'specifications', spec.spec_name
|
2013-12-18 22:05:37 -05:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
run_pre_install_hooks
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-03-01 04:41:32 -05:00
|
|
|
# Completely remove any previous gem files
|
2012-12-22 19:35:09 -05:00
|
|
|
FileUtils.rm_rf gem_dir
|
2011-03-01 04:41:32 -05:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
FileUtils.mkdir_p gem_dir
|
2013-07-09 19:41:44 -04:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
if @options[:install_as_default]
|
2015-07-01 17:50:14 -04:00
|
|
|
spec.loaded_from = default_spec_file
|
2013-09-14 04:59:02 -04:00
|
|
|
extract_bin
|
|
|
|
write_default_spec
|
|
|
|
else
|
2015-07-01 17:50:14 -04:00
|
|
|
spec.loaded_from = spec_file
|
2013-09-14 04:59:02 -04:00
|
|
|
extract_files
|
2013-07-09 19:41:44 -04:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
build_extensions
|
|
|
|
write_build_info_file
|
|
|
|
run_post_build_hooks
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
generate_bin
|
|
|
|
write_spec
|
|
|
|
write_cache_file
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
say spec.post_install_message if options[:post_install_message] && !spec.post_install_message.nil?
|
2013-09-13 15:58:57 -04:00
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
Gem::Installer.install_lock.synchronize { Gem::Specification.reset }
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
run_post_install_hooks
|
|
|
|
|
|
|
|
spec
|
|
|
|
|
|
|
|
# TODO This rescue is in the wrong place. What is raising this exception?
|
2012-12-22 19:35:09 -05:00
|
|
|
# move this rescue to around the code that actually might raise it.
|
2012-11-29 01:52:18 -05:00
|
|
|
rescue Zlib::GzipFile::Error
|
|
|
|
raise Gem::InstallError, "gzip error installing #{gem}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_pre_install_hooks # :nodoc:
|
|
|
|
Gem.pre_install_hooks.each do |hook|
|
|
|
|
if hook.call(self) == false then
|
|
|
|
location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/
|
|
|
|
|
|
|
|
message = "pre-install hook#{location} failed for #{spec.full_name}"
|
|
|
|
raise Gem::InstallError, message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_post_build_hooks # :nodoc:
|
|
|
|
Gem.post_build_hooks.each do |hook|
|
|
|
|
if hook.call(self) == 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
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_post_install_hooks # :nodoc:
|
2008-09-25 06:13:50 -04:00
|
|
|
Gem.post_install_hooks.each do |hook|
|
|
|
|
hook.call self
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# Return an Array of Specifications contained within the gem_home
|
|
|
|
# we'll be installing into.
|
|
|
|
|
|
|
|
def installed_specs
|
|
|
|
@specs ||= begin
|
|
|
|
specs = []
|
|
|
|
|
|
|
|
Dir[File.join(gem_home, "specifications", "*.gemspec")].each do |path|
|
|
|
|
spec = Gem::Specification.load path.untaint
|
|
|
|
specs << spec if spec
|
|
|
|
end
|
|
|
|
|
|
|
|
specs
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Ensure that the dependency is satisfied by the current installation of
|
|
|
|
# gem. If it is not an exception is raised.
|
|
|
|
#
|
|
|
|
# spec :: Gem::Specification
|
|
|
|
# dependency :: Gem::Dependency
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def ensure_dependency(spec, dependency)
|
|
|
|
unless installation_satisfies_dependency? dependency then
|
|
|
|
raise Gem::InstallError, "#{spec.name} requires #{dependency}"
|
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2012-11-29 01:52:18 -05:00
|
|
|
# True if the gems in the system satisfy +dependency+.
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def installation_satisfies_dependency?(dependency)
|
2014-09-13 23:30:02 -04:00
|
|
|
return true if @options[:development] and dependency.type == :development
|
2012-11-29 01:52:18 -05:00
|
|
|
return true if installed_specs.detect { |s| dependency.matches_spec? s }
|
|
|
|
return false if @only_install_dir
|
2011-05-31 23:45:05 -04:00
|
|
|
not dependency.matching_specs.empty?
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Unpacks the gem into the given directory.
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def unpack(directory)
|
|
|
|
@gem_dir = directory
|
|
|
|
extract_files
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
##
|
2015-11-23 20:00:15 -05:00
|
|
|
# The location of the spec file that is installed.
|
2012-11-29 01:52:18 -05:00
|
|
|
#
|
|
|
|
|
|
|
|
def spec_file
|
|
|
|
File.join gem_home, "specifications", "#{spec.full_name}.gemspec"
|
|
|
|
end
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
##
|
2015-11-23 20:00:15 -05:00
|
|
|
# The location of the default spec file for default gems.
|
2013-09-14 04:59:02 -04:00
|
|
|
#
|
|
|
|
|
|
|
|
def default_spec_file
|
2015-07-01 17:50:14 -04:00
|
|
|
File.join Gem::Specification.default_specifications_dir, "#{spec.full_name}.gemspec"
|
2013-09-14 04:59:02 -04:00
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
##
|
2008-12-22 18:11:11 -05:00
|
|
|
# Writes the .gemspec specification (in Ruby) to the gem home's
|
|
|
|
# specifications directory.
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def write_spec
|
2013-07-08 18:41:03 -04:00
|
|
|
open spec_file, 'w' do |file|
|
2013-10-19 20:31:12 -04:00
|
|
|
spec.installed_by_version = Gem.rubygems_version
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
file.puts spec.to_ruby_for_cache
|
2013-10-19 20:31:12 -04:00
|
|
|
|
2013-07-08 18:41:03 -04:00
|
|
|
file.fsync rescue nil # for filesystems without fsync(2)
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
2013-07-09 19:41:44 -04:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
##
|
|
|
|
# Writes the full .gemspec specification (in Ruby) to the gem home's
|
|
|
|
# specifications/default directory.
|
|
|
|
|
|
|
|
def write_default_spec
|
|
|
|
File.open(default_spec_file, "w") do |file|
|
|
|
|
file.puts spec.to_ruby
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
##
|
|
|
|
# Creates windows .bat files for easy running of commands
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
def generate_windows_script(filename, bindir)
|
2007-11-10 02:48:56 -05:00
|
|
|
if Gem.win_platform? then
|
|
|
|
script_name = filename + ".bat"
|
2007-12-20 03:39:12 -05:00
|
|
|
script_path = File.join bindir, File.basename(script_name)
|
|
|
|
File.open script_path, 'w' do |file|
|
2007-11-10 02:48:56 -05:00
|
|
|
file.puts windows_stub_script(bindir, filename)
|
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
verbose script_path
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def generate_bin # :nodoc:
|
2011-05-31 23:45:05 -04:00
|
|
|
return if spec.executables.nil? or spec.executables.empty?
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
Dir.mkdir @bin_dir unless File.exist? @bin_dir
|
|
|
|
raise Gem::FilePermissionError.new(@bin_dir) unless File.writable? @bin_dir
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
spec.executables.each do |filename|
|
2007-11-10 02:48:56 -05:00
|
|
|
filename.untaint
|
2012-11-29 01:52:18 -05:00
|
|
|
bin_path = File.join gem_dir, spec.bindir, filename
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
unless File.exist? bin_path then
|
|
|
|
# TODO change this to a more useful warning
|
|
|
|
warn "#{bin_path} maybe `gem pristine #{spec.name}` will fix it?"
|
2011-05-31 23:45:05 -04:00
|
|
|
next
|
2011-03-01 04:41:32 -05:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2014-12-06 19:53:01 -05:00
|
|
|
mode = File.stat(bin_path).mode
|
|
|
|
FileUtils.chmod mode | 0111, bin_path unless (mode | 0111) == mode
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
check_executable_overwrite filename
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
if @wrappers then
|
2012-11-29 01:52:18 -05:00
|
|
|
generate_bin_script filename, @bin_dir
|
2007-11-10 02:48:56 -05:00
|
|
|
else
|
2012-11-29 01:52:18 -05:00
|
|
|
generate_bin_symlink filename, @bin_dir
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Creates the scripts to run the applications in the gem.
|
|
|
|
#--
|
|
|
|
# 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
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def generate_bin_script(filename, bindir)
|
2007-12-20 03:39:12 -05:00
|
|
|
bin_script_path = File.join bindir, formatted_program_filename(filename)
|
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2011-03-01 04:41:32 -05:00
|
|
|
File.open bin_script_path, 'wb', 0755 do |file|
|
2011-01-18 19:08:49 -05:00
|
|
|
file.print app_script_text(filename)
|
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
verbose bin_script_path
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
generate_windows_script filename, bindir
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Creates the symlinks to run the applications in the gem. Moves
|
|
|
|
# the symlink if the gem being installed has a newer version.
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def generate_bin_symlink(filename, bindir)
|
2007-11-24 22:26:36 -05:00
|
|
|
if Gem.win_platform? then
|
|
|
|
alert_warning "Unable to use symlinks on Windows, installing wrapper"
|
2007-11-10 02:48:56 -05:00
|
|
|
generate_bin_script filename, bindir
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
src = File.join gem_dir, spec.bindir, filename
|
2007-12-20 03:39:12 -05:00
|
|
|
dst = File.join bindir, formatted_program_filename(filename)
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
if File.exist? dst then
|
|
|
|
if File.symlink? dst then
|
|
|
|
link = File.readlink(dst).split File::SEPARATOR
|
|
|
|
cur_version = Gem::Version.create(link[-3].sub(/^.*-/, ''))
|
2011-05-31 23:45:05 -04:00
|
|
|
return if spec.version < cur_version
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
File.unlink dst
|
|
|
|
end
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
FileUtils.symlink src, dst, :verbose => Gem.configuration.really_verbose
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Generates a #! line for +bin_file_name+'s wrapper copying arguments if
|
|
|
|
# necessary.
|
2012-11-29 01:52:18 -05:00
|
|
|
#
|
|
|
|
# If the :custom_shebang config is set, then it is used as a template
|
|
|
|
# for how to create the shebang used for to run a gem's executables.
|
|
|
|
#
|
|
|
|
# The template supports 4 expansions:
|
|
|
|
#
|
|
|
|
# $env the path to the unix env utility
|
|
|
|
# $ruby the path to the currently running ruby interpreter
|
|
|
|
# $exec the path to the gem's executable
|
|
|
|
# $name the name of the gem the executable is for
|
|
|
|
#
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def shebang(bin_file_name)
|
2014-01-06 20:19:28 -05:00
|
|
|
ruby_name = RbConfig::CONFIG['ruby_install_name'] if @env_shebang
|
2012-11-29 01:52:18 -05:00
|
|
|
path = File.join gem_dir, spec.bindir, bin_file_name
|
2009-03-09 03:03:39 -04:00
|
|
|
first_line = File.open(path, "rb") {|file| file.gets}
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2009-03-09 03:03:39 -04:00
|
|
|
if /\A#!/ =~ first_line then
|
|
|
|
# Preserve extra words on shebang line, like "-w". Thanks RPA.
|
2012-04-17 20:04:12 -04:00
|
|
|
shebang = first_line.sub(/\A\#!.*?ruby\S*((\s+\S+)+)/, "#!#{Gem.ruby}")
|
2009-03-14 23:01:39 -04:00
|
|
|
opts = $1
|
2009-03-09 03:03:39 -04:00
|
|
|
shebang.strip! # Avoid nasty ^M issues.
|
2009-03-14 23:01:39 -04:00
|
|
|
end
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
if which = Gem.configuration[:custom_shebang]
|
|
|
|
# replace bin_file_name with "ruby" to avoid endless loops
|
2014-01-06 20:19:28 -05:00
|
|
|
which = which.gsub(/ #{bin_file_name}$/," #{RbConfig::CONFIG['ruby_install_name']}")
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
which = which.gsub(/\$(\w+)/) do
|
|
|
|
case $1
|
|
|
|
when "env"
|
|
|
|
@env_path ||= ENV_PATHS.find {|env_path| File.executable? env_path }
|
|
|
|
when "ruby"
|
|
|
|
"#{Gem.ruby}#{opts}"
|
|
|
|
when "exec"
|
|
|
|
bin_file_name
|
|
|
|
when "name"
|
|
|
|
spec.name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
"#!#{which}"
|
|
|
|
elsif not ruby_name then
|
2009-03-14 23:01:39 -04:00
|
|
|
"#!#{Gem.ruby}#{opts}"
|
2009-06-09 17:38:59 -04:00
|
|
|
elsif opts then
|
|
|
|
"#!/bin/sh\n'exec' #{ruby_name.dump} '-x' \"$0\" \"$@\"\n#{shebang}"
|
2007-11-10 02:48:56 -05:00
|
|
|
else
|
2009-03-09 03:03:39 -04:00
|
|
|
# Create a plain shebang line.
|
2009-06-09 17:38:59 -04:00
|
|
|
@env_path ||= ENV_PATHS.find {|env_path| File.executable? env_path }
|
2009-03-14 23:01:39 -04:00
|
|
|
"#!#{@env_path} #{ruby_name}"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-22 19:35:09 -05:00
|
|
|
##
|
|
|
|
# Ensures the Gem::Specification written out for this gem is loadable upon
|
|
|
|
# installation.
|
|
|
|
|
|
|
|
def ensure_loadable_spec
|
|
|
|
ruby = spec.to_ruby_for_cache
|
2013-01-16 19:37:28 -05:00
|
|
|
ruby.untaint
|
2012-12-22 19:35:09 -05:00
|
|
|
|
|
|
|
begin
|
|
|
|
eval ruby
|
|
|
|
rescue StandardError, SyntaxError => e
|
|
|
|
raise Gem::InstallError,
|
|
|
|
"The specification for #{spec.full_name} is corrupt (#{e.class})"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def ensure_required_ruby_version_met # :nodoc:
|
2011-05-31 23:45:05 -04:00
|
|
|
if rrv = spec.required_ruby_version then
|
2011-01-19 16:23:04 -05:00
|
|
|
unless rrv.satisfied_by? Gem.ruby_version then
|
2011-05-31 23:45:05 -04:00
|
|
|
raise Gem::InstallError, "#{spec.name} requires Ruby version #{rrv}."
|
2011-01-19 16:23:04 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def ensure_required_rubygems_version_met # :nodoc:
|
2011-05-31 23:45:05 -04:00
|
|
|
if rrgv = spec.required_rubygems_version then
|
2012-11-29 01:52:18 -05:00
|
|
|
unless rrgv.satisfied_by? Gem.rubygems_version then
|
2011-01-19 16:23:04 -05:00
|
|
|
raise Gem::InstallError,
|
2011-05-31 23:45:05 -04:00
|
|
|
"#{spec.name} requires RubyGems version #{rrgv}. " +
|
2011-01-19 16:23:04 -05:00
|
|
|
"Try 'gem update --system' to update RubyGems itself."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def ensure_dependencies_met # :nodoc:
|
2011-05-31 23:45:05 -04:00
|
|
|
deps = spec.runtime_dependencies
|
|
|
|
deps |= spec.development_dependencies if @development
|
2011-01-19 16:23:04 -05:00
|
|
|
|
|
|
|
deps.each do |dep_gem|
|
2011-05-31 23:45:05 -04:00
|
|
|
ensure_dependency spec, dep_gem
|
2011-01-19 16:23:04 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def process_options # :nodoc:
|
2011-01-19 16:23:04 -05:00
|
|
|
@options = {
|
|
|
|
:bin_dir => nil,
|
|
|
|
:env_shebang => false,
|
|
|
|
:force => false,
|
2016-02-01 07:43:26 -05:00
|
|
|
:only_install_dir => false,
|
|
|
|
:post_install_message => true
|
2011-01-31 22:11:34 -05:00
|
|
|
}.merge options
|
2011-01-19 16:23:04 -05:00
|
|
|
|
2011-01-31 22:11:34 -05:00
|
|
|
@env_shebang = options[:env_shebang]
|
|
|
|
@force = options[:force]
|
2013-09-14 04:59:02 -04:00
|
|
|
@install_dir = options[:install_dir]
|
|
|
|
@gem_home = options[:install_dir] || Gem.dir
|
2011-01-31 22:11:34 -05:00
|
|
|
@ignore_dependencies = options[:ignore_dependencies]
|
|
|
|
@format_executable = options[:format_executable]
|
|
|
|
@wrappers = options[:wrappers]
|
2012-11-29 01:52:18 -05:00
|
|
|
@only_install_dir = options[:only_install_dir]
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
@bin_dir = options[:bin_dir] || Gem.bindir(gem_home)
|
2011-01-31 22:11:34 -05:00
|
|
|
@development = options[:development]
|
2014-09-13 23:30:02 -04:00
|
|
|
@build_root = options[:build_root]
|
2011-01-19 16:23:04 -05:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
@build_args = options[:build_args] || Gem::Command.build_args
|
2014-09-13 23:30:02 -04:00
|
|
|
|
|
|
|
unless @build_root.nil?
|
|
|
|
require 'pathname'
|
|
|
|
@build_root = Pathname.new(@build_root).expand_path
|
|
|
|
@bin_dir = File.join(@build_root, options[:bin_dir] || Gem.bindir(@gem_home))
|
|
|
|
@gem_home = File.join(@build_root, @gem_home)
|
|
|
|
alert_warning "You build with buildroot.\n Build root: #{@build_root}\n Bin dir: #{@bin_dir}\n Gem home: #{@gem_home}"
|
|
|
|
end
|
2011-01-19 16:23:04 -05:00
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def check_that_user_bin_dir_is_in_path # :nodoc:
|
2011-07-26 21:40:07 -04:00
|
|
|
user_bin_dir = @bin_dir || Gem.bindir(gem_home)
|
2013-02-19 17:51:38 -05:00
|
|
|
user_bin_dir = user_bin_dir.gsub(File::SEPARATOR, File::ALT_SEPARATOR) if
|
|
|
|
File::ALT_SEPARATOR
|
|
|
|
|
2012-09-28 04:29:21 -04:00
|
|
|
path = ENV['PATH']
|
|
|
|
if Gem.win_platform? then
|
|
|
|
path = path.downcase
|
|
|
|
user_bin_dir = user_bin_dir.downcase
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
path = path.split(File::PATH_SEPARATOR)
|
|
|
|
|
|
|
|
unless path.include? user_bin_dir then
|
|
|
|
unless !Gem.win_platform? && (path.include? user_bin_dir.sub(ENV['HOME'], '~'))
|
|
|
|
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
|
2011-01-19 16:23:04 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def verify_gem_home(unpack = false) # :nodoc:
|
2011-05-31 23:45:05 -04:00
|
|
|
FileUtils.mkdir_p gem_home
|
|
|
|
raise Gem::FilePermissionError, gem_home unless
|
|
|
|
unpack or File.writable?(gem_home)
|
2011-01-19 16:23:04 -05:00
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
##
|
2007-11-10 02:48:56 -05:00
|
|
|
# Return the text for an application file.
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def app_script_text(bin_file_name)
|
2011-05-31 23:45:05 -04:00
|
|
|
return <<-TEXT
|
2007-11-10 02:48:56 -05:00
|
|
|
#{shebang bin_file_name}
|
|
|
|
#
|
|
|
|
# This file was generated by RubyGems.
|
|
|
|
#
|
2011-05-31 23:45:05 -04:00
|
|
|
# The application '#{spec.name}' is installed as part of a gem, and
|
2007-11-10 02:48:56 -05:00
|
|
|
# this file is here to facilitate running it.
|
|
|
|
#
|
|
|
|
|
|
|
|
require 'rubygems'
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
version = "#{Gem::Requirement.default}.a"
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2012-04-17 20:04:12 -04:00
|
|
|
if ARGV.first
|
|
|
|
str = ARGV.first
|
|
|
|
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
|
2014-02-03 19:48:31 -05:00
|
|
|
if str =~ /\\A_(.*)_\\z/ and Gem::Version.correct?($1) then
|
2012-04-17 20:04:12 -04:00
|
|
|
version = $1
|
|
|
|
ARGV.shift
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
load Gem.bin_path('#{spec.name}', '#{bin_file_name}', version)
|
2007-11-10 02:48:56 -05:00
|
|
|
TEXT
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
##
|
2013-09-14 04:59:02 -04:00
|
|
|
# return the stub script text used to launch the true Ruby script
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def windows_stub_script(bindir, bin_file_name)
|
2015-02-05 08:42:45 -05:00
|
|
|
ruby = Gem.ruby.gsub(/^\"|\"$/, "").tr(File::SEPARATOR, "\\")
|
2011-05-31 23:45:05 -04:00
|
|
|
return <<-TEXT
|
2007-11-10 02:48:56 -05:00
|
|
|
@ECHO OFF
|
|
|
|
IF NOT "%~f0" == "~f0" GOTO :WinNT
|
2014-10-01 04:30:21 -04:00
|
|
|
@"#{ruby}" "#{File.join(bindir, bin_file_name)}" %1 %2 %3 %4 %5 %6 %7 %8 %9
|
2007-11-10 02:48:56 -05:00
|
|
|
GOTO :EOF
|
|
|
|
:WinNT
|
2014-10-01 04:30:21 -04:00
|
|
|
@"#{ruby}" "%~dpn0" %*
|
2007-11-10 02:48:56 -05:00
|
|
|
TEXT
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
##
|
2007-11-10 02:48:56 -05:00
|
|
|
# Builds extensions. Valid types of extensions are extconf.rb files,
|
|
|
|
# configure scripts and rakefiles or mkrf_conf files.
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def build_extensions
|
2013-09-14 04:59:02 -04:00
|
|
|
builder = Gem::Ext::Builder.new spec, @build_args
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
builder.build_extensions
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
##
|
2013-10-15 20:14:16 -04:00
|
|
|
# Logs the build +output+ in +build_dir+, then raises Gem::Ext::BuildError.
|
2013-09-14 04:59:02 -04:00
|
|
|
#
|
|
|
|
# TODO: Delete this for RubyGems 3. It remains for API compatibility
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def extension_build_error(build_dir, output, backtrace = nil) # :nodoc:
|
|
|
|
builder = Gem::Ext::Builder.new spec, @build_args
|
2013-09-13 15:58:57 -04:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
builder.build_error build_dir, output, backtrace
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Reads the file index and extracts each file into the gem directory.
|
|
|
|
#
|
|
|
|
# Ensures that files can't be installed outside the gem directory.
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def extract_files
|
2012-11-29 01:52:18 -05:00
|
|
|
@package.extract_files gem_dir
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
2013-07-09 19:41:44 -04:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
##
|
|
|
|
# Extracts only the bin/ files from the gem into the gem directory.
|
|
|
|
# This is used by default gems to allow a gem-aware stub to function
|
|
|
|
# without the full gem installed.
|
|
|
|
|
|
|
|
def extract_bin
|
|
|
|
@package.extract_files gem_dir, "bin/*"
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
##
|
2007-12-20 03:39:12 -05:00
|
|
|
# Prefix and suffix the program filename the same as ruby.
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
def formatted_program_filename(filename)
|
|
|
|
if @format_executable then
|
|
|
|
self.class.exec_format % File.basename(filename)
|
|
|
|
else
|
|
|
|
filename
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# Return the target directory where the gem is to be installed. This
|
|
|
|
# directory is not guaranteed to be populated.
|
|
|
|
#
|
|
|
|
|
|
|
|
def dir
|
|
|
|
gem_dir.to_s
|
|
|
|
end
|
2012-12-22 19:35:09 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# Performs various checks before installing the gem such as the install
|
2013-09-14 04:59:02 -04:00
|
|
|
# repository is writable and its directories exist, required Ruby and
|
2012-12-22 19:35:09 -05:00
|
|
|
# rubygems versions are met and that dependencies are installed.
|
|
|
|
#
|
|
|
|
# Version and dependency checks are skipped if this install is forced.
|
|
|
|
#
|
|
|
|
# The dependent check will be skipped this install is ignoring dependencies.
|
|
|
|
|
|
|
|
def pre_install_checks
|
|
|
|
verify_gem_home options[:unpack]
|
|
|
|
|
|
|
|
ensure_loadable_spec
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
if options[:install_as_default]
|
|
|
|
Gem.ensure_default_gem_subdirectories gem_home
|
|
|
|
else
|
|
|
|
Gem.ensure_gem_subdirectories gem_home
|
|
|
|
end
|
2012-12-22 19:35:09 -05:00
|
|
|
|
|
|
|
return true if @force
|
|
|
|
|
|
|
|
ensure_required_ruby_version_met
|
|
|
|
ensure_required_rubygems_version_met
|
|
|
|
ensure_dependencies_met unless @ignore_dependencies
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Writes the file containing the arguments for building this gem's
|
|
|
|
# extensions.
|
|
|
|
|
|
|
|
def write_build_info_file
|
|
|
|
return if @build_args.empty?
|
|
|
|
|
2013-07-08 18:41:03 -04:00
|
|
|
build_info_dir = File.join gem_home, 'build_info'
|
|
|
|
|
|
|
|
FileUtils.mkdir_p build_info_dir
|
|
|
|
|
|
|
|
build_info_file = File.join build_info_dir, "#{spec.full_name}.info"
|
|
|
|
|
|
|
|
open build_info_file, 'w' do |io|
|
2012-12-22 19:35:09 -05:00
|
|
|
@build_args.each do |arg|
|
|
|
|
io.puts arg
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Writes the .gem file to the cache directory
|
|
|
|
|
|
|
|
def write_cache_file
|
|
|
|
cache_file = File.join gem_home, 'cache', spec.file_name
|
2015-07-01 17:50:14 -04:00
|
|
|
@package.copy_to cache_file
|
2012-12-22 19:35:09 -05:00
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|