This Bazel module provides a pinned, prebuilt version of buildozer, a tool for manipulating Bazel BUILD files.
- Bazel 6.2.0 or later
- Add the following line to your
MODULE.bazel
file:
bazel_dep(name = "buildozer", version = "7.1.2", dev_dependency = True)
- Run buildozer via
bazel run
:
bazel run @buildozer -- ...
The --
is optional if you don't need to pass arguments to buildozer that start with a dash.
You can also use buildozer in a repository rule or module extension, i.e., during the loading phase:
- Add the following line to your
MODULE.bazel
file:
bazel_dep(name = "buildozer", version = "7.1.2")
- In your repository rule or module extension implementation function, get the path to the buildozer binary as follows:
load("@buildozer//:buildozer.bzl", "BUILDOZER_LABEL")
...
def my_impl(repository_or_module_ctx):
buildozer = repository_or_module_ctx.path(BUILDOZER_LABEL)
...
repository_or_module_ctx.execute(
[buildozer, 'set foo bar', '//path/to/pkg:target']
)
Keep the path
call at the top of your implementation function as it may cause a restart of the repository rule.
If you dont want to or can't load
from @buildozer
, you can also use the following approach:
- Add the following lines to your
MODULE.bazel
file:
bazel_dep(name = "buildozer", version = "7.1.2")
buildozer_binary = use_extension("@buildozer//:buildozer_binary.bzl", "buildozer_binary")
use_repo(buildozer_binary, "buildozer_binary")
- In your repository rule or module extension implementation function, get the path to the buildozer binary as follows:
def my_impl(repository_or_module_ctx):
# The ".exe" suffix is *not* a typo. It is present on all platforms to support
# Windows while maintaining a stable label.
buildozer = repository_or_module_ctx.path(Label("@buildozer_binary//:buildozer.exe))