Skip to content

Commit dba7213

Browse files
deivid-rodriguezhsbt
authored andcommitted
[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. ruby/rubygems@2c3039f1b0
1 parent 6560083 commit dba7213

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

lib/rubygems/commands/pristine_command.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,14 @@ def execute
137137
specs.group_by(&:full_name_with_location).values.each do |grouped_specs|
138138
spec = grouped_specs.find {|s| !s.default_gem? } || grouped_specs.first
139139

140-
unless only_executables_or_plugins?
140+
only_executables = options[:only_executables]
141+
only_plugins = options[:only_plugins]
142+
143+
unless only_executables || only_plugins
141144
# Default gemspecs include changes provided by ruby-core installer that
142145
# can't currently be pristined (inclusion of compiled extension targets in
143146
# the file list). So stick to resetting executables if it's a default gem.
144-
options[:only_executables] = true if spec.default_gem?
147+
only_executables = true if spec.default_gem?
145148
end
146149

147150
if options.key? :skip
@@ -151,14 +154,14 @@ def execute
151154
end
152155
end
153156

154-
unless spec.extensions.empty? || options[:extensions] || only_executables_or_plugins?
157+
unless spec.extensions.empty? || options[:extensions] || only_executables || only_plugins
155158
say "Skipped #{spec.full_name_with_location}, it needs to compile an extension"
156159
next
157160
end
158161

159162
gem = spec.cache_file
160163

161-
unless File.exist?(gem) || only_executables_or_plugins?
164+
unless File.exist?(gem) || only_executables || only_plugins
162165
require_relative "../remote_fetcher"
163166

164167
say "Cached gem for #{spec.full_name_with_location} not found, attempting to fetch..."
@@ -194,10 +197,10 @@ def execute
194197
bin_dir: bin_dir,
195198
}
196199

197-
if options[:only_executables]
200+
if only_executables
198201
installer = Gem::Installer.for_spec(spec, installer_options)
199202
installer.generate_bin
200-
elsif options[:only_plugins]
203+
elsif only_plugins
201204
installer = Gem::Installer.for_spec(spec, installer_options)
202205
installer.generate_plugins
203206
else
@@ -208,10 +211,4 @@ def execute
208211
say "Restored #{spec.full_name_with_location}"
209212
end
210213
end
211-
212-
private
213-
214-
def only_executables_or_plugins?
215-
options[:only_executables] || options[:only_plugins]
216-
end
217214
end

test/rubygems/test_gem_commands_pristine_command.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,42 @@ def test_execute_default_gem
659659
refute_includes "ruby_executable_hooks", File.read(exe)
660660
end
661661

662+
def test_execute_default_gem_and_regular_gem
663+
a_default = new_default_spec("a", "1.2.0")
664+
665+
a = util_spec "a" do |s|
666+
s.extensions << "ext/a/extconf.rb"
667+
end
668+
669+
ext_path = File.join @tempdir, "ext", "a", "extconf.rb"
670+
write_file ext_path do |io|
671+
io.write <<-'RUBY'
672+
File.open "Makefile", "w" do |f|
673+
f.puts "clean:\n\techo cleaned\n"
674+
f.puts "all:\n\techo built\n"
675+
f.puts "install:\n\techo installed\n"
676+
end
677+
RUBY
678+
end
679+
680+
install_default_gems a_default
681+
install_gem a
682+
683+
# Remove the extension files for a
684+
FileUtils.rm_rf a.gem_build_complete_path
685+
686+
@cmd.options[:args] = %w[a]
687+
688+
use_ui @ui do
689+
@cmd.execute
690+
end
691+
692+
assert_includes @ui.output, "Restored #{a.full_name}"
693+
694+
# Check extension files for a were restored
695+
assert_path_exist a.gem_build_complete_path
696+
end
697+
662698
def test_execute_multi_platform
663699
a = util_spec "a" do |s|
664700
s.extensions << "ext/a/extconf.rb"

0 commit comments

Comments
 (0)