This Bazel module provides a pinned, prebuilt version of buildozer, a tool for manipulating Bazel BUILD files.
MODULE.bazel file:bazel_dep(name = "buildozer", version = "10.1.0", dev_dependency = True)
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 create an alias for the @buildozer target in your main repo.
You can also use buildozer in a repository rule or module extension, i.e., during the loading phase:
MODULE.bazel file:bazel_dep(name = "buildozer", version = "10.1.0")
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:
MODULE.bazel file:bazel_dep(name = "buildozer", version = "10.1.0")
buildozer_binary = use_extension("@buildozer//:buildozer_binary.bzl", "buildozer_binary")
use_repo(buildozer_binary, "buildozer_binary")
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"))