@@ -59,12 +59,33 @@ def _run_tidy(
59
59
for i in compilation_context .framework_includes .to_list ():
60
60
args .add ("-F" + i )
61
61
62
- for i in compilation_context .includes .to_list ():
63
- args .add ("-I" + i )
64
-
65
- args .add_all (compilation_context .quote_includes .to_list (), before_each = "-iquote" )
62
+ isystems = compilation_context .system_includes .to_list ()
63
+
64
+ if ctx .attr ._clang_tidy_virtual_includes_are_system_includes :
65
+ # Include anything that uses include_prefix or strip_include_prefix as a system include
66
+ include_dirs = []
67
+ for include in compilation_context .includes .to_list ():
68
+ if "/_virtual_includes/" in include :
69
+ isystems .append (include )
70
+ else :
71
+ include_dirs .append (include )
72
+ else :
73
+ include_dirs = compilation_context .includes .to_list ()
74
+
75
+ if ctx .attr ._clang_tidy_bazel_out_includes_are_system_includes :
76
+ # Treat generated code in bazel-out/ as system include
77
+ iquotes = []
78
+ for quote_include in compilation_context .quote_includes .to_list ():
79
+ if quote_include .startswith ("bazel-out/" ):
80
+ isystems .append (quote_include )
81
+ else :
82
+ iquotes .append (quote_include )
83
+ else :
84
+ iquotes = compilation_context .quote_includes .to_list ()
66
85
67
- args .add_all (compilation_context .system_includes .to_list (), before_each = "-isystem" )
86
+ args .add_all (include_dirs , before_each = "-I" )
87
+ args .add_all (iquotes , before_each = "-iquote" )
88
+ args .add_all (isystems , before_each = "-isystem" )
68
89
69
90
ctx .actions .run (
70
91
inputs = inputs ,
@@ -184,6 +205,8 @@ clang_tidy_aspect = aspect(
184
205
"_clang_tidy_executable" : attr .label (default = Label ("//:clang_tidy_executable" )),
185
206
"_clang_tidy_additional_deps" : attr .label (default = Label ("//:clang_tidy_additional_deps" )),
186
207
"_clang_tidy_config" : attr .label (default = Label ("//:clang_tidy_config" )),
208
+ "_clang_tidy_bazel_out_includes_are_system_includes" : attr .bool (default = False ),
209
+ "_clang_tidy_virtual_includes_are_system_includes" : attr .bool (default = False ),
187
210
},
188
211
toolchains = ["@bazel_tools//tools/cpp:toolchain_type" ],
189
212
)
0 commit comments