buildtools
buildtools copied to clipboard
Runfile should allow passing in files on the command line
bazel run //:buildifier
automatically assumes you want to format all files in a repository: https://github.com/bazelbuild/buildtools/blob/master/buildifier/runner.bash.template#L21-L36
It would be nice if one could pass in a list of files to format instead, i.e.:
bazel run //:buildifier -- file1 file2 file3
This would be useful in tandem with tools like precommit, which automatically build up a list of files to pass to a formatter/linter.
One could do this by implementing a custom runner, except the _runner
attribute is private, and so consumers can't pass their own runner: https://github.com/bazelbuild/buildtools/blob/master/buildifier/internal/factory.bzl#L74-L77
Same use case here: I am using buildifier via bazel from a git pre-commit hook, which should only touch the files to be committed and leave other files alone.
OK, I found a workaround:
buildifier(
name = "buildifier-pre-commit",
exclude_patterns = ["*"],
mode = "fix",
)
This excludes all files by default and just runs on the ones that are passed to the command. It is just a bit wasteful since it still traverses all the files using find
...
edit: scratch that. The script does not accept any arguments... :see_no_evil:
I am simply using a genrule
now to run the buildifier tool with arbitrary arguments. See digital-asset/daml@aa9a78f
(#15637)
I tried the workaround described by @avdv , but our repo uses --symlink_prefix
so it doesn't work, more or less as described here: https://github.com/bazelbuild/bazel/issues/14821