[rubygems/rubygems] Fix binstubs sometimes not getting regenerated when --destdir
is given
This was only working for gems also installed in the default gem home. https://github.com/rubygems/rubygems/commit/47df02dbd9
This commit is contained in:
parent
35c5c7edb9
commit
c55c11d7d5
@ -57,7 +57,7 @@ class Gem::Commands::PristineCommand < Gem::Command
|
|||||||
end
|
end
|
||||||
|
|
||||||
add_option("-i", "--install-dir DIR",
|
add_option("-i", "--install-dir DIR",
|
||||||
"Gem repository to get binstubs and plugins installed") do |value, options|
|
"Gem repository to get gems restored") do |value, options|
|
||||||
options[:install_dir] = File.expand_path(value)
|
options[:install_dir] = File.expand_path(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -103,21 +103,25 @@ extensions will be restored.
|
|||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
|
install_dir = options[:install_dir]
|
||||||
|
|
||||||
|
specification_record = install_dir ? Gem::SpecificationRecord.from_path(install_dir) : Gem::Specification.specification_record
|
||||||
|
|
||||||
specs = if options[:all]
|
specs = if options[:all]
|
||||||
Gem::Specification.map
|
specification_record.map
|
||||||
|
|
||||||
# `--extensions` must be explicitly given to pristine only gems
|
# `--extensions` must be explicitly given to pristine only gems
|
||||||
# with extensions.
|
# with extensions.
|
||||||
elsif options[:extensions_set] &&
|
elsif options[:extensions_set] &&
|
||||||
options[:extensions] && options[:args].empty?
|
options[:extensions] && options[:args].empty?
|
||||||
Gem::Specification.select do |spec|
|
specification_record.select do |spec|
|
||||||
spec.extensions && !spec.extensions.empty?
|
spec.extensions && !spec.extensions.empty?
|
||||||
end
|
end
|
||||||
elsif options[:only_missing_extensions]
|
elsif options[:only_missing_extensions]
|
||||||
Gem::Specification.select(&:missing_extensions?)
|
specification_record.select(&:missing_extensions?)
|
||||||
else
|
else
|
||||||
get_all_gem_names.sort.map do |gem_name|
|
get_all_gem_names.sort.map do |gem_name|
|
||||||
Gem::Specification.find_all_by_name(gem_name, options[:version]).reverse
|
specification_record.find_all_by_name(gem_name, options[:version]).reverse
|
||||||
end.flatten
|
end.flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -176,7 +180,6 @@ extensions will be restored.
|
|||||||
end
|
end
|
||||||
|
|
||||||
bin_dir = options[:bin_dir] if options[:bin_dir]
|
bin_dir = options[:bin_dir] if options[:bin_dir]
|
||||||
install_dir = options[:install_dir] if options[:install_dir]
|
|
||||||
|
|
||||||
installer_options = {
|
installer_options = {
|
||||||
wrappers: true,
|
wrappers: true,
|
||||||
|
@ -585,6 +585,8 @@ abort "#{deprecation_message}"
|
|||||||
|
|
||||||
args = %w[--all --only-executables --silent]
|
args = %w[--all --only-executables --silent]
|
||||||
args << "--bindir=#{bindir}"
|
args << "--bindir=#{bindir}"
|
||||||
|
args << "--install-dir=#{default_dir}"
|
||||||
|
|
||||||
if options[:env_shebang]
|
if options[:env_shebang]
|
||||||
args << "--env-shebang"
|
args << "--env-shebang"
|
||||||
end
|
end
|
||||||
|
@ -344,7 +344,7 @@ class Gem::Installer
|
|||||||
|
|
||||||
say spec.post_install_message if options[:post_install_message] && !spec.post_install_message.nil?
|
say spec.post_install_message if options[:post_install_message] && !spec.post_install_message.nil?
|
||||||
|
|
||||||
Gem::Specification.add_spec(spec)
|
Gem::Specification.add_spec(spec) unless @install_dir
|
||||||
|
|
||||||
load_plugin
|
load_plugin
|
||||||
|
|
||||||
|
@ -925,31 +925,15 @@ class Gem::Specification < Gem::BasicSpecification
|
|||||||
# Enumerate every known spec. See ::dirs= and ::add_spec to set the list of
|
# Enumerate every known spec. See ::dirs= and ::add_spec to set the list of
|
||||||
# specs.
|
# specs.
|
||||||
|
|
||||||
def self.each
|
def self.each(&block)
|
||||||
return enum_for(:each) unless block_given?
|
specification_record.each(&block)
|
||||||
|
|
||||||
_all.each do |x|
|
|
||||||
yield x
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Returns every spec that matches +name+ and optional +requirements+.
|
# Returns every spec that matches +name+ and optional +requirements+.
|
||||||
|
|
||||||
def self.find_all_by_name(name, *requirements)
|
def self.find_all_by_name(name, *requirements)
|
||||||
req = Gem::Requirement.create(*requirements)
|
specification_record.find_all_by_name(name, *requirements)
|
||||||
env_req = Gem.env_requirement(name)
|
|
||||||
|
|
||||||
matches = stubs_for(name).find_all do |spec|
|
|
||||||
req.satisfied_by?(spec.version) && env_req.satisfied_by?(spec.version)
|
|
||||||
end.map(&:to_spec)
|
|
||||||
|
|
||||||
if name == "bundler" && !req.specific?
|
|
||||||
require_relative "bundler_version_finder"
|
|
||||||
Gem::BundlerVersionFinder.prioritize!(matches)
|
|
||||||
end
|
|
||||||
|
|
||||||
matches
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -111,6 +111,38 @@ module Gem
|
|||||||
all.map(&:full_name)
|
all.map(&:full_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
include Enumerable
|
||||||
|
|
||||||
|
##
|
||||||
|
# Enumerate every known spec.
|
||||||
|
|
||||||
|
def each
|
||||||
|
return enum_for(:each) unless block_given?
|
||||||
|
|
||||||
|
all.each do |x|
|
||||||
|
yield x
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Returns every spec in the record that matches +name+ and optional +requirements+.
|
||||||
|
|
||||||
|
def find_all_by_name(name, *requirements)
|
||||||
|
req = Gem::Requirement.create(*requirements)
|
||||||
|
env_req = Gem.env_requirement(name)
|
||||||
|
|
||||||
|
matches = stubs_for(name).find_all do |spec|
|
||||||
|
req.satisfied_by?(spec.version) && env_req.satisfied_by?(spec.version)
|
||||||
|
end.map(&:to_spec)
|
||||||
|
|
||||||
|
if name == "bundler" && !req.specific?
|
||||||
|
require_relative "bundler_version_finder"
|
||||||
|
Gem::BundlerVersionFinder.prioritize!(matches)
|
||||||
|
end
|
||||||
|
|
||||||
|
matches
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Return the best specification in the record that contains the file matching +path+.
|
# Return the best specification in the record that contains the file matching +path+.
|
||||||
|
|
||||||
|
@ -159,6 +159,23 @@ class TestGemCommandsSetupCommand < Gem::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_destdir_flag_regenerates_binstubs
|
||||||
|
# install to destdir
|
||||||
|
destdir = File.join(@tempdir, "foo")
|
||||||
|
gem_bin_path = gem_install "destdir-only-gem", install_dir: destdir
|
||||||
|
|
||||||
|
# change binstub manually
|
||||||
|
write_file gem_bin_path do |io|
|
||||||
|
io.puts "I changed it!"
|
||||||
|
end
|
||||||
|
|
||||||
|
@cmd.options[:destdir] = destdir
|
||||||
|
@cmd.options[:prefix] = "/"
|
||||||
|
@cmd.execute
|
||||||
|
|
||||||
|
assert_match(/\A#!/, File.read(gem_bin_path))
|
||||||
|
end
|
||||||
|
|
||||||
def test_files_in
|
def test_files_in
|
||||||
assert_equal %w[rubygems.rb rubygems/requirement.rb rubygems/ssl_certs/rubygems.org/foo.pem],
|
assert_equal %w[rubygems.rb rubygems/requirement.rb rubygems/ssl_certs/rubygems.org/foo.pem],
|
||||||
@cmd.files_in("lib").sort
|
@cmd.files_in("lib").sort
|
||||||
@ -412,7 +429,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def gem_install(name)
|
def gem_install(name, **options)
|
||||||
gem = util_spec name do |s|
|
gem = util_spec name do |s|
|
||||||
s.executables = [name]
|
s.executables = [name]
|
||||||
s.files = %W[bin/#{name}]
|
s.files = %W[bin/#{name}]
|
||||||
@ -420,8 +437,8 @@ class TestGemCommandsSetupCommand < Gem::TestCase
|
|||||||
write_file File.join @tempdir, "bin", name do |f|
|
write_file File.join @tempdir, "bin", name do |f|
|
||||||
f.puts "#!/usr/bin/ruby"
|
f.puts "#!/usr/bin/ruby"
|
||||||
end
|
end
|
||||||
install_gem gem
|
install_gem gem, **options
|
||||||
File.join @gemhome, "bin", name
|
File.join options[:install_dir] || @gemhome, "bin", name
|
||||||
end
|
end
|
||||||
|
|
||||||
def gem_install_with_plugin(name)
|
def gem_install_with_plugin(name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user