2016-02-01 15:43:26 +03:00
|
|
|
# frozen_string_literal: true
|
2023-03-17 12:36:42 +03:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
#--
|
|
|
|
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
|
|
|
# All rights reserved.
|
|
|
|
# See LICENSE.txt for permissions.
|
|
|
|
#++
|
|
|
|
|
2019-04-22 14:56:16 +03:00
|
|
|
require_relative "installer_uninstaller_utils"
|
|
|
|
require_relative "exceptions"
|
|
|
|
require_relative "deprecate"
|
|
|
|
require_relative "package"
|
|
|
|
require_relative "ext"
|
|
|
|
require_relative "user_interaction"
|
2007-11-10 10:48:56 +03:00
|
|
|
|
|
|
|
##
|
2012-11-29 10:52:18 +04:00
|
|
|
# The installer installs the files contained in the .gem into the Gem.home.
|
2007-11-10 10:48:56 +03: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-10 01:38:59 +04:00
|
|
|
#
|
2011-01-20 00:23:04 +03:00
|
|
|
# The installer invokes pre and post install hooks. Hooks can be added either
|
2009-06-10 01: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 14:13:50 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
class Gem::Installer
|
2018-05-18 04:39:13 +03:00
|
|
|
extend Gem::Deprecate
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
##
|
|
|
|
# Paths where env(1) might live. Some systems are broken and have it in
|
|
|
|
# /bin
|
|
|
|
|
2018-10-22 03:27:02 +03:00
|
|
|
ENV_PATHS = %w[/usr/bin/env /bin/env].freeze
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
##
|
2013-10-16 04:14:16 +04:00
|
|
|
# Deprecated in favor of Gem::Ext::BuildError
|
|
|
|
|
|
|
|
ExtensionBuildError = Gem::Ext::BuildError # :nodoc:
|
2007-11-10 10:48:56 +03:00
|
|
|
|
|
|
|
include Gem::UserInteraction
|
2007-12-20 11:39:12 +03:00
|
|
|
|
2020-02-01 05:14:04 +03:00
|
|
|
include Gem::InstallerUninstallerUtils
|
|
|
|
|
2008-09-25 14:13:50 +04:00
|
|
|
##
|
|
|
|
# The directory a gem's executables will be installed into
|
|
|
|
|
|
|
|
attr_reader :bin_dir
|
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
attr_reader :build_root # :nodoc:
|
|
|
|
|
2008-09-25 14:13:50 +04:00
|
|
|
##
|
|
|
|
# The gem repository the gem will be installed into
|
|
|
|
|
|
|
|
attr_reader :gem_home
|
|
|
|
|
2011-01-20 00:23:04 +03:00
|
|
|
##
|
|
|
|
# The options passed when the Gem::Installer was instantiated.
|
|
|
|
|
|
|
|
attr_reader :options
|
|
|
|
|
2019-06-19 15:39:39 +03:00
|
|
|
##
|
|
|
|
# The gem package instance.
|
|
|
|
|
|
|
|
attr_reader :package
|
|
|
|
|
2008-09-25 14:13:50 +04:00
|
|
|
@path_warning = false
|
|
|
|
|
2007-12-20 11:39:12 +03:00
|
|
|
class << self
|
2021-11-16 14:19:13 +03:00
|
|
|
#
|
|
|
|
# Changes in rubygems to lazily loading `rubygems/command` (in order to
|
|
|
|
# lazily load `optparse` as a side effect) affect bundler's custom installer
|
|
|
|
# which uses `Gem::Command` without requiring it (up until bundler 2.2.29).
|
|
|
|
# This hook is to compensate for that missing require.
|
|
|
|
#
|
|
|
|
# TODO: Remove when rubygems no longer supports running on bundler older
|
|
|
|
# than 2.2.29.
|
|
|
|
|
|
|
|
def inherited(klass)
|
|
|
|
if klass.name == "Bundler::RubyGemsGemInstaller"
|
|
|
|
require "rubygems/command"
|
|
|
|
end
|
|
|
|
|
|
|
|
super(klass)
|
|
|
|
end
|
|
|
|
|
2008-09-25 14:13:50 +04:00
|
|
|
##
|
|
|
|
# True if we've warned about PATH not including Gem.bindir
|
|
|
|
|
|
|
|
attr_accessor :path_warning
|
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
##
|
|
|
|
# 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 11:39:12 +03: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-02 00:50:14 +03:00
|
|
|
##
|
|
|
|
# Construct an installer object for the gem file located at +path+
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
def self.at(path, options = {})
|
2015-07-02 00:50:14 +03:00
|
|
|
security_policy = options[:security_policy]
|
|
|
|
package = Gem::Package.new path, security_policy
|
|
|
|
new package, options
|
|
|
|
end
|
|
|
|
|
|
|
|
class FakePackage
|
|
|
|
attr_accessor :spec
|
|
|
|
|
2018-05-30 16:01:35 +03:00
|
|
|
attr_accessor :dir_mode
|
|
|
|
attr_accessor :prog_mode
|
|
|
|
attr_accessor :data_mode
|
|
|
|
|
2015-07-02 00:50:14 +03:00
|
|
|
def initialize(spec)
|
|
|
|
@spec = spec
|
|
|
|
end
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
def extract_files(destination_dir, pattern = "*")
|
2015-07-02 00:50:14 +03: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 15:59:03 +03:00
|
|
|
File.open file, "w" do |fp|
|
|
|
|
fp.puts "# #{file}"
|
|
|
|
end
|
2015-07-02 00:50:14 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
def copy_to(path)
|
2015-07-02 00:50:14 +03:00
|
|
|
end
|
|
|
|
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 13:20:47 +03:00
|
|
|
def self.for_spec(spec, options = {})
|
2015-07-02 00:50:14 +03:00
|
|
|
# FIXME: we should have a real Package class for this
|
|
|
|
new FakePackage.new(spec), options
|
|
|
|
end
|
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
##
|
2017-10-08 04:32:18 +03: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 10:48:56 +03:00
|
|
|
#
|
2012-11-29 10:52:18 +04:00
|
|
|
# :bin_dir:: Where to put a bin wrapper if needed.
|
|
|
|
# :development:: Whether or not development dependencies should be installed.
|
2007-11-10 10:48:56 +03: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 12: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 11:39:12 +03:00
|
|
|
# foo_exec18.
|
2012-11-29 10:52:18 +04:00
|
|
|
# :ignore_dependencies:: Don't raise if a dependency is missing.
|
|
|
|
# :install_dir:: The directory to install the gem into.
|
2007-11-10 10:48:56 +03:00
|
|
|
# :security_policy:: Use the specified security policy. See Gem::Security
|
2012-11-29 10:52:18 +04: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 10:48:56 +03:00
|
|
|
# :wrappers:: Install wrappers if true, symlinks if false.
|
2012-11-29 10:52:18 +04: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-08 04:32:18 +03:00
|
|
|
# :post_install_message:: Print gem post install message if true
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2015-07-02 00:50:14 +03:00
|
|
|
def initialize(package, options={})
|
2011-01-19 03:08:49 +03:00
|
|
|
require "fileutils"
|
|
|
|
|
2011-01-20 00:23:04 +03:00
|
|
|
@options = options
|
2020-02-01 05:14:04 +03:00
|
|
|
@package = package
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2011-01-20 00:23:04 +03:00
|
|
|
process_options
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2018-05-30 16:01:35 +03:00
|
|
|
@package.dir_mode = options[:dir_mode]
|
|
|
|
@package.prog_mode = options[:prog_mode]
|
|
|
|
@package.data_mode = options[:data_mode]
|
|
|
|
|
2019-04-26 14:26:21 +03:00
|
|
|
if options[:user_install]
|
2008-09-25 14:13:50 +04:00
|
|
|
@gem_home = Gem.user_dir
|
2013-02-19 03:15:49 +04:00
|
|
|
@bin_dir = Gem.bindir gem_home unless options[:bin_dir]
|
2020-07-09 17:38:34 +03:00
|
|
|
@plugins_dir = Gem.plugindir(gem_home)
|
2011-01-20 00:23:04 +03:00
|
|
|
check_that_user_bin_dir_is_in_path
|
2008-06-26 06:06:00 +04:00
|
|
|
end
|
2011-06-01 07:45:05 +04:00
|
|
|
end
|
2008-06-26 06:06:00 +04:00
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
##
|
2012-11-29 10:52:18 +04:00
|
|
|
# Checks if +filename+ exists in +@bin_dir+.
|
|
|
|
#
|
|
|
|
# If +@force+ is set +filename+ is overwritten.
|
|
|
|
#
|
2019-10-03 00:46:40 +03:00
|
|
|
# If +filename+ exists and it is a RubyGems wrapper for a different gem, then
|
|
|
|
# the user is consulted.
|
2012-11-29 10:52:18 +04:00
|
|
|
#
|
|
|
|
# If +filename+ exists and +@bin_dir+ is Gem.default_bindir (/usr/local) the
|
|
|
|
# user is consulted.
|
|
|
|
#
|
|
|
|
# Otherwise +filename+ is overwritten.
|
2011-06-01 07:45:05 +04:00
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
def check_executable_overwrite(filename) # :nodoc:
|
2012-11-29 10:52:18 +04:00
|
|
|
return if @force
|
|
|
|
|
2013-02-28 03:20:57 +04:00
|
|
|
generated_bin = File.join @bin_dir, formatted_program_filename(filename)
|
2012-11-29 10:52:18 +04:00
|
|
|
|
|
|
|
return unless File.exist? generated_bin
|
|
|
|
|
|
|
|
ruby_executable = false
|
|
|
|
existing = nil
|
|
|
|
|
2018-02-06 05:58:35 +03:00
|
|
|
File.open generated_bin, "rb" do |io|
|
2019-10-21 20:26:51 +03:00
|
|
|
line = io.gets
|
|
|
|
shebang = /^#!.*ruby/
|
|
|
|
|
|
|
|
if load_relative_enabled?
|
|
|
|
until line.nil? || line =~ shebang do
|
|
|
|
line = io.gets
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
next unless line =~ shebang
|
|
|
|
|
2012-11-29 10:52:18 +04:00
|
|
|
io.gets # blankline
|
|
|
|
|
2023-03-16 07:36:06 +03:00
|
|
|
# TODO: detect a specially formatted comment instead of trying
|
2022-08-03 06:24:38 +03:00
|
|
|
# to find a string inside Ruby code.
|
|
|
|
next unless io.gets.to_s.include?("This file was generated by RubyGems")
|
2012-11-29 10:52:18 +04:00
|
|
|
|
|
|
|
ruby_executable = true
|
2016-02-01 15:43:26 +03:00
|
|
|
existing = io.read.slice(%r{
|
2017-05-01 14:40:46 +03:00
|
|
|
^\s*(
|
2016-02-01 15:43:26 +03:00
|
|
|
gem \s |
|
2016-03-28 05:26:39 +03:00
|
|
|
load \s Gem\.bin_path\( |
|
|
|
|
load \s Gem\.activate_bin_path\(
|
2016-02-01 15:43:26 +03:00
|
|
|
)
|
|
|
|
(['"])(.*?)(\2),
|
|
|
|
}x, 3)
|
2012-11-29 10:52:18 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
return if spec.name == existing
|
|
|
|
|
|
|
|
# somebody has written to RubyGems' directory, overwrite, too bad
|
2022-08-09 05:16:07 +03:00
|
|
|
return if Gem.default_bindir != @bin_dir && !ruby_executable
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2016-02-01 15:43:26 +03:00
|
|
|
question = "#{spec.name}'s executable \"#{filename}\" conflicts with ".dup
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
if ruby_executable
|
2016-04-06 09:01:14 +03:00
|
|
|
question << (existing || "an unknown executable")
|
2012-11-29 10:52:18 +04: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-06-01 07:45:05 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2012-11-29 10:52:18 +04:00
|
|
|
# Lazy accessor for the spec's gem directory.
|
2011-06-01 07:45:05 +04:00
|
|
|
|
2012-11-29 10:52:18 +04:00
|
|
|
def gem_dir
|
|
|
|
@gem_dir ||= File.join(gem_home, "gems", spec.full_name)
|
2011-06-01 07:45:05 +04:00
|
|
|
end
|
2010-02-22 05:52:35 +03:00
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
##
|
|
|
|
# Lazy accessor for the installer's spec.
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
def spec
|
2015-07-02 00:50:14 +03:00
|
|
|
@package.spec
|
2007-11-10 10:48:56 +03: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-18 02:04:18 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def install
|
2012-12-23 04:35:09 +04:00
|
|
|
pre_install_checks
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2012-11-29 10:52:18 +04:00
|
|
|
run_pre_install_hooks
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2016-09-28 03:57:53 +03:00
|
|
|
# Set loaded_from to ensure extension_dir is correct
|
2018-11-21 13:20:47 +03:00
|
|
|
if @options[:install_as_default]
|
2016-09-28 03:57:53 +03:00
|
|
|
spec.loaded_from = default_spec_file
|
|
|
|
else
|
|
|
|
spec.loaded_from = spec_file
|
|
|
|
end
|
|
|
|
|
2011-03-01 12:41:32 +03:00
|
|
|
# Completely remove any previous gem files
|
2012-12-23 04:35:09 +04:00
|
|
|
FileUtils.rm_rf gem_dir
|
2016-06-18 08:11:55 +03:00
|
|
|
FileUtils.rm_rf spec.extension_dir
|
2011-03-01 12:41:32 +03:00
|
|
|
|
2018-05-30 16:01:35 +03:00
|
|
|
dir_mode = options[:dir_mode]
|
2018-12-23 03:20:49 +03:00
|
|
|
FileUtils.mkdir_p gem_dir, :mode => dir_mode && 0755
|
2013-07-10 03:41:44 +04:00
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
if @options[:install_as_default]
|
2013-09-14 12:59:02 +04:00
|
|
|
extract_bin
|
|
|
|
write_default_spec
|
|
|
|
else
|
|
|
|
extract_files
|
2013-07-10 03:41:44 +04:00
|
|
|
|
2013-09-14 12:59:02 +04:00
|
|
|
build_extensions
|
|
|
|
write_build_info_file
|
|
|
|
run_post_build_hooks
|
2019-04-02 14:48:18 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
generate_bin
|
2020-02-01 05:14:04 +03:00
|
|
|
generate_plugins
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2019-04-02 14:48:18 +03:00
|
|
|
unless @options[:install_as_default]
|
2013-09-14 12:59:02 +04:00
|
|
|
write_spec
|
|
|
|
write_cache_file
|
|
|
|
end
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2018-05-30 16:01:35 +03:00
|
|
|
File.chmod(dir_mode, gem_dir) if dir_mode
|
|
|
|
|
2016-02-01 15:43:26 +03:00
|
|
|
say spec.post_install_message if options[:post_install_message] && !spec.post_install_message.nil?
|
2013-09-13 23:58:57 +04:00
|
|
|
|
2022-07-13 06:56:36 +03:00
|
|
|
Gem::Specification.add_spec(spec)
|
2008-09-25 14:13:50 +04:00
|
|
|
|
2012-11-29 10:52:18 +04:00
|
|
|
run_post_install_hooks
|
|
|
|
|
|
|
|
spec
|
|
|
|
|
2023-03-16 07:36:06 +03:00
|
|
|
# TODO: This rescue is in the wrong place. What is raising this exception?
|
2012-12-23 04:35:09 +04:00
|
|
|
# move this rescue to around the code that actually might raise it.
|
2012-11-29 10:52:18 +04: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|
|
2023-03-22 07:26:37 +03:00
|
|
|
next unless hook.call(self) == false
|
|
|
|
location = " at #{$1}" if hook.inspect =~ /[ @](.*:\d+)/
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2023-03-22 07:26:37 +03:00
|
|
|
message = "pre-install hook#{location} failed for #{spec.full_name}"
|
|
|
|
raise Gem::InstallError, message
|
2012-11-29 10:52:18 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_post_build_hooks # :nodoc:
|
|
|
|
Gem.post_build_hooks.each do |hook|
|
2023-03-22 07:26:37 +03:00
|
|
|
next unless hook.call(self) == false
|
|
|
|
FileUtils.rm_rf gem_dir
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2023-03-22 07:26:37 +03:00
|
|
|
location = " at #{$1}" if hook.inspect =~ /[ @](.*:\d+)/
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2023-03-22 07:26:37 +03:00
|
|
|
message = "post-build hook#{location} failed for #{spec.full_name}"
|
|
|
|
raise Gem::InstallError, message
|
2012-11-29 10:52:18 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_post_install_hooks # :nodoc:
|
2008-09-25 14:13:50 +04:00
|
|
|
Gem.post_install_hooks.each do |hook|
|
|
|
|
hook.call self
|
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
end
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2012-11-29 10:52:18 +04: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 13:05:04 +03:00
|
|
|
Gem::Util.glob_files_in_dir("*.gemspec", File.join(gem_home, "specifications")).each do |path|
|
2019-11-11 09:03:57 +03:00
|
|
|
spec = Gem::Specification.load path.tap(&Gem::UNTAINT)
|
2012-11-29 10:52:18 +04:00
|
|
|
specs << spec if spec
|
|
|
|
end
|
|
|
|
|
|
|
|
specs
|
2011-06-01 07:45:05 +04:00
|
|
|
end
|
2007-11-10 10:48:56 +03: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-18 02:04:18 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def ensure_dependency(spec, dependency)
|
2018-11-21 13:20:47 +03:00
|
|
|
unless installation_satisfies_dependency? dependency
|
2007-11-10 10:48:56 +03:00
|
|
|
raise Gem::InstallError, "#{spec.name} requires #{dependency}"
|
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2012-11-29 10:52:18 +04:00
|
|
|
# True if the gems in the system satisfy +dependency+.
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def installation_satisfies_dependency?(dependency)
|
2022-08-09 05:16:07 +03:00
|
|
|
return true if @options[:development] && dependency.type == :development
|
2020-06-10 20:46:05 +03:00
|
|
|
return true if installed_specs.detect {|s| dependency.matches_spec? s }
|
2012-11-29 10:52:18 +04:00
|
|
|
return false if @only_install_dir
|
2022-08-09 05:16:07 +03:00
|
|
|
!dependency.matching_specs.empty?
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Unpacks the gem into the given directory.
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def unpack(directory)
|
|
|
|
@gem_dir = directory
|
|
|
|
extract_files
|
|
|
|
end
|
2020-04-19 16:41:54 +03:00
|
|
|
rubygems_deprecate :unpack
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2012-11-29 10:52:18 +04:00
|
|
|
##
|
2015-11-24 04:00:15 +03:00
|
|
|
# The location of the spec file that is installed.
|
2012-11-29 10:52:18 +04:00
|
|
|
#
|
|
|
|
|
|
|
|
def spec_file
|
|
|
|
File.join gem_home, "specifications", "#{spec.full_name}.gemspec"
|
|
|
|
end
|
|
|
|
|
2013-09-14 12:59:02 +04:00
|
|
|
##
|
2015-11-24 04:00:15 +03:00
|
|
|
# The location of the default spec file for default gems.
|
2013-09-14 12:59:02 +04:00
|
|
|
#
|
|
|
|
|
|
|
|
def default_spec_file
|
2020-12-08 10:33:39 +03:00
|
|
|
File.join gem_home, "specifications", "default", "#{spec.full_name}.gemspec"
|
2013-09-14 12:59:02 +04:00
|
|
|
end
|
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
##
|
2008-12-23 02:11:11 +03:00
|
|
|
# Writes the .gemspec specification (in Ruby) to the gem home's
|
|
|
|
# specifications directory.
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def write_spec
|
2021-02-25 20:43:51 +03:00
|
|
|
spec.installed_by_version = Gem.rubygems_version
|
2013-10-20 04:31:12 +04:00
|
|
|
|
2021-02-25 20:43:51 +03:00
|
|
|
Gem.write_binary(spec_file, spec.to_ruby_for_cache)
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
2013-07-10 03:41:44 +04:00
|
|
|
|
2013-09-14 12:59:02 +04:00
|
|
|
##
|
|
|
|
# Writes the full .gemspec specification (in Ruby) to the gem home's
|
|
|
|
# specifications/default directory.
|
|
|
|
|
|
|
|
def write_default_spec
|
2021-02-25 20:43:51 +03:00
|
|
|
Gem.write_binary(default_spec_file, spec.to_ruby)
|
2013-09-14 12:59:02 +04:00
|
|
|
end
|
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
##
|
|
|
|
# Creates windows .bat files for easy running of commands
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2010-04-22 12:24:42 +04:00
|
|
|
def generate_windows_script(filename, bindir)
|
2018-11-21 13:20:47 +03:00
|
|
|
if Gem.win_platform?
|
2019-02-14 15:59:03 +03:00
|
|
|
script_name = formatted_program_filename(filename) + ".bat"
|
2007-12-20 11:39:12 +03:00
|
|
|
script_path = File.join bindir, File.basename(script_name)
|
|
|
|
File.open script_path, "w" do |file|
|
2007-11-10 10:48:56 +03:00
|
|
|
file.puts windows_stub_script(bindir, filename)
|
|
|
|
end
|
2007-12-20 11:39:12 +03:00
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
verbose script_path
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
def generate_bin # :nodoc:
|
2022-08-09 05:16:07 +03:00
|
|
|
return if spec.executables.nil? || spec.executables.empty?
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2020-03-24 09:39:24 +03:00
|
|
|
ensure_writable_dir @bin_dir
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
spec.executables.each do |filename|
|
2019-11-11 09:03:57 +03:00
|
|
|
filename.tap(&Gem::UNTAINT)
|
2012-11-29 10:52:18 +04:00
|
|
|
bin_path = File.join gem_dir, spec.bindir, filename
|
2022-08-02 11:27:42 +03:00
|
|
|
next unless File.exist? bin_path
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2014-12-07 03:53:01 +03:00
|
|
|
mode = File.stat(bin_path).mode
|
2018-05-30 16:01:35 +03:00
|
|
|
dir_mode = options[:prog_mode] || (mode | 0111)
|
2020-12-08 10:33:39 +03:00
|
|
|
|
|
|
|
unless dir_mode == mode
|
|
|
|
require "fileutils"
|
|
|
|
FileUtils.chmod dir_mode, bin_path
|
|
|
|
end
|
2011-06-01 07:45:05 +04:00
|
|
|
|
2012-11-29 10:52:18 +04:00
|
|
|
check_executable_overwrite filename
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
if @wrappers
|
2012-11-29 10:52:18 +04:00
|
|
|
generate_bin_script filename, @bin_dir
|
2007-11-10 10:48:56 +03:00
|
|
|
else
|
2012-11-29 10:52:18 +04:00
|
|
|
generate_bin_symlink filename, @bin_dir
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
2020-02-01 05:14:04 +03:00
|
|
|
end
|
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2020-02-01 05:14:04 +03:00
|
|
|
def generate_plugins # :nodoc:
|
2021-11-04 15:40:53 +03:00
|
|
|
latest = Gem::Specification.latest_spec_for(spec.name)
|
2020-02-01 05:14:04 +03:00
|
|
|
return if latest && latest.version > spec.version
|
|
|
|
|
2020-03-24 09:39:24 +03:00
|
|
|
ensure_writable_dir @plugins_dir
|
|
|
|
|
2020-02-01 05:14:04 +03:00
|
|
|
if spec.plugins.empty?
|
2020-03-24 09:39:24 +03:00
|
|
|
remove_plugins_for(spec, @plugins_dir)
|
2020-02-01 05:14:04 +03:00
|
|
|
else
|
2020-03-24 09:39:24 +03:00
|
|
|
regenerate_plugins_for(spec, @plugins_dir)
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
2023-03-06 07:01:54 +03:00
|
|
|
rescue ArgumentError => e
|
|
|
|
raise e, "#{latest.name} #{latest.version} #{spec.name} #{spec.version}: #{e.message}"
|
2007-11-10 10:48:56 +03:00
|
|
|
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
|
2023-01-23 06:27:53 +03:00
|
|
|
# https://blade.ruby-lang.org/ruby-talk/193379
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def generate_bin_script(filename, bindir)
|
2007-12-20 11:39:12 +03:00
|
|
|
bin_script_path = File.join bindir, formatted_program_filename(filename)
|
|
|
|
|
2020-12-08 10:33:39 +03:00
|
|
|
require "fileutils"
|
2011-01-19 03:08:49 +03:00
|
|
|
FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers
|
2007-12-20 11:39:12 +03:00
|
|
|
|
2018-12-23 03:20:49 +03:00
|
|
|
File.open bin_script_path, "wb", 0755 do |file|
|
2011-01-19 03:08:49 +03:00
|
|
|
file.print app_script_text(filename)
|
2018-05-30 16:01:35 +03:00
|
|
|
file.chmod(options[:prog_mode] || 0755)
|
2011-01-19 03:08:49 +03:00
|
|
|
end
|
2007-12-20 11:39:12 +03:00
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
verbose bin_script_path
|
2007-12-20 11:39:12 +03:00
|
|
|
|
2011-01-19 03:08:49 +03:00
|
|
|
generate_windows_script filename, bindir
|
2007-11-10 10:48:56 +03: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-18 02:04:18 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def generate_bin_symlink(filename, bindir)
|
2011-06-01 07:45:05 +04:00
|
|
|
src = File.join gem_dir, spec.bindir, filename
|
2007-12-20 11:39:12 +03:00
|
|
|
dst = File.join bindir, formatted_program_filename(filename)
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
if File.exist? dst
|
|
|
|
if File.symlink? dst
|
2007-11-10 10:48:56 +03:00
|
|
|
link = File.readlink(dst).split File::SEPARATOR
|
|
|
|
cur_version = Gem::Version.create(link[-3].sub(/^.*-/, ""))
|
2011-06-01 07:45:05 +04:00
|
|
|
return if spec.version < cur_version
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
File.unlink dst
|
|
|
|
end
|
|
|
|
|
2007-12-20 11:39:12 +03:00
|
|
|
FileUtils.symlink src, dst, :verbose => Gem.configuration.really_verbose
|
2016-04-28 03:33:08 +03:00
|
|
|
rescue NotImplementedError, SystemCallError
|
|
|
|
alert_warning "Unable to use symlinks, installing wrapper"
|
|
|
|
generate_bin_script filename, bindir
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Generates a #! line for +bin_file_name+'s wrapper copying arguments if
|
|
|
|
# necessary.
|
2012-11-29 10:52:18 +04: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-18 02:04:18 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def shebang(bin_file_name)
|
2012-11-29 10:52:18 +04:00
|
|
|
path = File.join gem_dir, spec.bindir, bin_file_name
|
2023-03-16 06:57:49 +03:00
|
|
|
first_line = File.open(path, "rb", &:gets) || ""
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2020-04-19 23:39:42 +03:00
|
|
|
if first_line.start_with?("#!")
|
2009-03-09 10:03:39 +03:00
|
|
|
# Preserve extra words on shebang line, like "-w". Thanks RPA.
|
2012-04-18 04:04:12 +04:00
|
|
|
shebang = first_line.sub(/\A\#!.*?ruby\S*((\s+\S+)+)/, "#!#{Gem.ruby}")
|
2009-03-15 06:01:39 +03:00
|
|
|
opts = $1
|
2009-03-09 10:03:39 +03:00
|
|
|
shebang.strip! # Avoid nasty ^M issues.
|
2009-03-15 06:01:39 +03:00
|
|
|
end
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2012-11-29 10:52:18 +04:00
|
|
|
if which = Gem.configuration[:custom_shebang]
|
|
|
|
# replace bin_file_name with "ruby" to avoid endless loops
|
2019-10-23 18:45:31 +03:00
|
|
|
which = which.gsub(/ #{bin_file_name}$/," #{ruby_install_name}")
|
2012-11-29 10:52:18 +04: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}"
|
2019-10-21 20:26:51 +03:00
|
|
|
elsif @env_shebang
|
2009-03-09 10:03:39 +03:00
|
|
|
# Create a plain shebang line.
|
2009-06-10 01:38:59 +04:00
|
|
|
@env_path ||= ENV_PATHS.find {|env_path| File.executable? env_path }
|
2019-10-21 20:26:51 +03:00
|
|
|
"#!#{@env_path} #{ruby_install_name}"
|
|
|
|
else
|
|
|
|
"#{bash_prolog_script}#!#{Gem.ruby}#{opts}"
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-23 04:35:09 +04:00
|
|
|
##
|
|
|
|
# Ensures the Gem::Specification written out for this gem is loadable upon
|
|
|
|
# installation.
|
|
|
|
|
|
|
|
def ensure_loadable_spec
|
|
|
|
ruby = spec.to_ruby_for_cache
|
2019-11-11 09:03:57 +03:00
|
|
|
ruby.tap(&Gem::UNTAINT)
|
2012-12-23 04:35:09 +04: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-14 07:30:02 +04:00
|
|
|
def ensure_dependencies_met # :nodoc:
|
2011-06-01 07:45:05 +04:00
|
|
|
deps = spec.runtime_dependencies
|
|
|
|
deps |= spec.development_dependencies if @development
|
2011-01-20 00:23:04 +03:00
|
|
|
|
|
|
|
deps.each do |dep_gem|
|
2011-06-01 07:45:05 +04:00
|
|
|
ensure_dependency spec, dep_gem
|
2011-01-20 00:23:04 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
def process_options # :nodoc:
|
2011-01-20 00:23:04 +03:00
|
|
|
@options = {
|
2022-09-07 08:13:04 +03:00
|
|
|
:bin_dir => nil,
|
|
|
|
:env_shebang => false,
|
|
|
|
:force => false,
|
2016-02-01 15:43:26 +03:00
|
|
|
:only_install_dir => false,
|
2020-12-08 10:33:39 +03:00
|
|
|
:post_install_message => true,
|
2011-02-01 06:11:34 +03:00
|
|
|
}.merge options
|
2011-01-20 00:23:04 +03:00
|
|
|
|
2011-02-01 06:11:34 +03:00
|
|
|
@env_shebang = options[:env_shebang]
|
|
|
|
@force = options[:force]
|
2013-09-14 12:59:02 +04:00
|
|
|
@install_dir = options[:install_dir]
|
|
|
|
@gem_home = options[:install_dir] || Gem.dir
|
2020-03-24 09:39:24 +03:00
|
|
|
@plugins_dir = Gem.plugindir(@gem_home)
|
2011-02-01 06:11:34 +03:00
|
|
|
@ignore_dependencies = options[:ignore_dependencies]
|
|
|
|
@format_executable = options[:format_executable]
|
|
|
|
@wrappers = options[:wrappers]
|
2012-11-29 10:52:18 +04: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-02-01 06:11:34 +03:00
|
|
|
@development = options[:development]
|
2014-09-14 07:30:02 +04:00
|
|
|
@build_root = options[:build_root]
|
2011-01-20 00:23:04 +03:00
|
|
|
|
2021-11-16 14:19:13 +03:00
|
|
|
@build_args = options[:build_args]
|
2014-09-14 07:30:02 +04:00
|
|
|
|
|
|
|
unless @build_root.nil?
|
2020-12-08 10:33:39 +03:00
|
|
|
@bin_dir = File.join(@build_root, @bin_dir.gsub(/^[a-zA-Z]:/, ""))
|
|
|
|
@gem_home = File.join(@build_root, @gem_home.gsub(/^[a-zA-Z]:/, ""))
|
|
|
|
@plugins_dir = File.join(@build_root, @plugins_dir.gsub(/^[a-zA-Z]:/, ""))
|
|
|
|
alert_warning "You build with buildroot.\n Build root: #{@build_root}\n Bin dir: #{@bin_dir}\n Gem home: #{@gem_home}\n Plugins dir: #{@plugins_dir}"
|
2014-09-14 07:30:02 +04:00
|
|
|
end
|
2011-01-20 00:23:04 +03:00
|
|
|
end
|
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
def check_that_user_bin_dir_is_in_path # :nodoc:
|
2020-05-02 13:22:42 +03:00
|
|
|
return if self.class.path_warning
|
|
|
|
|
2011-07-27 05:40:07 +04:00
|
|
|
user_bin_dir = @bin_dir || Gem.bindir(gem_home)
|
2020-07-14 14:40:27 +03:00
|
|
|
user_bin_dir = user_bin_dir.tr(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
2013-02-20 02:51:38 +04:00
|
|
|
|
2012-09-28 12:29:21 +04:00
|
|
|
path = ENV["PATH"]
|
2020-07-14 14:16:34 +03:00
|
|
|
path = path.tr(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
if Gem.win_platform?
|
2012-09-28 12:29:21 +04:00
|
|
|
path = path.downcase
|
|
|
|
user_bin_dir = user_bin_dir.downcase
|
|
|
|
end
|
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
path = path.split(File::PATH_SEPARATOR)
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
unless path.include? user_bin_dir
|
2014-09-14 07:30:02 +04:00
|
|
|
unless !Gem.win_platform? && (path.include? user_bin_dir.sub(ENV["HOME"], "~"))
|
2020-05-02 13:22:42 +03: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
|
2011-01-20 00:23:04 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-26 14:26:21 +03:00
|
|
|
def verify_gem_home # :nodoc:
|
2018-12-23 03:20:49 +03:00
|
|
|
FileUtils.mkdir_p gem_home, :mode => options[:dir_mode] && 0755
|
2019-04-26 14:26:21 +03:00
|
|
|
raise Gem::FilePermissionError, gem_home unless File.writable?(gem_home)
|
2011-01-20 00:23:04 +03:00
|
|
|
end
|
|
|
|
|
2019-03-05 06:32:58 +03:00
|
|
|
def verify_spec
|
|
|
|
unless spec.name =~ Gem::Specification::VALID_NAME_PATTERN
|
|
|
|
raise Gem::InstallError, "#{spec} has an invalid name"
|
|
|
|
end
|
|
|
|
|
2022-05-20 11:15:15 +03:00
|
|
|
if spec.raw_require_paths.any? {|path| path =~ /\R/ }
|
2019-03-05 06:32:58 +03:00
|
|
|
raise Gem::InstallError, "#{spec} has an invalid require_paths"
|
|
|
|
end
|
|
|
|
|
2022-05-20 11:15:15 +03:00
|
|
|
if spec.extensions.any? {|ext| ext =~ /\R/ }
|
2019-03-05 06:32:58 +03:00
|
|
|
raise Gem::InstallError, "#{spec} has an invalid extensions"
|
|
|
|
end
|
|
|
|
|
2021-05-28 13:47:49 +03:00
|
|
|
if spec.platform.to_s =~ /\R/
|
|
|
|
raise Gem::InstallError, "#{spec.platform} is an invalid platform"
|
|
|
|
end
|
|
|
|
|
2019-03-05 06:32:58 +03:00
|
|
|
unless spec.specification_version.to_s =~ /\A\d+\z/
|
|
|
|
raise Gem::InstallError, "#{spec} has an invalid specification_version"
|
|
|
|
end
|
|
|
|
|
2019-09-25 15:34:55 +03:00
|
|
|
if spec.dependencies.any? {|dep| dep.type != :runtime && dep.type != :development }
|
|
|
|
raise Gem::InstallError, "#{spec} has an invalid dependencies"
|
|
|
|
end
|
|
|
|
|
|
|
|
if spec.dependencies.any? {|dep| dep.name =~ /(?:\R|[<>])/ }
|
2019-03-05 06:32:58 +03:00
|
|
|
raise Gem::InstallError, "#{spec} has an invalid dependencies"
|
|
|
|
end
|
2017-08-28 11:31:28 +03:00
|
|
|
end
|
|
|
|
|
2008-06-18 02:04:18 +04:00
|
|
|
##
|
2007-11-10 10:48:56 +03:00
|
|
|
# Return the text for an application file.
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def app_script_text(bin_file_name)
|
2023-03-16 07:36:06 +03:00
|
|
|
# NOTE: that the `load` lines cannot be indented, as old RG versions match
|
2017-05-01 14:40:46 +03:00
|
|
|
# against the beginning of the line
|
2023-03-23 04:16:17 +03:00
|
|
|
<<-TEXT
|
2007-11-10 10:48:56 +03:00
|
|
|
#{shebang bin_file_name}
|
|
|
|
#
|
|
|
|
# This file was generated by RubyGems.
|
|
|
|
#
|
2011-06-01 07:45:05 +04:00
|
|
|
# The application '#{spec.name}' is installed as part of a gem, and
|
2007-11-10 10:48:56 +03:00
|
|
|
# this file is here to facilitate running it.
|
|
|
|
#
|
|
|
|
|
|
|
|
require 'rubygems'
|
2019-10-29 18:57:16 +03:00
|
|
|
#{gemdeps_load(spec.name)}
|
2019-09-24 18:35:00 +03:00
|
|
|
version = "#{Gem::Requirement.default_prerelease}"
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2018-11-28 06:08:14 +03:00
|
|
|
str = ARGV.first
|
|
|
|
if str
|
|
|
|
str = str.b[/\\A_(.*)_\\z/, 1]
|
|
|
|
if str and Gem::Version.correct?(str)
|
2021-12-12 22:43:09 +03:00
|
|
|
#{explicit_version_requirement(spec.name)}
|
2012-04-18 04:04:12 +04:00
|
|
|
ARGV.shift
|
|
|
|
end
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
2017-05-01 14:40:46 +03:00
|
|
|
if Gem.respond_to?(:activate_bin_path)
|
2016-03-28 05:26:39 +03:00
|
|
|
load Gem.activate_bin_path('#{spec.name}', '#{bin_file_name}', version)
|
2017-05-01 14:40:46 +03:00
|
|
|
else
|
|
|
|
gem #{spec.name.dump}, version
|
|
|
|
load Gem.bin_path(#{spec.name.dump}, #{bin_file_name.dump}, version)
|
|
|
|
end
|
2007-11-10 10:48:56 +03:00
|
|
|
TEXT
|
|
|
|
end
|
|
|
|
|
2019-10-29 18:57:16 +03:00
|
|
|
def gemdeps_load(name)
|
|
|
|
return "" if name == "bundler"
|
|
|
|
|
|
|
|
<<-TEXT
|
|
|
|
|
|
|
|
Gem.use_gemdeps
|
|
|
|
TEXT
|
|
|
|
end
|
|
|
|
|
2021-12-12 22:43:09 +03:00
|
|
|
def explicit_version_requirement(name)
|
|
|
|
code = "version = str"
|
|
|
|
return code unless name == "bundler"
|
|
|
|
|
|
|
|
code += <<-TEXT
|
|
|
|
|
|
|
|
ENV['BUNDLER_VERSION'] = str
|
|
|
|
TEXT
|
|
|
|
end
|
|
|
|
|
2008-06-18 02:04:18 +04:00
|
|
|
##
|
2013-09-14 12:59:02 +04:00
|
|
|
# return the stub script text used to launch the true Ruby script
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def windows_stub_script(bindir, bin_file_name)
|
2018-10-31 06:23:30 +03:00
|
|
|
rb_topdir = RbConfig::TOPDIR || File.dirname(rb_config["bindir"])
|
|
|
|
|
|
|
|
# get ruby executable file name from RbConfig
|
2023-03-16 07:00:54 +03:00
|
|
|
ruby_exe = "#{rb_config["RUBY_INSTALL_NAME"]}#{rb_config["EXEEXT"]}"
|
2018-10-31 06:23:30 +03:00
|
|
|
ruby_exe = "ruby.exe" if ruby_exe.empty?
|
|
|
|
|
2023-03-16 07:08:18 +03:00
|
|
|
if File.exist?(File.join(bindir, ruby_exe))
|
2020-02-01 05:14:04 +03:00
|
|
|
# stub & ruby.exe within same folder. Portable
|
2018-08-27 13:05:04 +03:00
|
|
|
<<-TEXT
|
2007-11-10 10:48:56 +03:00
|
|
|
@ECHO OFF
|
2019-08-15 19:43:50 +03:00
|
|
|
@"%~dp0#{ruby_exe}" "%~dpn0" %*
|
2018-08-27 13:05:04 +03:00
|
|
|
TEXT
|
2018-10-31 06:23:30 +03:00
|
|
|
elsif bindir.downcase.start_with? rb_topdir.downcase
|
|
|
|
# stub within ruby folder, but not standard bin. Portable
|
2018-08-27 13:05:04 +03:00
|
|
|
require "pathname"
|
|
|
|
from = Pathname.new bindir
|
2018-10-31 06:23:30 +03:00
|
|
|
to = Pathname.new "#{rb_topdir}/bin"
|
2018-08-27 13:05:04 +03:00
|
|
|
rel = to.relative_path_from from
|
|
|
|
<<-TEXT
|
|
|
|
@ECHO OFF
|
2019-08-15 19:43:50 +03:00
|
|
|
@"%~dp0#{rel}/#{ruby_exe}" "%~dpn0" %*
|
2018-08-27 13:05:04 +03:00
|
|
|
TEXT
|
|
|
|
else
|
2018-10-31 06:23:30 +03:00
|
|
|
# outside ruby folder, maybe -user-install or bundler. Portable, but ruby
|
|
|
|
# is dependent on PATH
|
2018-08-27 13:05:04 +03:00
|
|
|
<<-TEXT
|
|
|
|
@ECHO OFF
|
2019-08-15 19:43:50 +03:00
|
|
|
@#{ruby_exe} "%~dpn0" %*
|
2018-08-27 13:05:04 +03:00
|
|
|
TEXT
|
|
|
|
end
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
2008-06-18 02:04:18 +04:00
|
|
|
##
|
2007-11-10 10:48:56 +03:00
|
|
|
# Builds extensions. Valid types of extensions are extconf.rb files,
|
|
|
|
# configure scripts and rakefiles or mkrf_conf files.
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def build_extensions
|
2021-11-16 14:19:13 +03:00
|
|
|
builder = Gem::Ext::Builder.new spec, build_args
|
2012-11-29 10:52:18 +04:00
|
|
|
|
2013-09-14 12:59:02 +04:00
|
|
|
builder.build_extensions
|
2012-11-29 10:52:18 +04:00
|
|
|
end
|
2007-11-10 10:48:56 +03: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-18 02:04:18 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def extract_files
|
2012-11-29 10:52:18 +04:00
|
|
|
@package.extract_files gem_dir
|
2007-12-20 11:39:12 +03:00
|
|
|
end
|
2013-07-10 03:41:44 +04:00
|
|
|
|
2013-09-14 12: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-05 06:32:58 +03:00
|
|
|
@package.extract_files gem_dir, "#{spec.bindir}/*"
|
2013-09-14 12:59:02 +04:00
|
|
|
end
|
|
|
|
|
2008-06-18 02:04:18 +04:00
|
|
|
##
|
2007-12-20 11:39:12 +03:00
|
|
|
# Prefix and suffix the program filename the same as ruby.
|
2008-06-18 02:04:18 +04:00
|
|
|
|
2007-12-20 11:39:12 +03:00
|
|
|
def formatted_program_filename(filename)
|
2018-11-21 13:20:47 +03:00
|
|
|
if @format_executable
|
2007-12-20 11:39:12 +03:00
|
|
|
self.class.exec_format % File.basename(filename)
|
|
|
|
else
|
|
|
|
filename
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-01 07: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-23 04:35:09 +04:00
|
|
|
|
2020-03-24 09:39:24 +03:00
|
|
|
##
|
|
|
|
# Filename of the gem being installed.
|
|
|
|
|
|
|
|
def gem
|
|
|
|
@package.gem.path
|
|
|
|
end
|
|
|
|
|
2012-12-23 04:35:09 +04:00
|
|
|
##
|
|
|
|
# Performs various checks before installing the gem such as the install
|
2013-09-14 12:59:02 +04:00
|
|
|
# repository is writable and its directories exist, required Ruby and
|
2012-12-23 04:35:09 +04:00
|
|
|
# rubygems versions are met and that dependencies are installed.
|
|
|
|
#
|
|
|
|
# Version and dependency checks are skipped if this install is forced.
|
|
|
|
#
|
2017-10-08 04:32:18 +03:00
|
|
|
# The dependent check will be skipped if the install is ignoring dependencies.
|
2012-12-23 04:35:09 +04:00
|
|
|
|
|
|
|
def pre_install_checks
|
2019-04-26 14:26:21 +03:00
|
|
|
verify_gem_home
|
2012-12-23 04:35:09 +04:00
|
|
|
|
2019-03-05 06:32:58 +03: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-23 04:35:09 +04:00
|
|
|
|
2019-03-05 06:32:58 +03:00
|
|
|
ensure_loadable_spec
|
2017-08-28 11:31:28 +03:00
|
|
|
|
2013-09-14 12: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-23 04:35:09 +04:00
|
|
|
|
|
|
|
return true if @force
|
|
|
|
|
|
|
|
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
|
2021-11-16 14:19:13 +03:00
|
|
|
return if build_args.empty?
|
2012-12-23 04:35:09 +04:00
|
|
|
|
2013-07-09 02:41:03 +04:00
|
|
|
build_info_dir = File.join gem_home, "build_info"
|
|
|
|
|
2018-05-30 16:01:35 +03:00
|
|
|
dir_mode = options[:dir_mode]
|
2018-12-23 03:20:49 +03:00
|
|
|
FileUtils.mkdir_p build_info_dir, :mode => dir_mode && 0755
|
2013-07-09 02:41:03 +04:00
|
|
|
|
|
|
|
build_info_file = File.join build_info_dir, "#{spec.full_name}.info"
|
|
|
|
|
2018-02-06 05:58:35 +03:00
|
|
|
File.open build_info_file, "w" do |io|
|
2021-11-16 14:19:13 +03:00
|
|
|
build_args.each do |arg|
|
2012-12-23 04:35:09 +04:00
|
|
|
io.puts arg
|
|
|
|
end
|
|
|
|
end
|
2018-05-30 16:01:35 +03:00
|
|
|
|
|
|
|
File.chmod(dir_mode, build_info_dir) if dir_mode
|
2012-12-23 04:35:09 +04: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-02 00:50:14 +03:00
|
|
|
@package.copy_to cache_file
|
2012-12-23 04:35:09 +04:00
|
|
|
end
|
|
|
|
|
2020-03-24 09:39:24 +03:00
|
|
|
def ensure_writable_dir(dir) # :nodoc:
|
|
|
|
begin
|
|
|
|
Dir.mkdir dir, *[options[:dir_mode] && 0755].compact
|
|
|
|
rescue SystemCallError
|
|
|
|
raise unless File.directory? dir
|
|
|
|
end
|
|
|
|
|
|
|
|
raise Gem::FilePermissionError.new(dir) unless File.writable? dir
|
|
|
|
end
|
2021-11-16 14:19:13 +03:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def build_args
|
|
|
|
@build_args ||= begin
|
|
|
|
require_relative "command"
|
|
|
|
Gem::Command.build_args
|
|
|
|
end
|
|
|
|
end
|
2019-10-23 18:45:31 +03:00
|
|
|
|
|
|
|
def rb_config
|
|
|
|
RbConfig::CONFIG
|
|
|
|
end
|
|
|
|
|
|
|
|
def ruby_install_name
|
|
|
|
rb_config["ruby_install_name"]
|
|
|
|
end
|
2019-10-21 20:26:51 +03:00
|
|
|
|
|
|
|
def load_relative_enabled?
|
|
|
|
rb_config["LIBRUBY_RELATIVE"] == "yes"
|
|
|
|
end
|
|
|
|
|
|
|
|
def bash_prolog_script
|
|
|
|
if load_relative_enabled?
|
|
|
|
script = +<<~EOS
|
|
|
|
bindir="${0%/*}"
|
|
|
|
EOS
|
|
|
|
|
2023-03-16 08:01:16 +03:00
|
|
|
script << %(exec "$bindir/#{ruby_install_name}" "-x" "$0" "$@"\n)
|
2019-10-21 20:26:51 +03:00
|
|
|
|
|
|
|
<<~EOS
|
|
|
|
#!/bin/sh
|
|
|
|
# -*- ruby -*-
|
|
|
|
_=_\\
|
|
|
|
=begin
|
|
|
|
#{script.chomp}
|
|
|
|
=end
|
|
|
|
EOS
|
|
|
|
else
|
|
|
|
""
|
|
|
|
end
|
|
|
|
end
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|