feat(bazel): introduce a binary stamping feature (#22176)
This grabs version control metadata and makes it available in the build, eg. to put in the version field for released artifacts PR Close #22176
This commit is contained in:

committed by
Victor Berchet

parent
a069e08354
commit
bba65e0f41
@ -17,6 +17,14 @@ you run the first build.
|
||||
|
||||
[install]: https://bazel.build/versions/master/docs/install.html
|
||||
|
||||
### Installation of ibazel
|
||||
|
||||
Install interactive bazel runner / fs watcher via:
|
||||
|
||||
```
|
||||
yarn global add @bazel/ibazel
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
The `WORKSPACE` file indicates that our root directory is a
|
||||
@ -112,6 +120,33 @@ Apple+Shift+D on Mac) and click on the green play icon next to the configuration
|
||||
- Open chrome at: [http://localhost:9876/debug.html](http://localhost:9876/debug.html)
|
||||
- Open chrome inspector
|
||||
|
||||
### Debugging Bazel rules
|
||||
|
||||
Open `external` directory which contains everything that bazel downloaded while executing the workspace file:
|
||||
```sh
|
||||
open $(bazel info output_base)/external
|
||||
```
|
||||
|
||||
See subcommands that bazel executes (helpful for debugging):
|
||||
```sh
|
||||
bazel build //packages/core:package -s
|
||||
```
|
||||
|
||||
To debug nodejs_binary executable paths uncomment `find . -name rollup 1>&2` (~ line 96) in
|
||||
```sh
|
||||
open $(bazel info output_base)/external/build_bazel_rules_nodejs/internal/node_launcher.sh
|
||||
```
|
||||
|
||||
## Stamping
|
||||
|
||||
Bazel supports the ability to include non-hermetic information from the version control system in built artifacts. This is called stamping.
|
||||
You can see an overview at https://www.kchodorow.com/blog/2017/03/27/stamping-your-builds/
|
||||
In our repo, here is how it's configured:
|
||||
|
||||
1) In `tools/bazel_stamp_vars.sh` we run the `git` commands to generate our versioning info.
|
||||
1) In `tools/bazel.rc` we register this script as the value for the `workspace_status_command` flag. Bazel will run the script when it needs to stamp a binary.
|
||||
1) In `tools/BUILD.bazel` we have a target `stamp_data` with the special `stamp=1` attribute, which requests that Bazel run the `workspace_status_command`. The result is written to a text file that can be used as an input to other rules.
|
||||
|
||||
## Remote cache
|
||||
|
||||
Bazel supports fetching action results from a cache, allowing a clean build to pick up artifacts from prior builds.
|
||||
|
Reference in New Issue
Block a user