Skip to content

Commit e9ea032

Browse files
Merge pull request #8757 from rubygems/deivid-rodriguez/fix-gem-pristine-bug
Fix `gem pristine` not recompiling extensions sometimes
2 parents a80de66 + 2c3039f commit e9ea032

2 files changed

Lines changed: 54 additions & 21 deletions

File tree

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: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def test_execute_all
125125
@cmd.execute
126126
end
127127

128-
assert File.exist?(gem_bin)
129-
assert File.exist?(gem_stub)
128+
assert_path_exist gem_bin
129+
assert_path_exist gem_stub
130130

131131
out = @ui.output.split "\n"
132132

@@ -537,8 +537,8 @@ def test_execute_only_executables
537537
@cmd.execute
538538
end
539539

540-
assert File.exist? gem_exec
541-
refute File.exist? gem_lib
540+
assert_path_exist gem_exec
541+
assert_path_not_exist gem_lib
542542
end
543543

544544
def test_execute_only_plugins
@@ -572,9 +572,9 @@ def test_execute_only_plugins
572572
@cmd.execute
573573
end
574574

575-
refute File.exist? gem_exec
576-
assert File.exist? gem_plugin
577-
refute File.exist? gem_lib
575+
assert_path_not_exist gem_exec
576+
assert_path_exist gem_plugin
577+
assert_path_not_exist gem_lib
578578
end
579579

580580
def test_execute_bindir
@@ -606,8 +606,8 @@ def test_execute_bindir
606606
@cmd.execute
607607
end
608608

609-
refute File.exist? gem_exec
610-
assert File.exist? gem_bindir
609+
assert_path_not_exist gem_exec
610+
assert_path_exist gem_bindir
611611
end
612612

613613
def test_execute_unknown_gem_at_remote_source
@@ -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)