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

Stop gemspec requiring dependencies under Bundler #6927

Closed
wants to merge 1 commit into from

Conversation

alyssais
Copy link
Contributor

@alyssais alyssais commented Jan 23, 2019

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

The problem was that I couldn't use Bundler to set up an environment for hacking on Bundler, making it compatible with other Bundler-derived tools like Bundix.

What was your diagnosis of the problem?

My diagnosis was that the gemspec requires bundler/version, which then requires rubygems. When running under Bundler, requiring rubygems tries to load all of Bundler's development dependencies.

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

My fix is to ignore missing development dependencies in bundler/version, so that it can be loaded by the gemspec under Bundler.

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

I chose this fix because I don't see any other ones, and I don't think this should have any impact outside of this edge case.

I should be able to make a Gemfile and Gemfile.lock for Bundler with
`bundle init --gemspec && bundle lock`. This would allow me to use
Bundler to set up an environment for hacking on Bundler, making it
compatible with other Bundler-derived tools like Bundix.

But, this doesn't work, because the gemspec requires bundler/version,
which then requires rubygems. When running under Bundler, requiring
rubygems tries to load all of Bundler's development dependencies.

This isn't actually necessary just to load the gemspec, so
bundler/version shouldn't care if it's running under Bundler and the
development dependencies can't be loaded.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# HEAD detached from v2.0.1
# Changes to be committed:
#	modified:   lib/bundler/version.rb
#
# Untracked files:
#	Gemfile
#	Gemfile.lock
#	nix/
#	shell.nix
#
@segiddins
Copy link
Member

I’m not sure this is safe — we later call methods on Gem in this file, so we need to have rubygems.rb loaded

@alyssais
Copy link
Contributor Author

It should be obvious through an undefined constant or method error, right? It worked fine in by testing, and would definitely have executed Gem.loaded_specs at least?

@deivid-rodriguez
Copy link
Member

@alyssais Can you provide reproduction steps for this issue? Using bundler for hacking on bundler itself sounds... interesting 😃

@alyssais
Copy link
Contributor Author

Sure!

Here's a Gemfile:

source "https://rubygems.org"
gemspec

I really just want to use this to install the gems. The reason why I want to do this is a little weird, but it has to do with NixOS, and specifically its Bundix tool. I can go into more detail if required, but I don't think it's that relevant.

If I run bundle lock, with that Gemfile, I get this error:

[!] There was an error parsing `Gemfile`:
[!] There was an error while loading `bundler.gemspec`: Could not find gem 'automatiek (~> 0.1.0)' in any of the gem sources listed in your Gemfile.. Bundler cannot continue.

 #  from /bundler/bundler.gemspec:5
 #  -------------------------------------------
 #  begin
 >    require File.expand_path("../lib/bundler/version", __FILE__)
 #  rescue LoadError
 #  -------------------------------------------
. Bundler cannot continue.

 #  from /bundler/Gemfile:2
 #  -------------------------------------------
 #  source "https://rubygems.org"
 >  gemspec
 #  -------------------------------------------

But, with my fix applied, I can successfully install the gems.

@deivid-rodriguez
Copy link
Member

@alyssais I created #7062 that I think should also fix this problem!

@deivid-rodriguez
Copy link
Member

I'm pretty sure #7062 is a better approach to this, and I also tried that PR for your situation and it worked, so I'll close this, ok?

ghost pushed a commit that referenced this pull request May 12, 2019
7062: Remove version overwriting hacks r=deivid-rodriguez a=deivid-rodriguez

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

The problem was that we are doing some hacks in our version file that are... dangerous. At very least they cause "circular problems" like #6927, but I also have bad feelings about it.

### What was your diagnosis of the problem?

My diagnosis was we're overwriting the version of the currently loaded bundler 😬. This hack is _almost_ unnecessary (see the spec run here with the hack fully removed: https://travis-ci.org/bundler/bundler/builds/509497021. Only three jobs failed, and for old rubies/rubygems/bundler). 

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

My fix is to limit the hack to `bundler`'s spec run, since it's only needed there.

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

I chose this fix because fully getting the build green with the hack fully removed is a bit of work. I dedicated a bit of time to investigate one of the failures and it all comes down to the priority of loading default gems vs `-I`. So I think something like rubygems/rubygems#1868 should fix it. But that's out of the scope of this PR.

Closes #6927.

Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants