fix: manual runfiles path construction when using submodules#3636
fix: manual runfiles path construction when using submodules#3636faximan wants to merge 2 commits intobazel-contrib:mainfrom
Conversation
Summary of ChangesHello @faximan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue with runfiles path construction in Bazel when dealing with binaries defined in separate modules. It fixes a regression that led to incorrect path calculations, particularly when building from a root module that includes other modules. The solution involves using the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses the runfiles path construction issue by consistently utilizing the runfiles_root_path helper function across py_executable.bzl. This change correctly handles paths from different Bazel modules, preventing .. segments that previously caused incorrect runfiles root calculations. The update to the CHANGELOG.md accurately reflects this important fix. Overall, these changes significantly improve the correctness and maintainability of the Python bootstrap scripts.
| substitutions = { | ||
| "%python_binary%": python_binary, | ||
| "%python_binary_actual%": python_binary_actual, | ||
| "%stage2_bootstrap%": "{}/{}".format( |
There was a problem hiding this comment.
Would it be possible to add a test somewhere? For example examples/bzlmod has submodules in it which could ensure that we can still import things.
@rickeylev Any other ideas how we could do this?
There was a problem hiding this comment.
I tried and failed to write a test here tests the specific fix in this PR. As I'm very unfamiliar with this code base in general, I am afraid I'd need support to land that.
|
Related to #3605 |
This fixes #3563. Verified by running the repro in https://github.com/mering/reproduction_rules_python_1_7.
The identified regression in b8e32c4 is problematic because prepending
ctx.workspace_nametoshort_pathresults in paths containing..(e.g.,_main/../sub+/path/to/file.py) when building from a root module that includes other modules. This causes the_find_runfiles_rootlogic, which counts slashes, to incorrectly calculate the runfiles root.The fix is simply using the available
runfiles_root_pathfunction instead. In the example above, this makes the path simplysub+/path/to/file.py.