[rubygems/rubygems] Skip unresolved deps warning on Gem::Specification.reset on benign cases

If `Gem::Specification.reset` is used, but there are still unresolved
dependencies, RubyGems prints a warning. There are though, certain cases
where the situation will not cause any issues.

One such case is when the unresolved dependency does not restrict any
versions (>= 0) and there's a default gem matching it.

In this situation, it doesn't matter if Gem paths change, because
default gems are still activatable, so the dependency will be properly
activated if ever needed.

https://github.com/rubygems/rubygems/commit/e5f8a3068e
This commit is contained in:
David Rodríguez 2024-12-05 17:59:33 +01:00 committed by git
parent ba91ff5f78
commit 48443c0204
2 changed files with 41 additions and 12 deletions

View File

@ -1199,21 +1199,30 @@ class Gem::Specification < Gem::BasicSpecification
Gem.pre_reset_hooks.each(&:call)
@specification_record = nil
clear_load_cache
unresolved = unresolved_deps
unless unresolved.empty?
warn "WARN: Unresolved or ambiguous specs during Gem::Specification.reset:"
unresolved.values.each do |dep|
warn " #{dep}"
versions = find_all_by_name(dep.name).uniq(&:full_name)
unless versions.empty?
warn " Available/installed versions of this gem:"
versions.each {|s| warn " - #{s.version}" }
unless unresolved_deps.empty?
unresolved = unresolved_deps.filter_map do |name, dep|
matching_versions = find_all_by_name(name)
next if dep.latest_version? && matching_versions.any?(&:default_gem?)
[dep, matching_versions.uniq(&:full_name)]
end.to_h
unless unresolved.empty?
warn "WARN: Unresolved or ambiguous specs during Gem::Specification.reset:"
unresolved.each do |dep, versions|
warn " #{dep}"
unless versions.empty?
warn " Available/installed versions of this gem:"
versions.each {|s| warn " - #{s.version}" }
end
end
warn "WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>'"
warn "Please report a bug if this causes problems."
end
warn "WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>'"
warn "Please report a bug if this causes problems."
unresolved.clear
unresolved_deps.clear
end
Gem.post_reset_hooks.each(&:call)
end

View File

@ -3111,6 +3111,26 @@ Please report a bug if this causes problems.
assert_empty specification.unresolved_deps
end
def test_unresolved_specs_with_unrestricted_deps_on_default_gems
specification = Gem::Specification.clone
set_orig specification
spec = new_default_spec "stringio", "3.1.1"
specification.instance_variable_set(:@unresolved_deps, { stringio: Gem::Dependency.new("stringio", ">= 0") })
specification.define_singleton_method(:find_all_by_name) do |_dep_name|
[spec]
end
actual_stdout, actual_stderr = capture_output do
specification.reset
end
assert_empty actual_stdout
assert_empty actual_stderr
end
def test_duplicate_runtime_dependency
expected = "WARNING: duplicated b dependency [\"~> 3.0\", \"~> 3.0\"]\n"
out, err = capture_output do