New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazily load and vendor optparse
#4881
Conversation
2504048
to
a1257b6
Compare
0ac7730
to
f5d3438
Compare
f5d3438
to
3b1c34f
Compare
Still lacking a spec, but I rebased this PR and filled its description. |
This sounds like the same issue as the tsort activation problem in #5006. I wonder if it would make more sense to vendor in the optparse gem so we don't have too many different approaches to solving the activation problem. Keeping the approaches somewhat similar should allow us to keep the complexity of the codebase to a minimum. |
Yeah, it's the same thing, but I usually try lazy loading first, since lazy loading is a good thing by itself and if it's enough to fix the issue, then why not. |
That said, I think lazily loading |
The `optparse` library is loaded by `rubygems/command`, which should only be loaded when using the `gem` CLI. However, it was also being loaded in some other cases. This commit tries to lazily load it, so that it doesn't interfere with other usages. For example, when `rubygems/installer` is required directly from `bundler`.
616541d
to
1c7a68e
Compare
Alright, in the end I went with also vendoring I also added a spec, so this should be ready. |
Make sure using `auto_install` setting in combination with a `Gemfile` depending on `optparse` doesn't create activation conflicts.
1c7a68e
to
a227e1c
Compare
Thanks for the review @simi! |
Lazily load and vendor `optparse` (cherry picked from commit 1f0d78d)
Lazily load and vendor `optparse` (cherry picked from commit 1f0d78d)
Lazily load and vendor `optparse` (cherry picked from commit 1f0d78d)
What was the end-user or developer problem that led to this PR?
When
BUNDLE_AUTO_INSTALL
is setup,bundle exec
will also load all thebundle install
machinery to install gems. That means also eventually loading theoptparse
gem, and causing activation conflicts in theGemfile
also includes a non compatible version ofoptparse
.What is your fix for the problem, implemented in this PR?
My fix means lazily loading
optparse
from top-level to the places that need it, and that seems to fix this issue.It also requires #4887 from the
bundler
side, which was also loadingoptparse
. If that change inbundler
is not in place,Gem::Command
usages inbundler
will result in a missing constant error. Meaning this PR will break usingbundler
versions prior to 2.2.29 in combination with the rubygems version that ships this change. To fix that, I used aninherited
hook to backfill the missingrequire
from the rubygems side.However, the inherited hook breaks things again in the same way, so I finally went with also vendoring
optparse
insiderubygems
which should completely fix the issue in all cases.Fixes #4880.
Make sure the following tasks are checked