@@ -8,7 +8,7 @@ def _run_tidy(
8
8
additional_deps ,
9
9
config ,
10
10
flags ,
11
- compilation_context ,
11
+ compilation_contexts ,
12
12
infile ,
13
13
discriminator ):
14
14
inputs = depset (
@@ -17,7 +17,7 @@ def _run_tidy(
17
17
additional_deps .files .to_list () +
18
18
([exe .files_to_run .executable ] if exe .files_to_run .executable else [])
19
19
),
20
- transitive = [compilation_context .headers ],
20
+ transitive = [compilation_context .headers for compilation_context in compilation_contexts ],
21
21
)
22
22
23
23
args = ctx .actions .args ()
@@ -48,23 +48,24 @@ def _run_tidy(
48
48
# add args specified by the toolchain, on the command line and rule copts
49
49
args .add_all (flags )
50
50
51
- # add defines
52
- for define in compilation_context .defines .to_list ():
53
- args .add ("-D" + define )
51
+ for compilation_context in compilation_contexts :
52
+ # add defines
53
+ for define in compilation_context .defines .to_list ():
54
+ args .add ("-D" + define )
54
55
55
- for define in compilation_context .local_defines .to_list ():
56
- args .add ("-D" + define )
56
+ for define in compilation_context .local_defines .to_list ():
57
+ args .add ("-D" + define )
57
58
58
- # add includes
59
- for i in compilation_context .framework_includes .to_list ():
60
- args .add ("-F" + i )
59
+ # add includes
60
+ for i in compilation_context .framework_includes .to_list ():
61
+ args .add ("-F" + i )
61
62
62
- for i in compilation_context .includes .to_list ():
63
- args .add ("-I" + i )
63
+ for i in compilation_context .includes .to_list ():
64
+ args .add ("-I" + i )
64
65
65
- args .add_all (compilation_context .quote_includes .to_list (), before_each = "-iquote" )
66
+ args .add_all (compilation_context .quote_includes .to_list (), before_each = "-iquote" )
66
67
67
- args .add_all (compilation_context .system_includes .to_list (), before_each = "-isystem" )
68
+ args .add_all (compilation_context .system_includes .to_list (), before_each = "-isystem" )
68
69
69
70
args .add_all (compilation_context .external_includes .to_list (), before_each = "-isystem" )
70
71
@@ -153,7 +154,10 @@ def _clang_tidy_aspect_impl(target, ctx):
153
154
exe = ctx .attr ._clang_tidy_executable
154
155
additional_deps = ctx .attr ._clang_tidy_additional_deps
155
156
config = ctx .attr ._clang_tidy_config .files .to_list ()[0 ]
156
- compilation_context = target [CcInfo ].compilation_context
157
+
158
+ compilation_contexts = [target [CcInfo ].compilation_context ]
159
+ if hasattr (ctx .rule .attr , "implementation_deps" ):
160
+ compilation_contexts .extend ([implementation_dep [CcInfo ].compilation_context for implementation_dep in ctx .rule .attr .implementation_deps ])
157
161
158
162
rule_flags = ctx .rule .attr .copts if hasattr (ctx .rule .attr , "copts" ) else []
159
163
c_flags = _safe_flags (_toolchain_flags (ctx , ACTION_NAMES .c_compile ) + rule_flags ) + ["-xc" ]
@@ -169,7 +173,7 @@ def _clang_tidy_aspect_impl(target, ctx):
169
173
additional_deps ,
170
174
config ,
171
175
c_flags if src .extension == "c" else cxx_flags ,
172
- compilation_context ,
176
+ compilation_contexts ,
173
177
src ,
174
178
target .label .name ,
175
179
)
@@ -183,6 +187,7 @@ def _clang_tidy_aspect_impl(target, ctx):
183
187
clang_tidy_aspect = aspect (
184
188
implementation = _clang_tidy_aspect_impl ,
185
189
fragments = ["cpp" ],
190
+ attr_aspects = ["implementation_deps" ],
186
191
attrs = {
187
192
"_cc_toolchain" : attr .label (default = Label ("@bazel_tools//tools/cpp:current_cc_toolchain" )),
188
193
"_clang_tidy_wrapper" : attr .label (default = Label ("//clang_tidy:clang_tidy" )),
0 commit comments