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

Use full path for instance_eval in Bundler::DSL#eval_gemfile #7471

Merged
merged 1 commit into from Feb 15, 2024

Conversation

ccutrer
Copy link
Contributor

@ccutrer ccutrer commented Feb 12, 2024

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

When using eval_gemfile("../gemfile_prefix.rb") with a Gemfile that's not in the current directory, __dir__ and __FILE__
end up being ".." and "gemfile_prefix.rb" respectively, which is not usable from within gemfile_prefix.rb in order to find other relative files, since Dir.pwd is not the Gemfile's directory.

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

eval_gemfile already calculates the absolute path to the gemfile fragment; just pass that to instance_eval. This makes it behave the same wrt __dir__ and __FILE__ as require_relative.

Make sure the following tasks are checked

@segiddins
Copy link
Member

Looks good with an added test!

@ccutrer
Copy link
Contributor Author

ccutrer commented Feb 12, 2024

👍 I'll get some tests written. I wanted to push up (as a draft) just to make sure it didn't break anything else before I invested time in writing a test.

ccutrer added a commit to ccutrer/bundler-multilock that referenced this pull request Feb 12, 2024
ccutrer added a commit to instructure/bundler-multilock that referenced this pull request Feb 12, 2024
so that __dir__ and __FILE__ will work properly from within that gemfile
fragment, if eval_gemfile is given a relative path
@ccutrer ccutrer marked this pull request as ready for review February 12, 2024 22:55
@ccutrer
Copy link
Contributor Author

ccutrer commented Feb 12, 2024

Spec added.

@simi simi merged commit 484e1aa into rubygems:master Feb 15, 2024
83 checks passed
deivid-rodriguez pushed a commit that referenced this pull request Mar 20, 2024
Use full path for `instance_eval` in `Bundler::DSL#eval_gemfile`

(cherry picked from commit 484e1aa)
@ccutrer ccutrer deleted the eval_gemfile_absolute_path branch March 22, 2024 13:38
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

4 participants