hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.21k stars 4.43k forks source link

Failing to install plugin on Windows with Vagrant 2.4.0 #13322

Closed GSDragoon closed 8 months ago

GSDragoon commented 9 months ago

Installing some plugins with Vagrant 2.4.0 on Windows fails. I only use the vsphere plugin, so I'm not sure how many others are impacted. I'm also not sure if this is plugin specific issue or some other dependency. I'm starting with reporting the bug here and seeing what I get. This works with Vagrant 2.3.7 and earlier.

vagrant plugin install vagrant-vsphere

Debug output

https://gist.github.com/GSDragoon/24da7c178d844891964c74a41b17c471

Expected behavior

The plugin should successfully install without errors.

Actual behavior

Installing the 'vagrant-vsphere' plugin. This can take a few minutes...
Fetching optimist-3.1.0.gem
Fetching mini_portile2-2.8.5.gem
Fetching nokogiri-1.13.4.gem
Building native extensions. This could take a while...
Vagrant failed to properly resolve required dependencies. These
errors can commonly be caused by misconfigured plugin installations
or transient network issues. The reported error is:

ERROR: Failed to build gem native extension.

    current directory: C:/Users/gseaton/.vagrant.d/gems/3.1.3/gems/nokogiri-1.13.4/ext/nokogiri
C:/Program\ Files/Vagrant/embedded/mingw64/bin/ruby.exe -I C:/Program\ Files/Vagrant/embedded/mingw64/lib/ruby/3.1.0 extconf.rb
checking for whether -IC:\Program is accepted as CFLAGS... yes
checking for whether Files\Vagrant\embedded\mingw64\x86_64-w64-mingw32\include is accepted as CFLAGS... no
checking for whether -IC:\Program is accepted as CFLAGS... yes
checking for whether Files\Vagrant\embedded\mingw64\include is accepted as CFLAGS... no
checking for whether -IC:\Program is accepted as CFLAGS... yes
checking for whether Files\Vagrant\embedded\usr\include is accepted as CFLAGS... no
checking for whether -IC:\Program is accepted as CPPFLAGS... yes
checking for whether Files\Vagrant\embedded\mingw64\x86_64-w64-mingw32\include is accepted as CPPFLAGS... no
checking for whether -IC:\Program is accepted as CPPFLAGS... yes
checking for whether Files\Vagrant\embedded\mingw64\include is accepted as CPPFLAGS... no
checking for whether -IC:\Program is accepted as CPPFLAGS... yes
checking for whether Files\Vagrant\embedded\usr\include is accepted as CPPFLAGS... no
checking for whether -LC:\Program is accepted as LDFLAGS... yes
checking for whether Files\Vagrant\embedded\mingw64\x86_64-w64-mingw32\lib is accepted as LDFLAGS... no
checking for whether -LC:\Program is accepted as LDFLAGS... yes
checking for whether Files\Vagrant\embedded\mingw64\lib is accepted as LDFLAGS... no
checking for whether -LC:\Program is accepted as LDFLAGS... yes
checking for whether Files\Vagrant\embedded\usr\lib is accepted as LDFLAGS... no
checking for whether -std=c99 is accepted as CFLAGS... yes
checking for whether -Wno-declaration-after-statement is accepted as CFLAGS... yes
checking for whether -g is accepted as CFLAGS... yes
checking for whether -Winline is accepted as CFLAGS... yes
checking for whether -Wmissing-noreturn is accepted as CFLAGS... yes
checking for whether  "-Idummypath" is accepted as CPPFLAGS... yes
Building nokogiri using system libraries.
checking for gzdopen() in -lz... yes
checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -llibxml2... no
checking for libxml-2.0 using `pkg_config`... no
Please install either the `pkg-config` utility or the `pkg-config` rubygem.
checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -llibxml2... no

Based on the logging, the issue seems to be here, running this command: C:/Program\ Files/Vagrant/embedded/mingw64/bin/ruby.exe -I C:/Program\ Files/Vagrant/embedded/mingw64/lib/ruby/3.1.0 extconf.rb

The location Vagrant installs to contains spaces, C:\Program Files\Vagrant. That path is not wrapped in quotes, so the command is not going to be correct.

