[bazel] Run buildifier on Bazel build files#2904
[bazel] Run buildifier on Bazel build files#2904adhoc-bobcat wants to merge 4 commits intoraspberrypi:developfrom
Conversation
|
I reproduced the "bazel-build-check (ubuntu-latest)" failure, and confirmed it was my patch. I'll mark this as a draft PR until I figure what I did wrong (I'm guessing the full set of fixes was the wrong thing to do, and perhaps deps should NOT have been sorted). |
This is an automated change made with the following command:
$ buildifier --mode=fix --lint=fix **/BUILD.bazel \
src/rp2_common/pico_lwip/lwip.BUILD \
src/rp2_common/pico_mbedtls/mbedtls.BUILD \
src/rp2_common/tinyusb/tinyusb.BUILD \
src/rp2_common/pico_cyw43_driver/cyw43-driver.BUILD \
src/rp2_common/pico_btstack/btstack.BUILD
But with additional fixups.
- The ordering of certain linker script deps matters. For those places a
quick command and a "buildifier: leave-alone" comment were added to
prevent automatic reordering when this tool is next used to clean up
the Bazel build files.
The primary purpose was to get back Bazel 9 compatibility lost since the
last time this was done, as doing this automatically adds the necessary
rules_cc loads for its rules (cc_library, ...)
It also normalizes the formatting, in particular
- Loads go at the top
- Rule attributes are sorted
- Deps lists are sorted
- Trailing commas are added on multiline lists
- Standardizes whitespace between declarations, and at the end of file
Verified by running:
$ bazelisk build //... # Uses .bazelversion (8.1.0)
$ USE_BAZEL_VERSION=9.1.0.rc3 bazelisk build //...
Yes, the dependency ordering for the linker scripts is important, as earlier dependencies override files in later ones. If there's a way to run |
Hi Will! There are "buildifier: leave-alone" and even a check for "do not sort" comments that can be added, which may not be quite what you want. I added them in a test branch (to not add noise to this PR) about an hour ago after tracking down the deps where the order mattered, and reverting that part of the CL:
I was about to update this PR with that commit. And while I didn't think about adding a buildifier check to the presubmit tests, I was going to look into adding a Bazel 9 check build, but I can look into that too. |
6cd1310 to
010f944
Compare
|
Buildifier will sort attributes with the following names: |
|
I have what should be a Bazel 9 check (and a Bazel latest advisory check) as a local commit, but I'll need to upload it to my fork to see if it works as intended. I also have a working buildifier check which does run locally, and which runs on more files than I initially cleaned up (WORKSPACE, *.bzl, REPO.bazel). I'm now working on getting those to be lint-clean, which requires some manual intervention to satisfy checks about missing docstrings et al. After that, I'll do some testing on my fork that they catch regressions, but I think that won't take long. I think I'll have it working over the next few hours, but I've got some other things on my calendar today. I was planning on adding them to this PR, since it makes sense for them to all go in together, but if needed I'm happy to set up a new PR. |
|
I pulled out the latest Bazel ("last_rc") advisory check. It only checks a floating "9.x" version (latest released Bazel 9), which might be somewhat problematic on its own if a new version is released that requires changes. A "last_rc" check might be equally problematic, and if there is no release candidate, it duplicates the "9.x" run. Otherwise it looks like the Bazel 9 check and the buildifier check both work as intended. |
|
Maybe it works too well. It flagged one picotool file because it found it, though that isn't really part of the code here. I'll create a PR there. |
The checks is added as part of the "other" checks that are already run.
Running a build with the latest release of Bazel 9 will ensure it works, even as the main builds support only Bazel 8. Bazel 9 removes some built-ins (like cc_library), that now require using the appropriate replacement Bazel Module (like rules_cc).
95e9ddf to
c94cd49
Compare
This is an automated change made with the following command:
The primary purpose was to get back Bazel 9 compatibility lost since the last time this was done, as doing this automatically adds the necessary rules_cc loads for its rules (cc_library, ...)
It also normalizes the formatting, in particular
Verified by running: