Skip to content

Commit

Permalink
Merge pull request #4459 from rubygems/fail_lockfiles_with_incorrect_…
Browse files Browse the repository at this point in the history
…resolutions

Warn lockfiles with incorrect resolutions

(cherry picked from commit 1140686)
  • Loading branch information
deivid-rodriguez committed Mar 18, 2021
1 parent 4d5b85a commit 206df19
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 8 deletions.
37 changes: 30 additions & 7 deletions bundler/lib/bundler/installer/parallel_installer.rb
Expand Up @@ -6,10 +6,11 @@
module Bundler
class ParallelInstaller
class SpecInstallation
attr_accessor :spec, :name, :post_install_message, :state, :error
attr_accessor :spec, :name, :full_name, :post_install_message, :state, :error
def initialize(spec)
@spec = spec
@name = spec.name
@full_name = spec.full_name
@state = :none
@post_install_message = ""
@error = nil
Expand Down Expand Up @@ -49,14 +50,11 @@ def dependencies_installed?(all_specs)
# Represents only the non-development dependencies, the ones that are
# itself and are in the total list.
def dependencies
@dependencies ||= begin
all_dependencies.reject {|dep| ignorable_dependency? dep }
end
@dependencies ||= all_dependencies.reject {|dep| ignorable_dependency? dep }
end

def missing_lockfile_dependencies(all_spec_names)
deps = all_dependencies.reject {|dep| ignorable_dependency? dep }
deps.reject {|dep| all_spec_names.include? dep.name }
dependencies.reject {|dep| all_spec_names.include? dep.name }
end

# Represents all dependencies
Expand All @@ -65,7 +63,7 @@ def all_dependencies
end

def to_s
"#<#{self.class} #{@spec.full_name} (#{state})>"
"#<#{self.class} #{full_name} (#{state})>"
end
end

Expand Down Expand Up @@ -99,12 +97,37 @@ def call
install_serially
end

check_for_unmet_dependencies

handle_error if failed_specs.any?
@specs
ensure
worker_pool && worker_pool.stop
end

def check_for_unmet_dependencies
unmet_dependencies = @specs.map do |s|
[
s,
s.dependencies.reject {|dep| @specs.any? {|spec| dep.matches_spec?(spec.spec) } },
]
end.reject {|a| a.last.empty? }
return if unmet_dependencies.empty?

warning = []
warning << "Your lockfile doesn't include a valid resolution."
warning << "You can fix this by regenerating your lockfile or trying to manually editing the bad locked gems to a version that satisfies all dependencies."
warning << "The unmet dependencies are:"

unmet_dependencies.each do |spec, unmet_spec_dependencies|
unmet_spec_dependencies.each do |unmet_spec_dependency|
warning << "* #{unmet_spec_dependency}, depended upon #{spec.full_name}, unsatisfied by #{@specs.find {|s| s.name == unmet_spec_dependency.name && !unmet_spec_dependency.matches_spec?(s.spec) }.full_name}"
end
end

Bundler.ui.warn(warning.join("\n"))
end

def check_for_corrupt_lockfile
missing_dependencies = @specs.map do |s|
[
Expand Down
33 changes: 33 additions & 0 deletions bundler/spec/bundler/installer/parallel_installer_spec.rb
Expand Up @@ -44,4 +44,37 @@
end
end
end

context "when the spec set is not a valid resolution" do
let(:all_specs) do
[
build_spec("cucumber", "4.1.0") {|s| s.runtime "diff-lcs", "< 1.4" },
build_spec("diff-lcs", "1.4.4"),
].flatten
end

it "prints a warning" do
expect(Bundler.ui).to receive(:warn).with(<<-W.strip)
Your lockfile doesn't include a valid resolution.
You can fix this by regenerating your lockfile or trying to manually editing the bad locked gems to a version that satisfies all dependencies.
The unmet dependencies are:
* diff-lcs (< 1.4), depended upon cucumber-4.1.0, unsatisfied by diff-lcs-1.4.4
W
subject.check_for_unmet_dependencies
end
end

context "when the spec set is a valid resolution" do
let(:all_specs) do
[
build_spec("cucumber", "4.1.0") {|s| s.runtime "diff-lcs", "< 1.4" },
build_spec("diff-lcs", "1.3"),
].flatten
end

it "doesn't print a warning" do
expect(Bundler.ui).not_to receive(:warn)
subject.check_for_unmet_dependencies
end
end
end
4 changes: 4 additions & 0 deletions bundler/spec/bundler/installer/spec_installation_spec.rb
Expand Up @@ -8,6 +8,10 @@
def a_spec.name
"I like tests"
end

def a_spec.full_name
"I really like tests"
end
a_spec
end

Expand Down
2 changes: 1 addition & 1 deletion dev_gems.rb.lock
Expand Up @@ -3,7 +3,7 @@ GEM
specs:
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.0)
ast (2.4.2)
aws-eventstream (1.1.0)
aws-partitions (1.411.0)
aws-sdk-core (3.110.0)
Expand Down

0 comments on commit 206df19

Please sign in to comment.