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

Avoid duplicates -rbundler/setup in RUBYOPT with Ruby preview #7002

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

intrip
Copy link
Contributor

@intrip intrip commented Sep 26, 2023

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

When using a Ruby preview version the require path of bundler/setup is similar to -r/opt/ruby3.3.0-preview2/lib/ruby/3.3.0+0/bundler/setup. The special character + in the string makes the Regexp matching fail leading to the addition of duplicate require statements to RUBYOPT (e.g. server reloading).

Example:

>> RUBY_DESCRIPTION
=> "ruby 3.3.0preview2 (2023-09-14 master e50fcca9a7) [arm64-darwin22]"
>> ENV["RUBYOPT"]
=> "-r/Users/jacopobeschi/.rbenv/versions/3.3.0-preview2/lib/ruby/gems/3.3.0+0/gems/bundler-2.3.24/lib/bundler/setup"
>> Bundler::SharedHelpers.send(:set_rubyopt)
=> "-r/Users/jacopobeschi/.rbenv/versions/3.3.0-preview2/lib/ruby/gems/3.3.0+0/gems/bundler-2.3.24/lib/bundler/setup -r/Users/jacopobeschi/.rbenv/versions/3.3.0-preview2/lib/ruby/gems/3.3.0+0/gems/bundler-2.3.24/lib/bundler/setup"
>> ENV["RUBYOPT"]
=> "-r/Users/jacopobeschi/.rbenv/versions/3.3.0-preview2/lib/ruby/gems/3.3.0+0/gems/bundler-2.3.24/lib/bundler/setup -r/Users/jacopobeschi/.rbenv/versions/3.3.0-preview2/lib/ruby/gems/3.3.0+0/gems/bundler-2.3.24/lib/bundler/setup"

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

Escaping the characters in the string ensure a correct match with all the different Ruby versions.

Example:

>> s
=> "gems/3.3.0+0/gems/bundler-2.3.24/lib/bundler/setup"
>> /#{s}/.match?(s)
=> false
>> /#{Regexp.escape(s)}/.match?(s)
=> true

@welcome
Copy link

welcome bot commented Sep 26, 2023

Thanks for opening a pull request and helping make RubyGems and Bundler better! Someone from the RubyGems team will take a look at your pull request shortly and leave any feedback. Please make sure that your pull request has tests for any changes or added functionality.

We use GitHub Actions to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of GitHub Actions in the PR status window below.

If you have any questions or concerns that you wish to ask, feel free to leave a comment in this PR or join our #rubygems or #bundler channel on Slack.

For more information about contributing to the RubyGems project feel free to review our CONTRIBUTING guide

@deivid-rodriguez
Copy link
Member

I think there are specs for this at bundler/spec/bundler/shared_helpers_spec.rb, could you add one to catch this issue?

@intrip
Copy link
Contributor Author

intrip commented Sep 28, 2023

I think there are specs for this at bundler/spec/bundler/shared_helpers_spec.rb, could you add one to catch this issue?

Of course! Added a test.

@intrip
Copy link
Contributor Author

intrip commented Sep 28, 2023

Just noticed the failure, will fix it

@deivid-rodriguez
Copy link
Member

Thank you!

Copy link
Member

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super minor comment on the spec. Feel free to address it if you think it's a improvement!

bundler/spec/bundler/shared_helpers_spec.rb Outdated Show resolved Hide resolved
When using a Ruby preview the require path of `bundler/setup` is
similar to `-r/opt/ruby3.3.0-preview2/lib/ruby/3.3.0+0/bundler/setup`.
The special character `+` in the string makes the Regexp fail,
leading to multiple addition of the same require statement each time
`set_rubyopt` is called (e.g. server reloading).
Escaping the characters in the string esure a correct match with all
the different Ruby versions.
@intrip
Copy link
Contributor Author

intrip commented Oct 6, 2023

I'm having trouble reproducing the failure locally because It's triggered only in some combination of the test matrix. I've added a stub which "should" help but I have zero knowledge of this codebase, so let's wait for CI 🤞😅.

@intrip
Copy link
Contributor Author

intrip commented Oct 9, 2023

@deivid-rodriguez CI is green now

@deivid-rodriguez
Copy link
Member

Looks great, thank you!

@deivid-rodriguez deivid-rodriguez merged commit 6f7e7a9 into rubygems:master Oct 9, 2023
92 checks passed
@intrip intrip deleted the fix-set-rubyopt branch October 9, 2023 13:12
deivid-rodriguez added a commit that referenced this pull request Oct 13, 2023
Avoid duplicates -rbundler/setup in RUBYOPT with Ruby preview

(cherry picked from commit 6f7e7a9)
deivid-rodriguez added a commit that referenced this pull request Oct 13, 2023
Avoid duplicates -rbundler/setup in RUBYOPT with Ruby preview

(cherry picked from commit 6f7e7a9)
deivid-rodriguez added a commit that referenced this pull request Oct 13, 2023
Avoid duplicates -rbundler/setup in RUBYOPT with Ruby preview

(cherry picked from commit 6f7e7a9)
deivid-rodriguez added a commit that referenced this pull request Oct 16, 2023
Avoid duplicates -rbundler/setup in RUBYOPT with Ruby preview

(cherry picked from commit 6f7e7a9)
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.

None yet

2 participants