-
-
Notifications
You must be signed in to change notification settings - Fork 645
feat: basic build data with stamping #3484
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @rickeylev, 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 introduces the capability for Python binaries to access their build-time information, such as target name, config mode, and stamping status. It establishes a new 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. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a valuable feature for embedding build information into Python binaries. The implementation is well-designed, particularly the clever handling of Bazel's caching mechanisms to ensure stamped data is always fresh without destroying cacheability for dependent actions. The introduction of the bazel_binary_info module provides a clean and user-friendly API for accessing this data. The code is well-structured and includes thorough tests. I have a couple of suggestions for minor improvements to enhance efficiency and maintainability.
aignas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, this is a great feature!
| ### Added | ||
| * (binaries/tests) {obj}`--debugger`: allows specifying an extra dependency | ||
| to add to binaries/tests for custom debuggers. | ||
| * (binaries/tests) Build information is now included in binaries and tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also tell, that if users want, the could, for example set the __version__ or other standard Python metadata from the bazel_binary_info module. What do you think?
This makes build data accessible to binaries. By default, some basic information
is always available: target name, config mode, config id, and if stamping was enabled.
When
--stampis enabled, the fullworkspace_status_commandoutput is included in thebuild information.
Build information is made available through a special
bazel_binary_infomodule. Thismodule is created by the bootstrap and injected into sys.modules. It provides an API
for gettting the raw build information that was written. Exposing a module, instead
of a file, is done insulate from the Bazel-ism of runfiles.
When stamping is enabled, the way stamped data works is a bit round about to get
the desired semantics: that the build data reflects the most recent build of a
binary, not the last cached value of the build information (e.g., if I build
a binary, then modify a file in the binary, then build again, the build data
should reflect the timestamp of the second build). Normal Bazel caching, however,
makes that somewhat difficult (the build data file has to take the full transitive
set of files as inputs to properly detect changes, otherwise it'll get cached
on first build of the binary; plus actions can't take runfiles objects as inputs).
To work around this, we use some special APIs to get
ctx.version_fileinformationinto the output without entirely destroying caching.
ctx.version_filedoesn't trigger cache invalidation, a special helper,py_internal.copy_without_caching(), is used to make it always invalidatecaching. Now we can ensure we have a copy of the most recent invocation data.
py_internal.declare_constant_metadata_file()is used to restore the behaviorof a file never invalidating caching (even if it changes).
This dance is necessary because actions can't take runfiles as direct inputs. It
also avoids having to pass the entire program's transitive set of files as an input
just to do input change tracking.
Note the above only applies when stamping is enabled. Unstamped binaries don't
do any of this.
Along the way...
stampattribute now transitions the--stampflag. This was necessary so thatthe dependency on version_info was conditional on stamping.