Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

bundle config build.<gem> doesn't send multiple parameters to extconf.rb correctly #6940

Closed
brad1 opened this issue Jan 31, 2019 · 7 comments · Fixed by #7023
Closed

bundle config build.<gem> doesn't send multiple parameters to extconf.rb correctly #6940

brad1 opened this issue Jan 31, 2019 · 7 comments · Fixed by #7023

Comments

@brad1
Copy link

brad1 commented Jan 31, 2019

What works (bundler 1.7.2)

bundle config build.<gem> --with-opt-lib=... --with-client-lib=..., then
bundle install
This succeeds, giving the same results as:
gem install gem -v x.y.z -- --with-opt-lib=... --with-client-lib=....

From mkmf.log:

gcc ... -L"/path/to/lib" -L"/another/path"

What happens now (tried with bundler 1.17.1 and 2.0.1)

After the exact same steps as above:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.  

...

/usr/bin/ruby -I /usr/lib64/ruby/2.6.0 -r ./siteconf20190130-29495-12z1ot5.rb \ 
 extconf.rb --with-opt-lib\=<...>\ --with-client-lib\=<...>

Notice that the build parameters are separated by an escaped space, because extconf.rb is being given the build parameters as one big string. Verified this using pry.

From mkmf.log:

gcc ... -L"/path/to/lib --with-client-lib=/another/path"

And the native extension fails to install because we can no longer find the required headers.

@brad1 brad1 changed the title bundle config build.<gem> doesn't multiple parameters to extconf.rb correctly bundle config build.<gem> doesn't send multiple parameters to extconf.rb correctly Jan 31, 2019
@amygitsthings
Copy link

I'm seeing this problem with 1.17.2 as well and I was not seeing this issue with bundler 1.15.4

@colby-swandale
Copy link
Member

Can you please provide a Gemfile that we can use to reproduce this problem.

@amygitsthings
Copy link

I was trying to install the do_postgres gem and providing --with-pgsql-server-include and --with-pgsql-client-dir options

@coding-red-panda
Copy link

Running into similar problems with bundler 1.17.3 on ruby 2.1.6
Downgrading to bundler 1.15.4 makes it all work without issues.

Used the following command to generate output:

export DEBUG_RESOLVER=1
bundle 2> ~/debug_output.txt 1>~/stdio.txt &

see attached file
stdio.txt

@jeremy
Copy link
Contributor

jeremy commented Mar 7, 2019

Quick repro:

# repro.rb
require 'bundler/inline'

system "bundle config --local build.mysql2 --with-mysql-config=mysqlconfig --example-argument"

gemfile do
  source 'https://rubygems.org'
  gem 'mysql2'
end

Running it:

$ ruby repro.rb 
You are replacing the current local value of build.mysql2, which is currently nil
Traceback (most recent call last):
…snip…
/Users/jeremy/.rbenv/versions/2.6.1/lib/ruby/site_ruby/2.6.0/bundler/installer/parallel_installer.rb:201:in `handle_error': Gem::Ext::BuildError: ERROR: Failed to build gem native extension. (Bundler::InstallError)

    current directory: /Users/jeremy/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/mysql2-0.5.2/ext/mysql2
/Users/jeremy/.rbenv/versions/2.6.1/bin/ruby -I /Users/jeremy/.rbenv/versions/2.6.1/lib/ruby/site_ruby/2.6.0 -r ./siteconf20190306-75775-1csb26z.rb extconf.rb --with-mysql-config\=mysqlconfig\ --example-argument
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
-----
Cannot find mysql_config at mysqlconfig --example-argument
…snip…

Here's the escaped build config from the extconf.rb invocation:

… extconf.rb --with-mysql-config\=mysqlconfig\ --example-argument

(can repro on Ruby 2.5, 2.6; RubyGems 2.7.3, 3.0.3; Bundler 1.17.3, 2.0.1)

@jeremy
Copy link
Contributor

jeremy commented Mar 7, 2019

Quick fix:

require 'bundler/inline'

system "bundle config --local build.mysql2 --with-mysql-config=mysqlconfig --example-argument"

if ENV['SHELLSPLIT']
  require 'bundler/installer/gem_installer'
  require 'shellwords'

  module ShellsplitSpecSettings
    def spec_settings
      if settings = super
        Shellwords.shellsplit settings
      end
    end
  end

  Bundler::GemInstaller.prepend ShellsplitSpecSettings
end

gemfile do
  source 'https://rubygems.org'
  gem 'mysql2'
end

Running it:

$ SHELLSPLIT=1 ruby repro.rb
… extconf.rb --with-mysql-config\=mysqlconfig --example-argument

Looks like this was introduced by shellescaping/shelljoining arguments in the RubyGems installer: https://github.com/rubygems/rubygems/pull/2441/files#diff-352b7b3f2988f0f74c3e332074f59e09R74

So shellsplitting the spec_settings fixes it.

@deivid-rodriguez
Copy link
Member

Thanks @jeremy, I created #7023 to add your patch to bundler.

ghost pushed a commit that referenced this issue Apr 4, 2019
7023: Shellsplit build config r=deivid-rodriguez a=deivid-rodriguez

### What was the end-user problem that led to this PR?

The problem was #6940. Build configurations with multiple whitepaced parameter are no longer properly handled.

### What was your diagnosis of the problem?

My diagnosis was not mine, was @jeremy's: Since [shellscaping / shelljoining build arguments to the rubygems gem installer](#6940), these are no longer properly passed

### What is your fix for the problem, implemented in this PR?

My fix is not mine, it's @jeremy's: shellsplit settings before passing them.

### Why did you choose this fix out of the possible options?

I chose this fix because it works and it sounds like the proper followup to rubygems/rubygems#2441.

Fixes #6940.

Co-authored-by: David Rodríguez <[email protected]>
@ghost ghost closed this as completed in #7023 Apr 4, 2019
charleshansen added a commit to cloudfoundry/bosh that referenced this issue Jul 9, 2019
rubygems 3.0 introduced a bug so that no version of bundler could
install the pg gem correctly. We are temporarily rolling back to
rubygems 2.7 until the bug is fixed.
See rubygems/bundler#6940 for more details

[#164713288](https://www.pivotaltracker.com/story/show/164713288)

Co-authored-by: Belinda Liu <[email protected]>
charleshansen added a commit to cloudfoundry/bosh-package-ruby-release that referenced this issue Jul 9, 2019
Previously ruby 2.6 was on rubygems 3.0, but 3.0 introduced a bug in
bundler where build arguments were not properly used. Rolling back for
now until the bug is fixed. See rubygems/bundler#6940 for more details

[#164713288](https://www.pivotaltracker.com/story/show/164713288)

Co-authored-by: Belinda Liu <[email protected]>
tjvman pushed a commit to tjvman/bosh that referenced this issue Oct 7, 2019
rubygems 3.0 introduced a bug so that no version of bundler could
install the pg gem correctly. We are temporarily rolling back to
rubygems 2.7 until the bug is fixed.
See rubygems/bundler#6940 for more details

[#164713288](https://www.pivotaltracker.com/story/show/164713288)

Co-authored-by: Belinda Liu <[email protected]>
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants