erenon / bazel_clang_tidy

Run clang-tidy on Bazel C++ targets directly, efficiently, with caching enabled
MIT License
109 stars 58 forks source link

Is it possible to invoke this as a bazel test? #15

Open ghorn opened 2 years ago

ghorn commented 2 years ago

Currently I invoke this project as documented, with a command similar to

bazel build --keep_going \
  --aspects //lint/clang_tidy:clang_tidy.bzl%clang_tidy_aspect \
  --output_groups=report \
  -- //...

The downside to this is that I can't run it in parallel with my other tests. I have to do something like:

$ bazel test //...
$ bazel build --keep_going \
  --aspects //lint/clang_tidy:clang_tidy.bzl%clang_tidy_aspect \
  --output_groups=report \
  -- //... 

My goal is to be able to run bazel test //... and have the clang-tidy checks run. To do this I think we would need to add a new test rule to clang_tidy.bzl which could be invoked like this:

# macro that attaches linting to cc_ rules
def my_cc_library(**kwargs):
    # invoke native rule
    native.cc_library(**kwargs)

    # invoke the new clang_tidy test rule from erenon/bazel_clang_tidy
    clang_tidy_rule(**kwargs)

From the https://bazel.build/rules/aspects#advanced_example documentation, it seems possible to attach an aspect to a rule. Do you have any idea how difficult this would be, or how to approach it?

erenon commented 2 years ago

This looks like a very nice possible improvement. I do not know if this is feasible or not. I'll not be able to spend time on this in the near future (probably), but I'd be happy to review/merge a related PR. Thanks for filing this ticket.