[bazel] Run buildifier on Bazel build files #2904
No reviewers
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk!2904
Loading…
Reference in a new issue
No description provided.
Delete branch "buildifier"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:
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).
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
buildifierwithout doing the re-ordering of those dependencies, it might be nice to add that to the other Bazel CI checks (throwing an error and printing out the diff if there are any changes needed, for the PR author to copy into their PR) - that would ensure Bazel 9 compatibility doesn't get lost againHi 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.
Buildifier will sort attributes with the following names:
github.com/bazelbuild/buildtools@05d2ebe49b/tables/tables.go (L110-L158)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.
To make it clear, my last change altered the buildifier checks so that only files that are checked in are checked, which naturally excludes the picotool files. The presubmit checks now pass.
I think this PR is ready, and will be happy to make any adjustments necessary.
@ -86,6 +85,9 @@ cc_library(visibility = ["//src/rp2_common/pico_standard_link:__pkg__",I'm afraid I know nothing about Bazel or linker-scripts, but should
src/rp2350/pico_platform/BUILD.bazelhave the samecomments that
src/rp2040/pico_platform/BUILD.bazeldoes?@ -86,6 +85,9 @@ cc_library(visibility = ["//src/rp2_common/pico_standard_link:__pkg__",Yes, it should - it probably isn't breaking things because RP2350 doesn't override any of the default files
@ -86,6 +85,9 @@ cc_library(visibility = ["//src/rp2_common/pico_standard_link:__pkg__",Sorry I missed those. I'll add the
leave-alone, and revert any order changes.@ -86,6 +85,9 @@ cc_library(visibility = ["//src/rp2_common/pico_standard_link:__pkg__",I fixed up
src/rp2350/pico_platform/BUILD.bazel.I additionally did a grep for (regex)
linker.script,memmap_and_script.Out of caution, I added a "leave-alone" comment to the list for the non-bare metal case deps list in
pico_standard_linkinsrc/rp2_common/pico_standard_link/BUILD.bazel, though that list appears to be sorted already.I also saw a small number of cases like
rp2350_linker_scriptsinsrc/rp2350/pico_platform/script_include/BUILD.bazelwhere there was a deps list with just a single value. I could see that changing at some point, but I decided to leave it alone.Firstly: do we need this? I'm not seeing it referenced. If we want to add this, maybe
tools/bazel_buildifier_lint_check.pyshould use this.Second:
If you want a top-level
buildifiershortcut for convenience, we still need to be careful about how we add it since this is adev_dependency:When you're just adding a
dep, this is less sensitive. The instant you do aloadfrom a dev-dependency, anyone who lacks that dependency fails to parse theBUILDfile completely. Not an issue yet, but it immediately prevents the root package of this module from being parsable by a downstream user in the future.The simplest solution is to just make this a private alias:
@ -1,5 +1,8 @@def declare_flag_choices(flag, choices):"""Declares a `config_setting` for each known choice for the provided flag."""Utilities for creating multiple choice flags."""nameis unused here. You can disable the Buildifier lint that is complaining about needing a name. Normally, I prefer ensuring there's anameand that it does something, but it doesn't really make sense for this macro.Also, using a signature like this prevents passing the args positionally:
@ -1,5 +1,8 @@def declare_flag_choices(flag, choices):"""Declares a `config_setting` for each known choice for the provided flag."""Utilities for creating multiple choice flags."""Ok, I've disabled the lint warning (I was on the fence about doing it that way), and added the
*.Well then, I should have reviewed this change a bit more closely.
I started off adding buildifier by following the official instructions at https://github.com/bazelbuild/buildtools/tree/main/buildifier#setup-and-usage-via-bazel, adding the few lines suggested there to the root BUILD.bazel (and creating one).
I then got busy with the other changes, and when I got around to putting together tools/bazel_buildifier_lint_check.py, I just directly ran "@buildifier_presubmit//:buildifier", since I wasn't just blindly following instructions.
I've removed this BUILD.bazel file as unneeded.
Ack, again I was just blindly following the suggested instructions, and wasn't questioning them too much.
This all looks good to me - if @armandomontanez is happy too then I will merge this
LGTM