Vagrant reinstalling all previously installed gems/plugins on each new plugin install

I originally posted this in the discussion group at https://groups.google.com/g/vagrant-up/c/bKFLtRN1jOc but didn’t get any answers.

Due to some issues with building native extensions for plugins that need to link between ruby libraries provided by the embedded ruby distributed with vagrant and system libraries, I’ve put together a docker image for vagrant-libvirt to try and help users on distros that run into this issue to have access to an alternative to hacking around with re-compiling various libraries.

As part of this, I was trying to provide a trimmed image except people noticed they were running into an issue when extending to install plugins that were pure ruby, and to the best of my knowledge shouldn’t have had an issue.

The root cause appears to be that vagrant re-installs all currently installed plugins on each subsequent install irrespective of whether the versions currently installed are sufficient for the resolved requirements.

Is this intentional or unexpected?

The reason I spotted this was, I was installing a plugin that I thought was pure ruby and yet I saw the lines about native extensions appearing in the output:

Building native extensions. This could take a while...
Building native extensions. This could take a while...

Digging deeper I noticed that all of the gems under the global config directory for the current vagrant install were getting updated timestamps even though all except the one I’d requested to install had already been present due to being dependencies of vagrant-libvirt

When I enable debug output I see a dependency list of gems for installation, a report on activating a solution set, followed by removal of activation request from install as already installed for specific gems, which appears to only include the gems bundled with vagrant, it doesn’t include any of the dependencies that appear under the user global ~/.vagrant.d/gems/<ruby-version>/gems/

Added a public gist containing the output vagrant plugin install debug output · GitHub

It looks like it goes through the process of detecting all of the dependencies, but only recognizing those bundled with the ruby install under /opt/vagrant/embedded/lib/ruby/2.6.0/ and /opt/vagrant/embedded/lib/ruby/gems/2.6.0/gems/, along with the ones needed by vagrant itself under /opt/vagrant/embedded/gems/2.2.13/gems/ as already installed, ignoring the any under ~/.vagrant.d/gems/2.6.6/gems/, which in my case are the following gems:

fog-core-2.2.3
fog-json-1.2.0
fog-libvirt-0.8.0
fog-xml-0.1.3
formatador-0.2.5
nokogiri-1.11.2-x86_64-linux
racc-1.5.2
ruby-libvirt-0.7.1
tzinfo-2.0.4
tzinfo-data-1.2021.1
vagrant-guests-clearlinux-1.2.4
vagrant-libvirt-0.4.0
vagrant-proxyconf-2.0.10
vagrant-winrm-syncedfolders-1.0.1

With the last 4 being the plugins installed, and the preceding ones being any dependencies.

Is there a reason for this behaviour or is it a bug that no one has noticed before because it hasn’t been impacting?