[rubygems/rubygems] Fix gem pristine
sometimes not resetting extensions
If `gem pristine foo` is run, and there's a default copy of foo, only executables for it are reset. However, that was causing other copies of `foo` to only reset executables, which is unexpected. We should not modify `options[:only_executables]`, but respect its value for every gem, and make sure special handling for default gems does not leak to other gems. https://github.com/rubygems/rubygems/commit/2c3039f1b0
This commit is contained in:
parent
6560083c39
commit
dba72134de
@ -137,11 +137,14 @@ extensions will be restored.
|
||||
specs.group_by(&:full_name_with_location).values.each do |grouped_specs|
|
||||
spec = grouped_specs.find {|s| !s.default_gem? } || grouped_specs.first
|
||||
|
||||
unless only_executables_or_plugins?
|
||||
only_executables = options[:only_executables]
|
||||
only_plugins = options[:only_plugins]
|
||||
|
||||
unless only_executables || only_plugins
|
||||
# Default gemspecs include changes provided by ruby-core installer that
|
||||
# can't currently be pristined (inclusion of compiled extension targets in
|
||||
# the file list). So stick to resetting executables if it's a default gem.
|
||||
options[:only_executables] = true if spec.default_gem?
|
||||
only_executables = true if spec.default_gem?
|
||||
end
|
||||
|
||||
if options.key? :skip
|
||||
@ -151,14 +154,14 @@ extensions will be restored.
|
||||
end
|
||||
end
|
||||
|
||||
unless spec.extensions.empty? || options[:extensions] || only_executables_or_plugins?
|
||||
unless spec.extensions.empty? || options[:extensions] || only_executables || only_plugins
|
||||
say "Skipped #{spec.full_name_with_location}, it needs to compile an extension"
|
||||
next
|
||||
end
|
||||
|
||||
gem = spec.cache_file
|
||||
|
||||
unless File.exist?(gem) || only_executables_or_plugins?
|
||||
unless File.exist?(gem) || only_executables || only_plugins
|
||||
require_relative "../remote_fetcher"
|
||||
|
||||
say "Cached gem for #{spec.full_name_with_location} not found, attempting to fetch..."
|
||||
@ -194,10 +197,10 @@ extensions will be restored.
|
||||
bin_dir: bin_dir,
|
||||
}
|
||||
|
||||
if options[:only_executables]
|
||||
if only_executables
|
||||
installer = Gem::Installer.for_spec(spec, installer_options)
|
||||
installer.generate_bin
|
||||
elsif options[:only_plugins]
|
||||
elsif only_plugins
|
||||
installer = Gem::Installer.for_spec(spec, installer_options)
|
||||
installer.generate_plugins
|
||||
else
|
||||
@ -208,10 +211,4 @@ extensions will be restored.
|
||||
say "Restored #{spec.full_name_with_location}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def only_executables_or_plugins?
|
||||
options[:only_executables] || options[:only_plugins]
|
||||
end
|
||||
end
|
||||
|
@ -659,6 +659,42 @@ class TestGemCommandsPristineCommand < Gem::TestCase
|
||||
refute_includes "ruby_executable_hooks", File.read(exe)
|
||||
end
|
||||
|
||||
def test_execute_default_gem_and_regular_gem
|
||||
a_default = new_default_spec("a", "1.2.0")
|
||||
|
||||
a = util_spec "a" do |s|
|
||||
s.extensions << "ext/a/extconf.rb"
|
||||
end
|
||||
|
||||
ext_path = File.join @tempdir, "ext", "a", "extconf.rb"
|
||||
write_file ext_path do |io|
|
||||
io.write <<-'RUBY'
|
||||
File.open "Makefile", "w" do |f|
|
||||
f.puts "clean:\n\techo cleaned\n"
|
||||
f.puts "all:\n\techo built\n"
|
||||
f.puts "install:\n\techo installed\n"
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
install_default_gems a_default
|
||||
install_gem a
|
||||
|
||||
# Remove the extension files for a
|
||||
FileUtils.rm_rf a.gem_build_complete_path
|
||||
|
||||
@cmd.options[:args] = %w[a]
|
||||
|
||||
use_ui @ui do
|
||||
@cmd.execute
|
||||
end
|
||||
|
||||
assert_includes @ui.output, "Restored #{a.full_name}"
|
||||
|
||||
# Check extension files for a were restored
|
||||
assert_path_exist a.gem_build_complete_path
|
||||
end
|
||||
|
||||
def test_execute_multi_platform
|
||||
a = util_spec "a" do |s|
|
||||
s.extensions << "ext/a/extconf.rb"
|
||||
|
Loading…
x
Reference in New Issue
Block a user