Stop gemspec requiring dependencies under Bundler #6927
Conversation
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 #
83ab8f0
to
6bfdca1
Compare
I’m not sure this is safe — we later call methods on |
It should be obvious through an undefined constant or method error, right? It worked fine in by testing, and would definitely have executed |
@alyssais Can you provide reproduction steps for this issue? Using bundler for hacking on bundler itself sounds... interesting 😃 |
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
But, with my fix applied, I can successfully install the gems. |
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? |
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>
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.