Merge pull request #12567 from electrofelix/improve-gem-resolving

Improve Gem spec selection when resolving
This commit is contained in:
Paul Hinze 2022-08-01 12:49:16 -05:00 committed by GitHub
commit 1b93691b8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -258,7 +258,12 @@ module Vagrant
if solution_file&.valid?
@logger.debug("loading cached solution set")
solution = solution_file.dependency_list.map do |dep|
spec = composed_set.find_all(dep).first
spec = composed_set.find_all(dep).select do |dep_spec|
next(true) unless Gem.loaded_specs.has_key?(dep_spec.name)
Gem.loaded_specs[dep_spec.name].version.eql?(dep_spec.version)
end.first
if !spec
@logger.warn("failed to locate specification for dependency - #{dep}")
@logger.warn("invalidating solution file - #{solution_file}")

View File

@ -644,6 +644,34 @@ describe Vagrant::Bundler do
expect(Gem.sources.sources.first.uri.to_s).to eq(described_class.const_get(:HASHICORP_GEMSTORE))
end
end
context "multiple specs" do
let(:solution_file) { double('solution_file') }
let(:vagrant_set) { double('vagrant_set') }
before do
allow(subject).to receive(:load_solution_file).and_return(solution_file)
allow(subject).to receive(:generate_vagrant_set).and_return(vagrant_set)
allow(solution_file).to receive(:valid?).and_return(true)
end
it "should activate spec of deps already loaded" do
spec = Gem.loaded_specs.first
deps = [spec[0]]
specs = [spec[1].dup, spec[1].dup]
specs[0].version = Gem::Version::new('0.0.1')
# make sure haven't accidentally modified both
expect(specs[0].version).to_not eq(specs[1].version)
expect(solution_file).to receive(:dependency_list).and_return(deps)
expect(vagrant_set).to receive(:find_all).and_return(specs)
expect(subject).to receive(:activate_solution) do |activate_specs|
expect(activate_specs.length()).to eq(1)
expect(activate_specs[0].full_spec()).to eq(specs[1])
end
subject.init!([])
end
end
end
describe "#install" do