124
124
installed (if using a custom install location). All paths specified
125
125
here are converted to absolute.
126
126
127
- Default is """
127
+ Default is """ ,
128
128
)
129
129
assert arg .help is not None
130
130
arg .help += "a blank string." if not arg .default else f"``{ arg .default } ``."
237
237
238
238
Defaults to ``%(default)s``.""" ,
239
239
)
240
+ cli_arg_parser .add_argument (
241
+ "-x" ,
242
+ "--extra-arg" ,
243
+ default = [],
244
+ action = "append" ,
245
+ help = """A string of extra arguments passed to clang-tidy for use as
246
+ compiler arguments. This can be specified more than once for each
247
+ additional argument. Recommend using quotes around the value and
248
+ avoid using spaces between name and value (use ``=`` instead):
249
+
250
+ .. code-block:: shell
251
+
252
+ cpp-linter --extra-arg="-std=c++17" --extra-arg="-Wall"
253
+
254
+ Defaults to ``'%(default)s'``.
255
+ """ ,
256
+ )
240
257
241
258
242
259
def set_exit_code (override : int = None ) -> int :
@@ -477,6 +494,7 @@ def run_clang_tidy(
477
494
lines_changed_only : int ,
478
495
database : str ,
479
496
repo_root : str ,
497
+ extra_args : List [str ],
480
498
) -> None :
481
499
"""Run clang-tidy on a certain file.
482
500
@@ -489,6 +507,23 @@ def run_clang_tidy(
489
507
diff info.
490
508
:param database: The path to the compilation database.
491
509
:param repo_root: The path to the repository root folder.
510
+ :param extra_args: A list of extra arguments used by clang-tidy as compiler
511
+ arguments.
512
+
513
+ .. note::
514
+ If the list is only 1 item long and there is a space in the first item,
515
+ then the list is reformed from splitting the first item by whitespace
516
+ characters.
517
+
518
+ .. code-block:: shell
519
+
520
+ cpp-linter -extra-arg="-std=c++14 -Wall"
521
+
522
+ is equivalent to
523
+
524
+ .. code-block:: shell
525
+
526
+ cpp-linter -extra-arg=-std=c++14 --extra-arg=-Wall
492
527
"""
493
528
if checks == "-*" : # if all checks are disabled, then clang-tidy is skipped
494
529
# clear the clang-tidy output file and exit function
@@ -511,6 +546,10 @@ def run_clang_tidy(
511
546
line_ranges = dict (name = filename , lines = file_obj ["line_filter" ][ranges ])
512
547
logger .info ("line_filter = %s" , json .dumps ([line_ranges ]))
513
548
cmds .append (f"--line-filter={ json .dumps ([line_ranges ])} " )
549
+ if len (extra_args ) == 1 and " " in extra_args [0 ]:
550
+ extra_args = extra_args [0 ].split ()
551
+ for extra_arg in extra_args :
552
+ cmds .append (f"--extra-arg={ extra_arg } " )
514
553
cmds .append (filename )
515
554
# clear yml file's content before running clang-tidy
516
555
Path ("clang_tidy_output.yml" ).write_bytes (b"" )
@@ -623,6 +662,7 @@ def capture_clang_tools_output(
623
662
lines_changed_only : int ,
624
663
database : str ,
625
664
repo_root : str ,
665
+ extra_args : List [str ],
626
666
):
627
667
"""Execute and capture all output from clang-tidy and clang-format. This aggregates
628
668
results in the :attr:`~cpp_linter.Globals.OUTPUT`.
@@ -636,14 +676,23 @@ def capture_clang_tools_output(
636
676
diff info.
637
677
:param database: The path to the compilation database.
638
678
:param repo_root: The path to the repository root folder.
679
+ :param extra_args: A list of extra arguments used by clang-tidy as compiler
680
+ arguments.
639
681
"""
640
682
# temporary cache of parsed notifications for use in log commands
641
683
tidy_notes : List [TidyNotification ] = []
642
684
for file in Globals .FILES :
643
685
filename = cast (str , file ["filename" ])
644
686
start_log_group (f"Performing checkup on { filename } " )
645
687
run_clang_tidy (
646
- filename , file , version , checks , lines_changed_only , database , repo_root
688
+ filename ,
689
+ file ,
690
+ version ,
691
+ checks ,
692
+ lines_changed_only ,
693
+ database ,
694
+ repo_root ,
695
+ extra_args ,
647
696
)
648
697
run_clang_format (filename , file , version , style , lines_changed_only )
649
698
end_log_group ()
@@ -962,6 +1011,7 @@ def main():
962
1011
args .lines_changed_only ,
963
1012
args .database ,
964
1013
args .repo_root ,
1014
+ args .extra_arg ,
965
1015
)
966
1016
967
1017
start_log_group ("Posting comment(s)" )
0 commit comments