1
1
load ("@bazel_tools//tools/cpp:toolchain_utils.bzl" , "find_cpp_toolchain" )
2
2
3
- def _run_tidy (ctx , exe , config , flags , compilation_context , infile , discriminator ):
4
- inputs = depset (direct = [infile , config ], transitive = [compilation_context .headers ])
3
+ def _run_tidy (ctx , wrapper , exe , additional_deps , config , flags , compilation_context , infile , discriminator ):
4
+ inputs = depset (direct = [infile , config ] + additional_deps . files . to_list () + ([ exe . files_to_run . executable ] if exe . files_to_run . executable else []) , transitive = [compilation_context .headers ])
5
5
6
6
args = ctx .actions .args ()
7
7
@@ -10,6 +10,12 @@ def _run_tidy(ctx, exe, config, flags, compilation_context, infile, discriminato
10
10
"bazel_clang_tidy_" + infile .path + "." + discriminator + ".clang-tidy.yaml" ,
11
11
)
12
12
13
+ # this is consumed by the wrapper script
14
+ if len (exe .files .to_list ()) == 0 :
15
+ args .add ("clang-tidy" )
16
+ else :
17
+ args .add (exe .files_to_run .executable )
18
+
13
19
args .add (outfile .path ) # this is consumed by the wrapper script
14
20
args .add ("--export-fixes" , outfile .path )
15
21
@@ -43,7 +49,7 @@ def _run_tidy(ctx, exe, config, flags, compilation_context, infile, discriminato
43
49
ctx .actions .run (
44
50
inputs = inputs ,
45
51
outputs = [outfile ],
46
- executable = exe ,
52
+ executable = wrapper ,
47
53
arguments = [args ],
48
54
mnemonic = "ClangTidy" ,
49
55
use_default_shell_env = True ,
@@ -92,14 +98,16 @@ def _clang_tidy_aspect_impl(target, ctx):
92
98
if not CcInfo in target :
93
99
return []
94
100
95
- exe = ctx .attr ._clang_tidy .files_to_run
101
+ wrapper = ctx .attr ._clang_tidy_wrapper .files_to_run
102
+ exe = ctx .attr ._clang_tidy_executable
103
+ additional_deps = ctx .attr ._clang_tidy_additional_deps
96
104
config = ctx .attr ._clang_tidy_config .files .to_list ()[0 ]
97
105
toolchain_flags = _toolchain_flags (ctx )
98
106
rule_flags = ctx .rule .attr .copts if hasattr (ctx .rule .attr , "copts" ) else []
99
107
safe_flags = _safe_flags (toolchain_flags + rule_flags )
100
108
compilation_context = target [CcInfo ].compilation_context
101
109
srcs = _rule_sources (ctx )
102
- outputs = [_run_tidy (ctx , exe , config , safe_flags , compilation_context , src , target .label .name ) for src in srcs ]
110
+ outputs = [_run_tidy (ctx , wrapper , exe , additional_deps , config , safe_flags , compilation_context , src , target .label .name ) for src in srcs ]
103
111
104
112
return [
105
113
OutputGroupInfo (report = depset (direct = outputs )),
@@ -110,7 +118,9 @@ clang_tidy_aspect = aspect(
110
118
fragments = ["cpp" ],
111
119
attrs = {
112
120
"_cc_toolchain" : attr .label (default = Label ("@bazel_tools//tools/cpp:current_cc_toolchain" )),
113
- "_clang_tidy" : attr .label (default = Label ("//clang_tidy:clang_tidy" )),
121
+ "_clang_tidy_wrapper" : attr .label (default = Label ("//clang_tidy:clang_tidy" )),
122
+ "_clang_tidy_executable" : attr .label (default = Label ("//:clang_tidy_executable" )),
123
+ "_clang_tidy_additional_deps" : attr .label (default = Label ("//:clang_tidy_additional_deps" )),
114
124
"_clang_tidy_config" : attr .label (default = Label ("//:clang_tidy_config" )),
115
125
},
116
126
toolchains = ["@bazel_tools//tools/cpp:toolchain_type" ],
0 commit comments