Skip to content
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

Make ruby -r work with bundle exec #4616

Closed
wants to merge 3 commits into from
Closed

Conversation

deivid-rodriguez
Copy link
Member

@deivid-rodriguez deivid-rodriguez commented May 24, 2021

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

When bundle exec''ing to ruby, and using -rflags, requiring gems in theGemfilewon't work becausebundler/setupis required through-roptions insideRUBYOPT, which are processed after -r` CLI flags.

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

My fix is to special case bundle exec ruby and prepend -rbundler/setup to ruby CLI flags, so that gems in the Gemfile are made available before other -r options are processed.

Note: The test I wrote for this revealed an issue with Bundler.which under Windows, which I also fixed.

Fixes #4025.

Make sure the following tasks are checked

Several specs don't need these gems installed globally.
It was ignoring executable extensions, which is the only hint
`File.executable?` uses on Windows to figure out executability.
When `bundle exec`'ing to `ruby` itself, direct `-r` flags get run
before `RUBYOPT`, so they get run before `bundler/setup` gets the chance
to be required.

This seems like a flag precedence issue in ruby, but we can workaround
it.
@deivid-rodriguez deivid-rodriguez marked this pull request as ready for review May 24, 2021 20:53
@deivid-rodriguez
Copy link
Member Author

I'm closing this since it doesn't work for shell scripts invoking ruby. I will extract some changes from here that still make sense (fixes to Bundler.which on Windows) to a separate PR. A better approach that works in general is being discussed at https://bugs.ruby-lang.org/issues/17883.

@deivid-rodriguez deivid-rodriguez deleted the bundle_exec_ruby branch May 25, 2021 10:29
@deivid-rodriguez deivid-rodriguez restored the bundle_exec_ruby branch August 2, 2021 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bundle exec ruby is not always equivalent to ruby -rbundler/setup.
2 participants