Skip to content

Commit

Permalink
[rubygems/rubygems] Added only missing extensions option into pristin…
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt authored and matzbot committed Mar 10, 2023
1 parent 86d38b4 commit 15739c6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/rubygems/commands/pristine_command.rb
Expand Up @@ -34,6 +34,12 @@ def initialize
options[:extensions] = value
end

add_option("--only-missing-extensions",
"Only restore gems with missing extensions") do |value, options|
options[:extensions_set] = true
options[:only_missing_extensions] = value
end

add_option("--only-executables",
"Only restore executables") do |value, options|
options[:only_executables] = value
Expand Down Expand Up @@ -107,6 +113,10 @@ def execute
Gem::Specification.select do |spec|
spec.extensions && !spec.extensions.empty?
end
elsif options[:only_missing_extensions]
Gem::Specification.select do |spec|
spec.missing_extensions?
end
else
get_all_gem_names.sort.map do |gem_name|
Gem::Specification.find_all_by_name(gem_name, options[:version]).reverse
Expand Down
48 changes: 48 additions & 0 deletions test/rubygems/test_gem_commands_pristine_command.rb
Expand Up @@ -202,6 +202,54 @@ def test_execute_extensions_explicit
assert_empty out, out.inspect
end

def test_execute_extensions_only_missing_extensions
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

b = util_spec "b" do |s|
s.extensions << "ext/b/extconf.rb"
end

ext_path = File.join @tempdir, "ext", "b", "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_gem a
install_gem b

# Remove the extension files for b
FileUtils.rm_rf b.gem_build_complete_path

@cmd.options[:only_missing_extensions] = true
@cmd.options[:args] = []

use_ui @ui do
@cmd.execute
end

refute_includes @ui.output, "Restored #{a.full_name}"
assert_includes @ui.output, "Restored #{b.full_name}"
end

def test_execute_no_extension
a = util_spec "a" do |s|
s.extensions << "ext/a/extconf.rb"
Expand Down

0 comments on commit 15739c6

Please sign in to comment.