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'
|
2018-05-17 21:39:13 -04:00
|
|
|
require 'rubygems/deprecate'
|
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
|
|
|
|
|
2018-05-17 21:39:13 -04:00
|
|
|
extend Gem::Deprecate
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
##
|
|
|
|
# Paths where env(1) might live. Some systems are broken and have it in
|
|
|
|
# /bin
|
|
|
|
|
2018-10-21 20:27:02 -04:00
|
|
|
ENV_PATHS = %w[/usr/bin/env /bin/env].freeze
|
2009-06-09 17:38:59 -04:00
|
|
|
|
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+
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.at(path, options = {})
|
2015-07-01 17:50:14 -04:00
|
|
|
security_policy = options[:security_policy]
|
|
|
|
package = Gem::Package.new path, security_policy
|
|
|
|
new package, options
|
|
|
|
end
|
|
|
|
|
|
|
|
class FakePackage
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
attr_accessor :spec
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
attr_accessor :dir_mode
|
|
|
|
attr_accessor :prog_mode
|
|
|
|
attr_accessor :data_mode
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
def initialize(spec)
|
|
|
|
@spec = spec
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def extract_files(destination_dir, pattern = '*')
|
2015-07-01 17:50:14 -04:00
|
|
|
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)
|
2019-02-14 07:59:03 -05:00
|
|
|
File.open file, 'w' do |fp|
|
|
|
|
fp.puts "# #{file}"
|
|
|
|
end
|
2015-07-01 17:50:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def copy_to(path)
|
2015-07-01 17:50:14 -04:00
|
|
|
end
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Construct an installer object for an ephemeral gem (one where we don't
|
|
|
|
# actually have a .gem file, just a spec)
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def self.for_spec(spec, options = {})
|
2015-07-01 17:50:14 -04:00
|
|
|
# FIXME: we should have a real Package class for this
|
|
|
|
new FakePackage.new(spec), options
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
##
|
2017-10-07 21:32:18 -04:00
|
|
|
# Constructs an Installer instance that will install the gem at +package+ which
|
|
|
|
# can either be a path or an instance of Gem::Package. +options+ is a Hash
|
|
|
|
# with the following keys:
|
2007-11-10 02:48:56 -05:00
|
|
|
#
|
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
|
2017-10-07 21:32:18 -04:00
|
|
|
# :post_install_message:: Print gem post install message if true
|
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
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
@package.dir_mode = options[:dir_mode]
|
|
|
|
@package.prog_mode = options[:prog_mode]
|
|
|
|
@package.data_mode = options[:data_mode]
|
|
|
|
|
2018-08-27 06:05:04 -04:00
|
|
|
@bin_dir = options[:bin_dir] if options[:bin_dir]
|
|
|
|
|
2019-04-26 07:26:21 -04:00
|
|
|
if options[:user_install]
|
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
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def check_executable_overwrite(filename) # :nodoc:
|
2012-11-29 01:52:18 -05:00
|
|
|
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
|
|
|
|
|
2018-02-05 21:58:35 -05:00
|
|
|
File.open generated_bin, 'rb' do |io|
|
2012-11-29 01:52:18 -05:00
|
|
|
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{
|
2017-05-01 07:40:46 -04:00
|
|
|
^\s*(
|
2016-02-01 07:43:26 -05:00
|
|
|
gem \s |
|
2016-03-27 22:26:39 -04:00
|
|
|
load \s Gem\.bin_path\( |
|
|
|
|
load \s Gem\.activate_bin_path\(
|
2016-02-01 07:43:26 -05:00
|
|
|
)
|
|
|
|
(['"])(.*?)(\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
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if ruby_executable
|
2016-04-06 02:01:14 -04:00
|
|
|
question << (existing || 'an unknown executable')
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
2016-09-27 20:57:53 -04:00
|
|
|
# Set loaded_from to ensure extension_dir is correct
|
2018-11-21 05:20:47 -05:00
|
|
|
if @options[:install_as_default]
|
2016-09-27 20:57:53 -04:00
|
|
|
spec.loaded_from = default_spec_file
|
|
|
|
else
|
|
|
|
spec.loaded_from = spec_file
|
|
|
|
end
|
|
|
|
|
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
|
2016-06-18 01:11:55 -04:00
|
|
|
FileUtils.rm_rf spec.extension_dir
|
2011-03-01 04:41:32 -05:00
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
dir_mode = options[:dir_mode]
|
2018-12-22 19:20:49 -05:00
|
|
|
FileUtils.mkdir_p gem_dir, :mode => dir_mode && 0755
|
2013-07-09 19:41:44 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if @options[:install_as_default]
|
2013-09-14 04:59:02 -04:00
|
|
|
extract_bin
|
|
|
|
write_default_spec
|
|
|
|
else
|
|
|
|
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
|
2019-04-02 07:48:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
generate_bin
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2019-04-02 07:48:18 -04:00
|
|
|
unless @options[:install_as_default]
|
2013-09-14 04:59:02 -04:00
|
|
|
write_spec
|
|
|
|
write_cache_file
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
File.chmod(dir_mode, gem_dir) if dir_mode
|
|
|
|
|
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|
|
2018-11-21 05:20:47 -05:00
|
|
|
if hook.call(self) == false
|
2012-11-29 01:52:18 -05:00
|
|
|
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|
|
2018-11-21 05:20:47 -05:00
|
|
|
if hook.call(self) == false
|
2012-11-29 01:52:18 -05:00
|
|
|
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 = []
|
|
|
|
|
2018-08-27 06:05:04 -04:00
|
|
|
Gem::Util.glob_files_in_dir("*.gemspec", File.join(gem_home, "specifications")).each do |path|
|
2012-11-29 01:52:18 -05:00
|
|
|
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)
|
2018-11-21 05:20:47 -05:00
|
|
|
unless installation_satisfies_dependency? dependency
|
2007-11-10 02:48:56 -05:00
|
|
|
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
|
2019-04-26 07:26:21 -04:00
|
|
|
deprecate :unpack, :none, 2020, 04
|
2007-11-10 02:48:56 -05:00
|
|
|
|
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
|
2018-02-05 21:58:35 -05:00
|
|
|
File.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)
|
2018-11-21 05:20:47 -05:00
|
|
|
if Gem.win_platform?
|
2019-02-14 07:59:03 -05:00
|
|
|
script_name = formatted_program_filename(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
|
|
|
|
2018-02-05 21:58:35 -05:00
|
|
|
begin
|
2018-12-22 19:20:49 -05:00
|
|
|
Dir.mkdir @bin_dir, *[options[:dir_mode] && 0755].compact
|
2018-02-05 21:58:35 -05:00
|
|
|
rescue SystemCallError
|
|
|
|
raise unless File.directory? @bin_dir
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
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
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
unless File.exist? bin_path
|
2012-11-29 01:52:18 -05:00
|
|
|
# TODO change this to a more useful warning
|
2017-10-07 21:32:18 -04:00
|
|
|
warn "`#{bin_path}` does not exist, 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
|
2018-05-30 09:01:35 -04:00
|
|
|
dir_mode = options[:prog_mode] || (mode | 0111)
|
|
|
|
FileUtils.chmod dir_mode, bin_path unless dir_mode == mode
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
check_executable_overwrite filename
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if @wrappers
|
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
|
|
|
|
2018-12-22 19:20:49 -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)
|
2018-05-30 09:01:35 -04:00
|
|
|
file.chmod(options[:prog_mode] || 0755)
|
2011-01-18 19:08:49 -05:00
|
|
|
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)
|
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
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if File.exist? dst
|
|
|
|
if File.symlink? dst
|
2007-11-10 02:48:56 -05:00
|
|
|
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
|
2016-04-27 20:33:08 -04:00
|
|
|
rescue NotImplementedError, SystemCallError
|
|
|
|
alert_warning "Unable to use symlinks, installing wrapper"
|
|
|
|
generate_bin_script filename, bindir
|
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
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if /\A#!/ =~ first_line
|
2009-03-09 03:03:39 -04:00
|
|
|
# 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}"
|
2018-11-21 05:20:47 -05:00
|
|
|
elsif not ruby_name
|
2009-03-14 23:01:39 -04:00
|
|
|
"#!#{Gem.ruby}#{opts}"
|
2018-11-21 05:20:47 -05:00
|
|
|
elsif opts
|
2009-06-09 17:38:59 -04:00
|
|
|
"#!/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:
|
2018-11-21 05:20:47 -05:00
|
|
|
if rrv = spec.required_ruby_version
|
|
|
|
ruby_version = Gem.ruby_version
|
|
|
|
unless rrv.satisfied_by? ruby_version
|
2017-10-07 21:32:18 -04:00
|
|
|
raise Gem::RuntimeRequirementNotMetError,
|
|
|
|
"#{spec.name} requires Ruby version #{rrv}. The current ruby version is #{ruby_version}."
|
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:
|
2018-11-21 05:20:47 -05:00
|
|
|
if rrgv = spec.required_rubygems_version
|
|
|
|
unless rrgv.satisfied_by? Gem.rubygems_version
|
2017-10-07 21:32:18 -04:00
|
|
|
rg_version = Gem::VERSION
|
|
|
|
raise Gem::RuntimeRequirementNotMetError,
|
|
|
|
"#{spec.name} requires RubyGems version #{rrgv}. The current RubyGems version is #{rg_version}. " +
|
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']
|
2018-11-21 05:20:47 -05:00
|
|
|
if Gem.win_platform?
|
2012-09-28 04:29:21 -04:00
|
|
|
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)
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
unless path.include? user_bin_dir
|
2014-09-13 23:30:02 -04:00
|
|
|
unless !Gem.win_platform? && (path.include? user_bin_dir.sub(ENV['HOME'], '~'))
|
2018-11-21 05:20:47 -05:00
|
|
|
unless self.class.path_warning
|
2014-09-13 23:30:02 -04:00
|
|
|
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
|
|
|
|
|
2019-04-26 07:26:21 -04:00
|
|
|
def verify_gem_home # :nodoc:
|
2018-12-22 19:20:49 -05:00
|
|
|
FileUtils.mkdir_p gem_home, :mode => options[:dir_mode] && 0755
|
2019-04-26 07:26:21 -04:00
|
|
|
raise Gem::FilePermissionError, gem_home unless File.writable?(gem_home)
|
2011-01-19 16:23:04 -05:00
|
|
|
end
|
|
|
|
|
2019-03-04 22:32:58 -05:00
|
|
|
def verify_spec
|
|
|
|
unless spec.name =~ Gem::Specification::VALID_NAME_PATTERN
|
|
|
|
raise Gem::InstallError, "#{spec} has an invalid name"
|
|
|
|
end
|
|
|
|
|
|
|
|
if spec.raw_require_paths.any?{|path| path =~ /\R/ }
|
|
|
|
raise Gem::InstallError, "#{spec} has an invalid require_paths"
|
|
|
|
end
|
|
|
|
|
|
|
|
if spec.extensions.any?{|ext| ext =~ /\R/ }
|
|
|
|
raise Gem::InstallError, "#{spec} has an invalid extensions"
|
|
|
|
end
|
|
|
|
|
|
|
|
unless spec.specification_version.to_s =~ /\A\d+\z/
|
|
|
|
raise Gem::InstallError, "#{spec} has an invalid specification_version"
|
|
|
|
end
|
|
|
|
|
|
|
|
if spec.dependencies.any? {|dep| dep.type =~ /\R/ || dep.name =~ /\R/ }
|
|
|
|
raise Gem::InstallError, "#{spec} has an invalid dependencies"
|
|
|
|
end
|
2017-08-28 04:31:28 -04: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)
|
2017-05-01 07:40:46 -04:00
|
|
|
# note that the `load` lines cannot be indented, as old RG versions match
|
|
|
|
# against the beginning of the line
|
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
|
|
|
|
2018-11-27 22:08:14 -05:00
|
|
|
str = ARGV.first
|
|
|
|
if str
|
|
|
|
str = str.b[/\\A_(.*)_\\z/, 1]
|
|
|
|
if str and Gem::Version.correct?(str)
|
|
|
|
version = str
|
2012-04-17 20:04:12 -04:00
|
|
|
ARGV.shift
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2017-05-01 07:40:46 -04:00
|
|
|
if Gem.respond_to?(:activate_bin_path)
|
2016-03-27 22:26:39 -04:00
|
|
|
load Gem.activate_bin_path('#{spec.name}', '#{bin_file_name}', version)
|
2017-05-01 07:40:46 -04:00
|
|
|
else
|
|
|
|
gem #{spec.name.dump}, version
|
|
|
|
load Gem.bin_path(#{spec.name.dump}, #{bin_file_name.dump}, version)
|
|
|
|
end
|
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)
|
2018-10-30 23:23:30 -04:00
|
|
|
rb_config = RbConfig::CONFIG
|
|
|
|
rb_topdir = RbConfig::TOPDIR || File.dirname(rb_config["bindir"])
|
|
|
|
|
|
|
|
# get ruby executable file name from RbConfig
|
|
|
|
ruby_exe = "#{rb_config['RUBY_INSTALL_NAME']}#{rb_config['EXEEXT']}"
|
|
|
|
ruby_exe = "ruby.exe" if ruby_exe.empty?
|
|
|
|
|
|
|
|
if File.exist?(File.join bindir, ruby_exe)
|
2018-08-27 06:05:04 -04:00
|
|
|
# stub & ruby.exe withing same folder. Portable
|
|
|
|
<<-TEXT
|
2007-11-10 02:48:56 -05:00
|
|
|
@ECHO OFF
|
2018-08-27 06:05:04 -04:00
|
|
|
@"%~dp0ruby.exe" "%~dpn0" %*
|
|
|
|
TEXT
|
2018-10-30 23:23:30 -04:00
|
|
|
elsif bindir.downcase.start_with? rb_topdir.downcase
|
|
|
|
# stub within ruby folder, but not standard bin. Portable
|
2018-08-27 06:05:04 -04:00
|
|
|
require 'pathname'
|
|
|
|
from = Pathname.new bindir
|
2018-10-30 23:23:30 -04:00
|
|
|
to = Pathname.new "#{rb_topdir}/bin"
|
2018-08-27 06:05:04 -04:00
|
|
|
rel = to.relative_path_from from
|
|
|
|
<<-TEXT
|
|
|
|
@ECHO OFF
|
|
|
|
@"%~dp0#{rel}/ruby.exe" "%~dpn0" %*
|
|
|
|
TEXT
|
|
|
|
else
|
2018-10-30 23:23:30 -04:00
|
|
|
# outside ruby folder, maybe -user-install or bundler. Portable, but ruby
|
|
|
|
# is dependent on PATH
|
2018-08-27 06:05:04 -04:00
|
|
|
<<-TEXT
|
|
|
|
@ECHO OFF
|
|
|
|
@ruby.exe "%~dpn0" %*
|
|
|
|
TEXT
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
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
|
|
|
#
|
2018-05-17 21:39:13 -04:00
|
|
|
# TODO: Delete this for RubyGems 4. 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
|
2018-05-17 21:39:13 -04:00
|
|
|
deprecate :extension_build_error, :none, 2018, 12
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# 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
|
2019-03-04 22:32:58 -05:00
|
|
|
@package.extract_files gem_dir, "#{spec.bindir}/*"
|
2013-09-14 04:59:02 -04:00
|
|
|
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)
|
2018-11-21 05:20:47 -05:00
|
|
|
if @format_executable
|
2007-12-20 03:39:12 -05:00
|
|
|
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.
|
|
|
|
#
|
2017-10-07 21:32:18 -04:00
|
|
|
# The dependent check will be skipped if the install is ignoring dependencies.
|
2012-12-22 19:35:09 -05:00
|
|
|
|
|
|
|
def pre_install_checks
|
2019-04-26 07:26:21 -04:00
|
|
|
verify_gem_home
|
2012-12-22 19:35:09 -05:00
|
|
|
|
2019-03-04 22:32:58 -05:00
|
|
|
# The name and require_paths must be verified first, since it could contain
|
|
|
|
# ruby code that would be eval'ed in #ensure_loadable_spec
|
|
|
|
verify_spec
|
2012-12-22 19:35:09 -05:00
|
|
|
|
2019-03-04 22:32:58 -05:00
|
|
|
ensure_loadable_spec
|
2017-08-28 04:31:28 -04:00
|
|
|
|
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'
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
dir_mode = options[:dir_mode]
|
2018-12-22 19:20:49 -05:00
|
|
|
FileUtils.mkdir_p build_info_dir, :mode => dir_mode && 0755
|
2013-07-08 18:41:03 -04:00
|
|
|
|
|
|
|
build_info_file = File.join build_info_dir, "#{spec.full_name}.info"
|
|
|
|
|
2018-02-05 21:58:35 -05:00
|
|
|
File.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
|
2018-05-30 09:01:35 -04:00
|
|
|
|
|
|
|
File.chmod(dir_mode, build_info_dir) if dir_mode
|
2012-12-22 19:35:09 -05:00
|
|
|
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
|