1 From dc7156d8951242231cfd9142b3d5628815dc6589 Mon Sep 17 00:00:00 2001
2 From: Maximilian Bosch <maximilian@mbosch.me>
3 Date: Wed, 31 Mar 2021 14:30:01 +0200
4 Subject: [PATCH] Revert "Merge pull request #12225 from
5 chrisroberts/resolution-isolation"
7 This reverts commit 8a69d0c4dae035a4b1aa789bc4ec3db69c210df2, reversing
8 changes made to 5dd0a8c8acc36b654c13a5102e4327eedf1858f2.
12 Rationale: NixOS-specific patch. The changes in here break our current
13 implementation of declarative plugins (only `vagrant-libvirt` atm).
15 bin/vagrant | 28 +--------------
17 lib/vagrant/bundler.rb | 17 +++------
18 lib/vagrant/errors.rb | 12 -------
19 lib/vagrant/plugin/manager.rb | 22 ++----------
20 templates/locales/en.yml | 23 ++----------
21 test/unit/bin/vagrant_test.rb | 1 -
22 test/unit/vagrant/bundler_test.rb | 58 ++++++++++++++-----------------
23 8 files changed, 39 insertions(+), 124 deletions(-)
25 diff --git a/bin/vagrant b/bin/vagrant
26 index c019f30ff..ba7e40076 100755
29 @@ -23,9 +23,9 @@ if idx = argv.index("--")
30 argv = argv.slice(0, idx)
33 -require_relative "../lib/vagrant/version"
34 # Fast path the version of Vagrant
35 if argv.include?("-v") || argv.include?("--version")
36 + require_relative "../lib/vagrant/version"
37 puts "Vagrant #{Vagrant::VERSION}"
40 @@ -82,29 +82,6 @@ end
44 -# Before we start activate all our dependencies
45 -# so we can provide correct resolutions later
48 -vagrant_spec = Gem::Specification.find_all_by_name("vagrant").detect do |spec|
49 - spec.version == Gem::Version.new(Vagrant::VERSION)
52 -dep_activator = proc do |spec|
53 - spec.runtime_dependencies.each do |dep|
54 - gem(dep.name, *dep.requirement.as_list)
55 - dep_spec = Gem::Specification.find_all_by_name(dep.name).detect(&:activated?)
57 - builtin_specs << dep_spec
58 - dep_activator.call(dep_spec)
64 - dep_activator.call(vagrant_spec)
70 @@ -114,9 +91,6 @@ begin
71 require 'vagrant/util/platform'
72 require 'vagrant/util/experimental'
74 - # Set our list of builtin specs
75 - Vagrant::Bundler.instance.builtin_specs = builtin_specs
77 # Schedule the cleanup of things
78 at_exit(&Vagrant::Bundler.instance.method(:deinit))
80 diff --git a/lib/vagrant.rb b/lib/vagrant.rb
81 index f790039d3..97e67e3b8 100644
84 @@ -59,7 +59,7 @@ require "vagrant/plugin/manager"
85 # See https://github.com/rest-client/rest-client/issues/34#issuecomment-290858
86 # for more information
87 class VagrantLogger < Log4r::Logger
93 diff --git a/lib/vagrant/bundler.rb b/lib/vagrant/bundler.rb
94 index eb2caabb0..d75f54362 100644
95 --- a/lib/vagrant/bundler.rb
96 +++ b/lib/vagrant/bundler.rb
97 @@ -189,11 +189,8 @@ module Vagrant
98 attr_reader :env_plugin_gem_path
99 # @return [Pathname] Vagrant environment data path
100 attr_reader :environment_data_path
101 - # @return [Array<Gem::Specification>, nil] List of builtin specs
102 - attr_accessor :builtin_specs
105 - @builtin_specs = []
106 @plugin_gem_path = Vagrant.user_data_path.join("gems", RUBY_VERSION).freeze
107 @logger = Log4r::Logger.new("vagrant::bundler")
109 @@ -290,6 +287,7 @@ module Vagrant
110 # Never allow dependencies to be remotely satisfied during init
111 request_set.remote = false
113 + repair_result = nil
115 @logger.debug("resolving solution from available specification set")
116 # Resolve the request set to ensure proper activation order
117 @@ -652,6 +650,7 @@ module Vagrant
119 @logger.info("Activated vagrant specification version - #{self_spec.version}")
121 + self_spec.runtime_dependencies.each { |d| gem d.name, *d.requirement.as_list }
122 # discover all the gems we have available
124 if Gem.respond_to?(:default_specifications_dir)
125 @@ -660,16 +659,10 @@ module Vagrant
126 spec_dir = Gem::Specification.default_specifications_dir
128 directories = [spec_dir]
129 - if Vagrant.in_bundler?
130 - Gem::Specification.find_all{true}.each do |spec|
131 - list[spec.full_name] = spec
134 - builtin_specs.each do |spec|
135 - list[spec.full_name] = spec
137 + Gem::Specification.find_all{true}.each do |spec|
138 + list[spec.full_name] = spec
140 - if Vagrant.in_installer?
141 + if(!Object.const_defined?(:Bundler))
142 directories += Gem::Specification.dirs.find_all do |path|
143 !path.start_with?(Gem.user_dir)
145 diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb
146 index 5cb861c06..782615bc4 100644
147 --- a/lib/vagrant/errors.rb
148 +++ b/lib/vagrant/errors.rb
149 @@ -636,18 +636,6 @@ module Vagrant
150 error_key(:provisioner_winrm_unsupported)
153 - class PluginNeedsDeveloperTools < VagrantError
154 - error_key(:plugin_needs_developer_tools)
157 - class PluginMissingLibrary < VagrantError
158 - error_key(:plugin_missing_library)
161 - class PluginMissingRubyDev < VagrantError
162 - error_key(:plugin_missing_ruby_dev)
165 class PluginGemNotFound < VagrantError
166 error_key(:plugin_gem_not_found)
168 diff --git a/lib/vagrant/plugin/manager.rb b/lib/vagrant/plugin/manager.rb
169 index b73f07f9c..9058e68b3 100644
170 --- a/lib/vagrant/plugin/manager.rb
171 +++ b/lib/vagrant/plugin/manager.rb
172 @@ -179,26 +179,8 @@ module Vagrant
174 rescue Gem::GemNotFoundException
175 raise Errors::PluginGemNotFound, name: name
176 - rescue Gem::Exception => err
177 - @logger.warn("Failed to install plugin: #{err}")
178 - @logger.debug("#{err.class}: #{err}\n#{err.backtrace.join("\n")}")
179 - # Try and determine a cause for the failure
181 - when /install development tools first/
182 - raise Errors::PluginNeedsDeveloperTools
183 - when /library not found in default locations/
184 - lib = err.message.match(/(\w+) library not found in default locations/)
186 - raise Errors::BundlerError, message: err.message
188 - raise Errors::PluginMissingLibrary,
189 - library: lib.captures.first,
191 - when /find header files for ruby/
192 - raise Errors::PluginMissingRubyDev
194 - raise Errors::BundlerError, message: err.message
196 + rescue Gem::Exception => e
197 + raise Errors::BundlerError, message: e.to_s
200 # Uninstalls the plugin with the given name.
201 diff --git a/templates/locales/en.yml b/templates/locales/en.yml
202 index edae9b477..782904f49 100644
203 --- a/templates/locales/en.yml
204 +++ b/templates/locales/en.yml
205 @@ -794,9 +794,9 @@ en:
206 matching this provider. For example, if you're using VirtualBox,
207 the clone environment must also be using VirtualBox.
208 cloud_init_not_found: |-
209 - cloud-init is not found. Please ensure that cloud-init is installed and
210 + cloud-init is not found. Please ensure that cloud-init is installed and
211 available on path for guest '%{guest_name}'.
212 - cloud_init_command_failed: |-
213 + cloud_init_command_failed: |-
214 cloud init command '%{cmd}' failed on guest '%{guest_name}'.
215 command_deprecated: |-
216 The command 'vagrant %{name}' has been deprecated and is no longer functional
217 @@ -1245,30 +1245,6 @@ en:
220 vagrant plugin install --local
221 - plugin_needs_developer_tools: |-
222 - Vagrant failed to install the requested plugin because development tools
223 - are required for installation but are not currently installed on this
224 - machine. Please install development tools and then try this command
226 - plugin_missing_library: |-
227 - Vagrant failed to install the requested plugin because it depends
228 - on development files for a library which is not currently installed
229 - on this system. The following library is required by the '%{name}'
234 - If a package manager is used on this system, please install the development
235 - package for the library. The name of the package will be similar to:
237 - %{library}-dev or %{library}-devel
239 - After the library and development files have been installed, please
240 - run the command again.
241 - plugin_missing_ruby_dev: |-
242 - Vagrant failed to install the requested plugin because the Ruby header
243 - files could not be found. Install the ruby development package for your
244 - system and then run this command again.
245 powershell_not_found: |-
246 Failed to locate the powershell executable on the available PATH. Please
247 ensure powershell is installed and available on the local PATH, then
248 @@ -3015,7 +2998,7 @@ en:
251 no_destination: "File destination must be specified."
256 Autocomplete installed at paths:
257 diff --git a/test/unit/bin/vagrant_test.rb b/test/unit/bin/vagrant_test.rb
258 index dbbd52112..bc11309aa 100644
259 --- a/test/unit/bin/vagrant_test.rb
260 +++ b/test/unit/bin/vagrant_test.rb
261 @@ -30,7 +30,6 @@ describe "vagrant bin" do
262 allow(Kernel).to receive(:exit)
263 allow(Vagrant::Environment).to receive(:new).and_return(env)
264 allow(Vagrant).to receive(:in_installer?).and_return(true)
265 - allow(self).to receive(:require_relative)
268 after { expect(run_vagrant).to eq(exit_code) }
269 diff --git a/test/unit/vagrant/bundler_test.rb b/test/unit/vagrant/bundler_test.rb
270 index 69f425c66..00cedc021 100644
271 --- a/test/unit/vagrant/bundler_test.rb
272 +++ b/test/unit/vagrant/bundler_test.rb
273 @@ -778,46 +778,42 @@ describe Vagrant::Bundler do
277 - context "when bundler is not defined" do
278 - before { expect(Vagrant).to receive(:in_bundler?).and_return(false) }
279 + context "when run time dependencies are defined" do
280 + let(:vagrant_dep_specs) { [double("spec", name: "vagrant-dep", requirement: double("spec-req", as_list: []))] }
282 - context "when running inside the installer" do
283 - before { expect(Vagrant).to receive(:in_installer?).and_return(true) }
284 + it "should call #gem to activate the dependencies" do
285 + expect(subject).to receive(:gem).with("vagrant-dep", any_args)
286 + subject.send(:vagrant_internal_specs)
290 - it "should load gem specification directories" do
291 - expect(Gem::Specification).to receive(:dirs).and_return(spec_dirs)
292 - subject.send(:vagrant_internal_specs)
294 + context "when bundler is not defined" do
295 + before { expect(Object).to receive(:const_defined?).with(:Bundler).and_return(false) }
297 - context "when checking paths" do
298 - let(:spec_dirs) { [double("spec-dir", start_with?: in_user_dir)] }
299 - let(:in_user_dir) { true }
300 - let(:user_dir) { double("user-dir") }
301 + it "should load gem specification directories" do
302 + expect(Gem::Specification).to receive(:dirs).and_return(spec_dirs)
303 + subject.send(:vagrant_internal_specs)
306 - before { allow(Gem).to receive(:user_dir).and_return(user_dir) }
307 + context "when checking paths" do
308 + let(:spec_dirs) { [double("spec-dir", start_with?: in_user_dir)] }
309 + let(:in_user_dir) { true }
310 + let(:user_dir) { double("user-dir") }
312 - it "should check if path is within local user directory" do
313 - expect(spec_dirs.first).to receive(:start_with?).with(user_dir).and_return(false)
314 - subject.send(:vagrant_internal_specs)
317 - context "when path is not within user directory" do
318 - let(:in_user_dir) { false }
319 + before { allow(Gem).to receive(:user_dir).and_return(user_dir) }
321 - it "should use path when loading specs" do
322 - expect(Gem::Specification).to receive(:each_spec) { |arg| expect(arg).to include(spec_dirs.first) }
323 - subject.send(:vagrant_internal_specs)
326 + it "should check if path is within local user directory" do
327 + expect(spec_dirs.first).to receive(:start_with?).with(user_dir).and_return(false)
328 + subject.send(:vagrant_internal_specs)
332 - context "when running outside the installer" do
333 - before { expect(Vagrant).to receive(:in_installer?).and_return(false) }
334 + context "when path is not within user directory" do
335 + let(:in_user_dir) { false }
337 - it "should not load gem specification directories" do
338 - expect(Gem::Specification).not_to receive(:dirs)
339 - subject.send(:vagrant_internal_specs)
340 + it "should use path when loading specs" do
341 + expect(Gem::Specification).to receive(:each_spec) { |arg| expect(arg).to include(spec_dirs.first) }
342 + subject.send(:vagrant_internal_specs)