To try and prove this out and work around the issue, I copied the vagrant installation files to another directory that does not contain a space (such as C:\Programs\Vagrant) and added that to the system PATH environment variable (such as C:\Programs\Vagrant\bin, making sure it's listed before the other vagrant path. Open a new console window and run the same command and the plugin installs fine without errors.

Reproduction information

Vagrant version

Vagrant 2.4.0. Previous release version, 2.3.7 does not have this issue.

Host operating system

I have recreated this on Windows 10 22H2 and Window Server 2019. Vagrant 2.4.0 on Ubuntu Server 20.04 is able to install the plugin fine.

Guest operating system

N/A

Steps to reproduce

  1. Install Vagrant 2.4.0 on a Windows OS.
  2. Delete the .vagrant.d directory in your user's home directory C:\Users\[YourUsername] to start clean with no plugins installed.
  3. Run vagrant plugin install vagrant-vsphere. You should see the plugin installation fail with a similar line as mentioned in the Actual behavior section above with no quotes around the path with spaces.

Vagrantfile

N/A

chrisroberts commented 8 months ago

The pathing issues appears to be affecting the CFLAGS/LDFLAGS which is causing library dependencies to not be located. Investigating further to see if it's possible to force quote these.

GSDragoon commented 8 months ago

@chrisroberts was this working for you after your changes? I installed the latest 2.4.1 nightly release and am still seeing the issue.

vagrant plugin install vagrant-vsphere
Installing the 'vagrant-vsphere' plugin. This can take a few minutes...
Fetching optimist-3.1.0.gem
Fetching mini_portile2-2.8.5.gem
Fetching nokogiri-1.13.4.gem
Building native extensions. This could take a while...
Vagrant failed to properly resolve required dependencies. These
errors can commonly be caused by misconfigured plugin installations
or transient network issues. The reported error is:

ERROR: Failed to build gem native extension.

    current directory: C:/Users/gseaton/.vagrant.d/gems/3.1.4/gems/nokogiri-1.13.4/ext/nokogiri
C:/Program\ Files/Vagrant/embedded/mingw64/bin/ruby.exe -IC:/Program\ Files/Vagrant/embedded/gems/gems/vagrant-2.4.1.dev/lib/vagrant/patches/builder -I C:/Program\ Files/Vagrant/embedded/mingw64/lib/ruby/3.1.0 extconf.rb
checking for whether -I"C:\Program Files\Vagrant\embedded\mingw64\x86_64-w64-mingw32\include" -I"C:\Program Files\Vagrant\embedded\mingw64\include" -I"C:\Program Files\Vagrant\embedded\usr\include" is accepted as CFLAGS... yes
checking for whether -I"C:\Program Files\Vagrant\embedded\mingw64\x86_64-w64-mingw32\include" -I"C:\Program Files\Vagrant\embedded\mingw64\include" -I"C:\Program Files\Vagrant\embedded\usr\include" is accepted as CPPFLAGS... yes
checking for whether -L"C:\Program Files\Vagrant\embedded\mingw64\x86_64-w64-mingw32\lib" -L"C:\Program Files\Vagrant\embedded\mingw64\lib" -L"C:\Program Files\Vagrant\embedded\usr\lib" is accepted as LDFLAGS... yes
checking for whether -I"C:\Program is accepted as CFLAGS... no
checking for whether Files\Vagrant\embedded\mingw64\x86_64-w64-mingw32\include" is accepted as CFLAGS... no
checking for whether -I"C:\Program is accepted as CFLAGS... no
checking for whether Files\Vagrant\embedded\mingw64\include" is accepted as CFLAGS... no
checking for whether -I"C:\Program is accepted as CFLAGS... no
checking for whether Files\Vagrant\embedded\usr\include" is accepted as CFLAGS... no
checking for whether -I"C:\Program is accepted as CPPFLAGS... no
checking for whether Files\Vagrant\embedded\mingw64\x86_64-w64-mingw32\include" is accepted as CPPFLAGS... no
checking for whether -I"C:\Program is accepted as CPPFLAGS... no
checking for whether Files\Vagrant\embedded\mingw64\include" is accepted as CPPFLAGS... no
checking for whether -I"C:\Program is accepted as CPPFLAGS... no
checking for whether Files\Vagrant\embedded\usr\include" is accepted as CPPFLAGS... no
checking for whether -L"C:\Program is accepted as LDFLAGS... yes
checking for whether Files\Vagrant\embedded\mingw64\x86_64-w64-mingw32\lib" is accepted as LDFLAGS... yes
checking for whether -L"C:\Program is accepted as LDFLAGS... yes
checking for whether Files\Vagrant\embedded\mingw64\lib" is accepted as LDFLAGS... yes
checking for whether -L"C:\Program is accepted as LDFLAGS... yes
checking for whether Files\Vagrant\embedded\usr\lib" is accepted as LDFLAGS... yes
checking for whether -std=c99 is accepted as CFLAGS... yes
checking for whether -Wno-declaration-after-statement is accepted as CFLAGS... yes
checking for whether -g is accepted as CFLAGS... yes
checking for whether -Winline is accepted as CFLAGS... yes
checking for whether -Wmissing-noreturn is accepted as CFLAGS... yes
checking for whether  "-Idummypath" is accepted as CPPFLAGS... yes

I've been doing some digging...

I don't think the logging is exactly what is being run, at the operating system level. Using Process Monitor, I'm seeing slightly different process commands being run.

2.4.1.dev+000177-600eef07:

Despite the FLAGS environment variables looking okay, the second ruby command looks off. "C:\Program Files\Vagrant\embedded\mingw64\bin\ruby.exe" "-IC:/Program Files/Vagrant/embedded/gems/gems/vagrant-2.4.1.dev/lib/vagrant/patches/builder" -I "C:/Program Files/Vagrant/embedded/mingw64/lib/ruby/3.1.0" extconf.rb Should it be something like this instead? "C:\Program Files\Vagrant\embedded\mingw64\bin\ruby.exe" -I "C:/Program Files/Vagrant/embedded/gems/gems/vagrant-2.4.1.dev/lib/vagrant/patches/builder" -I "C:/Program Files/Vagrant/embedded/mingw64/lib/ruby/3.1.0" extconf.rb

Despite the FLAGS environment variables having quotes around them, there are later logging messages for the checks seems to be ignoring them and treating the space as two separate items, or perhaps that's for a completely different area/process?

Compared to 2.4.0:

With this versions, the second command being run does actually have the quotes around the path in the command. The FLAGS environment variables, however, do not.

chrisroberts commented 8 months ago

@GSDragoon Thanks for following up on this! Yes, it was working for me locally but it was due to a manual gem installation via plugin install masking the gem missing from Vagrant internals. You are correct that what is being logged is not exactly what is getting executed when the extension is built. The mkmf.log file will contain the actual commands being run. The changes in #13322 help to resolve common issues with flag modifications where paths are assumed to not include spaces.

The remaining issue now is that it appears the embedding of the pkg-config gem was not applied correctly to the package. You should be able to resolve your installation issue by first installing pkg-config and then installing your plugin:

> vagrant plugin install pkg-config
> vagrant plugin install vagrant-vsphere

The packaging issue is being tracked here: hashicorp/vagrant-installers#290