buildtools icon indicating copy to clipboard operation
buildtools copied to clipboard

Runfile should allow passing in files on the command line

Open rcorre opened this issue 2 years ago • 4 comments

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

rcorre avatar May 24 '22 15:05 rcorre

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.

avdv avatar Nov 22 '22 11:11 avdv

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:

avdv avatar Nov 22 '22 11:11 avdv

I am simply using a genrule now to run the buildifier tool with arbitrary arguments. See digital-asset/daml@aa9a78f (#15637)

avdv avatar Nov 23 '22 15:11 avdv

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

gannicottb avatar Jan 22 '24 23:01 gannicottb