Skip to content

Commit 48443c0

Browse files
deivid-rodriguezmatzbot
authored andcommitted
[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. ruby/rubygems@e5f8a3068e
1 parent ba91ff5 commit 48443c0

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

lib/rubygems/specification.rb

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,21 +1199,30 @@ def self.reset
11991199
Gem.pre_reset_hooks.each(&:call)
12001200
@specification_record = nil
12011201
clear_load_cache
1202-
unresolved = unresolved_deps
1203-
unless unresolved.empty?
1204-
warn "WARN: Unresolved or ambiguous specs during Gem::Specification.reset:"
1205-
unresolved.values.each do |dep|
1206-
warn " #{dep}"
1207-
1208-
versions = find_all_by_name(dep.name).uniq(&:full_name)
1209-
unless versions.empty?
1210-
warn " Available/installed versions of this gem:"
1211-
versions.each {|s| warn " - #{s.version}" }
1202+
1203+
unless unresolved_deps.empty?
1204+
unresolved = unresolved_deps.filter_map do |name, dep|
1205+
matching_versions = find_all_by_name(name)
1206+
next if dep.latest_version? && matching_versions.any?(&:default_gem?)
1207+
1208+
[dep, matching_versions.uniq(&:full_name)]
1209+
end.to_h
1210+
1211+
unless unresolved.empty?
1212+
warn "WARN: Unresolved or ambiguous specs during Gem::Specification.reset:"
1213+
unresolved.each do |dep, versions|
1214+
warn " #{dep}"
1215+
1216+
unless versions.empty?
1217+
warn " Available/installed versions of this gem:"
1218+
versions.each {|s| warn " - #{s.version}" }
1219+
end
12121220
end
1221+
warn "WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>'"
1222+
warn "Please report a bug if this causes problems."
12131223
end
1214-
warn "WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>'"
1215-
warn "Please report a bug if this causes problems."
1216-
unresolved.clear
1224+
1225+
unresolved_deps.clear
12171226
end
12181227
Gem.post_reset_hooks.each(&:call)
12191228
end

test/rubygems/test_gem_specification.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,6 +3111,26 @@ def test_unresolved_specs_with_duplicated_versions
31113111
assert_empty specification.unresolved_deps
31123112
end
31133113

3114+
def test_unresolved_specs_with_unrestricted_deps_on_default_gems
3115+
specification = Gem::Specification.clone
3116+
3117+
set_orig specification
3118+
3119+
spec = new_default_spec "stringio", "3.1.1"
3120+
3121+
specification.instance_variable_set(:@unresolved_deps, { stringio: Gem::Dependency.new("stringio", ">= 0") })
3122+
3123+
specification.define_singleton_method(:find_all_by_name) do |_dep_name|
3124+
[spec]
3125+
end
3126+
3127+
actual_stdout, actual_stderr = capture_output do
3128+
specification.reset
3129+
end
3130+
assert_empty actual_stdout
3131+
assert_empty actual_stderr
3132+
end
3133+
31143134
def test_duplicate_runtime_dependency
31153135
expected = "WARNING: duplicated b dependency [\"~> 3.0\", \"~> 3.0\"]\n"
31163136
out, err = capture_output do

0 commit comments

Comments
 (0)