-
Notifications
You must be signed in to change notification settings - Fork 263
/
configuration.py
1401 lines (1267 loc) · 44.1 KB
/
configuration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding:utf-8 -*-
# ************************** Copyrights and license ***************************
#
# This file is part of gcovr 5.1, a parsing and reporting tool for gcov.
# https://gcovr.com/en/stable
#
# _____________________________________________________________________________
#
# Copyright (c) 2013-2022 the gcovr authors
# Copyright (c) 2013 Sandia Corporation.
# Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
# the U.S. Government retains certain rights in this software.
#
# This software is distributed under the 3-clause BSD License.
# For more information, see the README.rst file.
#
# ****************************************************************************
from __future__ import annotations
from argparse import ArgumentParser, ArgumentTypeError, SUPPRESS
from inspect import isclass
from locale import getpreferredencoding
from multiprocessing import cpu_count
from typing import Iterable, Any, List, Optional, Union, Callable, TextIO, Dict
from dataclasses import dataclass
import datetime
import os
import re
from .utils import FilterOption
from .writer.html import CssRenderer
def check_percentage(value: str) -> float:
r"""
Check that the percentage is within a reasonable range and if so return it.
"""
# strip trailing percent sign if present, useful for config files
if value.endswith("%"):
value = value[:-1]
try:
x = float(value)
if not (0.0 <= x <= 100.0):
raise ValueError()
except ValueError:
raise ArgumentTypeError(f"{value} not in range [0.0, 100.0]") from None
return x
def check_input_file(value: str, basedir: str = None) -> str:
r"""
Check that the input file is present. Return the full path.
"""
if basedir is None:
basedir = os.getcwd()
if not os.path.isabs(value):
value = os.path.join(basedir, value)
value = os.path.normpath(value)
if not os.path.isfile(value):
raise ArgumentTypeError(
f"Should be a file that already exists: {value!r}"
) from None
return os.path.abspath(value)
def timestamp(value: str) -> datetime.datetime:
from .timestamps import parse_timestamp # lazy import
try:
return parse_timestamp(value)
except ValueError as ex:
raise ArgumentTypeError(f"{ex}: {value!r}") from None
class OutputOrDefault:
"""An output path that may be empty.
- ``None``: the option is not set
- ``OutputOrDefault(None)``: fall back to some default value
- ``OutputOrDefault(path)``: use that path
"""
def __init__(self, value: Optional[str], basedir: str = None) -> None:
self.value = value
self._check_output_and_make_abspath(os.getcwd() if basedir is None else basedir)
def __repr__(self):
name = self.__class__.__name__
value = self.value
return f"{name}({value!r})"
def _check_output_and_make_abspath(self, basedir: str) -> None:
r"""
Check if the output file can be created.
"""
if self.value in (None, "-"):
self.abspath = "-"
self.is_dir = False
else:
# Replace / and \ with the os path separator.
value = str(self.value).replace("\\", os.sep).replace("/", os.sep)
# Save if it is a directory
self.is_dir = value.endswith(os.sep)
value = os.path.normpath(value)
if self.is_dir:
value += os.sep
if not os.path.isabs(value):
value = os.path.join(basedir, value)
self.abspath = value
if self.is_dir:
# Now mormalize and add the trailing slash after creating the directory.
if not os.path.isdir(value):
try:
os.mkdir(value)
except OSError as e:
raise ArgumentTypeError(
f"Could not create output directory {self.value!r}: {e.strerror}"
) from None
else:
try:
with open(value, "w") as _:
pass
except OSError as e:
raise ArgumentTypeError(
f"Could not create output file {self.value!r}: {e.strerror}"
) from None
os.unlink(value)
@classmethod
def choose(
cls,
choices: List[Optional[OutputOrDefault]],
default: Optional[OutputOrDefault] = None,
) -> Optional[OutputOrDefault]:
"""select the first choice that contains a value
Example: chooses a truthy value over None:
>>> OutputOrDefault.choose([None, OutputOrDefault(42)])
OutputOrDefault(42)
Example: chooses a truthy value over empty value:
>>> OutputOrDefault.choose([OutputOrDefault(None), OutputOrDefault('x')])
OutputOrDefault('x')
Example: chooses default when given empty list
>>> OutputOrDefault.choose([], default=OutputOrDefault('default'))
OutputOrDefault('default')
Example: chooses default when only given falsey values:
>>> OutputOrDefault.choose(
... [None, OutputOrDefault(None)],
... default=OutputOrDefault('default'))
OutputOrDefault('default')
Example: throws when given other value
>>> OutputOrDefault.choose([True])
Traceback (most recent call last):
...
TypeError: ...
"""
for choice in choices:
if choice is None:
continue
if not isinstance(choice, OutputOrDefault):
raise TypeError(f"expected OutputOrDefault instance, got: {choice}")
if choice.value is not None:
return choice
return default
class GcovrConfigOption:
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-few-public-methods
# pylint: disable=redefined-builtin
r"""
Represents a single setting for a gcovr runtime parameter.
Gcovr can be extensively configured through a series of options,
representing these options as a simple class object allows them to be
portabilty re-used in multiple configuration schemes. This is implemented
in a way similar to how options are defined in argparse. The converter
keyword argument is expected to return a valid conversion of a string
value or throw an error.
Arguments:
name (str):
Destination (options object field),
must be valid Python identifier.
flags (list of str, optional):
Any command line flags.
Keyword Arguments:
action (str, optional):
What to do when the option is parsed:
- store (default): store the option argument
- store_const: store the const value
- store_true, store_false: shortcuts for store_const
- append: append the option argument
(Compare also the *argparse* documentation.)
choices (list, optional):
Value must be one of these after conversion.
config (str or bool, optional):
Configuration file key.
If absent, the first ``--flag`` is used without the leading dashes.
If explicitly set to False,
the option cannot be set from a config file.
const (any, optional):
Assigned by the "store_const" action.
const_negate (any, optional):
Generate a "--no-foo" negation flag with the given "const" value.
default (any, optional):
Default value if the option is not found, defaults to None.
group (str, optional):
Name of the option group in GCOVR_CONFIG_OPTION_GROUPS.
Only relevant for documentation purposes.
help (str):
Help message.
Must display well on terminal *and* render as Restructured Text.
Any named curly-brace placeholders
are filled in from the option attributes via ``str.format()``.
metavar (str, optional):
Name of the value in help messages, defaults to the name.
nargs (int or '+', '*', '?', optional):
How often the option may occur.
Special case for "?": if the option exists but has no value,
the const value is stored.
positional (bool, optional):
Whether this is a positional option, defaults to False.
A positional argument cannot have flags.
required (bool, optional):
Whether this option is required, defaults to False.
type (function, optional):
Check and convert the option value, may throw exceptions.
Constraint: an option must be either have a flag or be positional
or have a config key, or a combination thereof.
"""
def __init__(
self,
name: str,
flags: List[str] = None,
*,
help: str,
action: str = "store",
choices: list = None,
const: Any = None,
const_negate: Any = None,
config: Union[str, bool] = True,
default: Any = None,
group: str = None,
metavar: str = None,
nargs: Union[int, str] = None,
positional: bool = False,
required: bool = False,
type: Callable[[str], Any] = None,
) -> None:
if flags is None:
flags = []
assert not (flags and positional), "option cannot have flags and be positional"
config_key = _derive_configuration_key(config, flags=flags)
del config
assert (
flags or positional or config_key
), "option must be named, positional, or config argument."
negate: List[str] = []
if flags and const_negate is not None:
negate = ["--no-" + f[2:] for f in flags if f.startswith("--")]
assert negate, "cannot autogenerate negation"
assert help is not None, "help required"
if negate:
help += " Negation: {}.".format(", ".join(negate))
if (flags or positional) and config_key and "--" + config_key not in flags:
help += f" Config key: {config_key}."
# the store_true and store_false actions have hardcoded boolean
# constants in their definitions so they need switched to the generic
# store_const in order for the logic here to work correctly.
if action == "store_true":
assert const is None, "action=store_true and const conflict"
assert default is None, "action=store_true and default conflict"
action = "store_const"
const = True
default = False
elif action == "store_false":
assert const is None, "action=store_false and const conflict"
assert default is None, "action=store_false and default conflict"
action = "store_const"
const = False
default = True
assert action in ("store", "store_const", "append")
self.name = name
self.flags = flags
self.action = action
self.choices = choices
self.config = config_key
self.const = const
self.const_negate = const_negate
self.default = default
self.group = group
self.help = "" # assigned later
self.metavar = metavar
self.nargs = nargs
self.negate = negate
self.positional = positional
self.required = required
self.type = type
# format the help
self.help = help.format(**self.__dict__)
def __repr__(self):
r"""String representation of instance.
>>> GcovrConfigOption('foo', ['-f', '--foo'], help="fooify")
GcovrConfigOption('foo', [-f, --foo], ..., help='fooify', ...)
"""
name = self.name
flags = ", ".join(self.flags)
kwargs = ", ".join(
f"{k}={v!r}"
for k, v in sorted(self.__dict__.items())
if k not in ("name", "flags")
)
return f"GcovrConfigOption({name!r}, [{flags}], {kwargs})"
def _derive_configuration_key(
config: Union[str, bool],
*,
flags: List[str],
) -> Optional[str]:
if config is True:
for flag in flags:
if flag.startswith("--"):
return flag.lstrip("-")
assert False, "could not autogenerate config key from {flags!r}"
elif config is False:
return None
else:
assert isinstance(config, str)
return config
def argument_parser_setup(parser: ArgumentParser, default_group):
r"""Add all options and groups to the given argparse parser."""
# setup option groups
groups = {}
for group_def in GCOVR_CONFIG_OPTION_GROUPS:
group = parser.add_argument_group(
group_def["name"],
description=group_def["description"],
)
groups[group_def["key"]] = group
# create each option value
for opt in GCOVR_CONFIG_OPTIONS:
group = default_group if opt.group is None else groups[opt.group]
kwargs: Dict[str, Any] = {
"action": opt.action,
"const": opt.const,
"default": SUPPRESS, # default will be assigned manually
"help": opt.help,
"metavar": opt.metavar,
}
# To avoid store_const problems, optionally set choices, nargs, type:
if opt.choices is not None:
kwargs["choices"] = opt.choices
if opt.nargs is not None:
kwargs["nargs"] = opt.nargs
if opt.type is not None:
kwargs["type"] = opt.type
# We only want to set dest and required for non-positionals.
if opt.flags:
kwargs["dest"] = opt.name
kwargs["required"] = opt.required # only meaningful for flags
group.add_argument(*opt.flags, **kwargs)
# possibly add a negation flag
if opt.const_negate is not None:
kwargs["required"] = False
kwargs["help"] = SUPPRESS # don't show separate help entry
kwargs["const"] = opt.const_negate
group.add_argument(*opt.negate, **kwargs)
elif opt.positional:
group.add_argument(opt.name, **kwargs)
def parse_config_into_dict(
config_entry_source: Iterable[ConfigEntry],
all_options: Iterable[GcovrConfigOption] = None,
) -> Dict[str, Any]:
cfg_dict: Dict[str, Any] = {}
if all_options is None:
all_options = GCOVR_CONFIG_OPTIONS
options_lookup = {
option.config: option for option in all_options if option.config is not None
}
for cfg_entry in config_entry_source:
try:
option: GcovrConfigOption = options_lookup[cfg_entry.key]
except KeyError:
raise cfg_entry.error("unknown config option") from None
value = _get_value_from_config_entry(cfg_entry, option)
_assign_value_to_dict(cfg_dict, value, option, is_single_value=True)
return cfg_dict
def _get_value_from_config_entry(
cfg_entry: ConfigEntry,
option: GcovrConfigOption,
) -> Any:
def get_boolean(silent_error: bool = False):
try:
return cfg_entry.value_as_bool
except ValueError:
if silent_error:
return None
raise
# special case: store_const expects a boolean
if option.action == "store_const":
use_const = get_boolean()
# special case: nargs=? optionally expects a boolean
elif option.nargs == "?":
use_const = get_boolean(silent_error=True)
else:
use_const = None # marker to continue with parsing
if use_const is True:
return option.const
if use_const is False:
return option.default
assert use_const is None
# parse the value
value: object
if option.type is bool:
value = cfg_entry.value_as_bool
elif option.type is not None:
assert (
cfg_entry.filename is not None
), "conversion function must derive base directory from filename"
basedir = os.path.dirname(cfg_entry.filename)
converter = _get_converter_function(option.type, basedir=basedir)
try:
value = converter(cfg_entry.value)
except (ValueError, ArgumentTypeError) as err:
raise cfg_entry.error(str(err))
else:
value = cfg_entry.value
# verify choices:
if option.choices is not None:
if value not in option.choices:
raise cfg_entry.error( # pylint: disable=raising-format-tuple
"must be one of ({}) but got {!r}",
", ".join(repr(choice) for choice in option.choices),
value,
)
return value
def _get_converter_function(
option_type: Callable[[str], Any],
*,
basedir: str,
) -> Callable[[str], Any]:
"""
Obtain a converter function that corresponds to `option.type`.
Usually, `option.type` already is that converter function.
But sometimes, it needs extra arguments that are injected here.
"""
if isclass(option_type) and issubclass(option_type, FilterOption):
return lambda value: FilterOption(value, basedir)
if option_type is check_input_file:
return lambda value: check_input_file(value, basedir)
if option_type is OutputOrDefault:
return lambda value: OutputOrDefault(value, basedir)
return option_type
def _assign_value_to_dict(
namespace: Dict[str, Any],
value: Any,
option: GcovrConfigOption,
is_single_value: bool,
) -> None:
if option.action == "append" or option.nargs == "*":
append_target = namespace.setdefault(option.name, [])
if is_single_value:
append_target.append(value)
else:
append_target.extend(value)
return
if option.action in ("store", "store_const"):
namespace[option.name] = value
return
assert False, f"unexpected action for {option.name}: {option.action!r}"
def merge_options_and_set_defaults(
partial_namespaces: List[Dict[str, Any]],
all_options: List[GcovrConfigOption] = None,
) -> Dict[str, Any]:
assert partial_namespaces, "at least one namespace required"
if all_options is None:
all_options = GCOVR_CONFIG_OPTIONS
target: Dict[str, Any] = {}
for namespace in partial_namespaces:
for option in all_options:
if option.name not in namespace:
continue
_assign_value_to_dict(
target, namespace[option.name], option, is_single_value=False
)
# if no value was provided, set the default.
for option in all_options:
target.setdefault(option.name, option.default)
return target
GCOVR_CONFIG_OPTION_GROUPS = [
{
"key": "output_options",
"name": "Output Options",
"description": (
"Gcovr prints a text report by default, but can switch to XML or HTML."
),
},
{
"key": "filter_options",
"name": "Filter Options",
"description": (
"Filters decide which files are included in the report. "
"Any filter must match, and no exclude filter must match. "
"A filter is a regular expression that matches a path. "
"Filter paths use forward slashes, even on Windows. "
"If the filter looks like an absolute path "
"it is matched against an absolute path. "
"Otherwise, the filter is matched against a relative path, "
"where that path is relative to the current directory "
"or if defined in a configuration file to the directory of the file."
),
},
{
"key": "gcov_options",
"name": "GCOV Options",
"description": (
"The 'gcov' tool turns raw coverage files (.gcda and .gcno) "
"into .gcov files that are then processed by gcovr. "
"The gcno files are generated by the compiler. "
"The gcda files are generated when the instrumented program is "
"executed."
),
},
]
# Style guide for option descriptions:
# - Prefer complete sentences.
# - Phrase first sentence as a command:
# “Print report”, not “Prints report”.
# - Must be readable on the command line,
# AND parse as reStructured Text.
GCOVR_CONFIG_OPTIONS = [
GcovrConfigOption(
"verbose",
["-v", "--verbose"],
help="Print progress messages. Please include this output in bug reports.",
action="store_true",
),
GcovrConfigOption(
"root",
["-r", "--root"],
help=(
"The root directory of your source files. "
"Defaults to '{default!s}', the current directory. "
"File names are reported relative to this root. "
"The --root is the default --filter."
),
default=".",
),
GcovrConfigOption(
"add_tracefile",
["-a", "--add-tracefile"],
help=(
"Combine the coverage data from JSON files. "
"Coverage files contains source files structure relative "
"to root directory. Those structures are combined "
"in the output relative to the current root directory. "
"Unix style wildcards can be used to add the pathnames "
"matching a specified pattern. In this case pattern "
"must be set in double quotation marks. "
"Option can be specified multiple times. "
"When option is used gcov is not run to collect "
"the new coverage data."
),
action="append",
default=[],
),
GcovrConfigOption(
"search_paths",
config="search-path",
positional=True,
nargs="*",
help=(
"Search these directories for coverage files. "
"Defaults to --root and --object-directory."
),
),
GcovrConfigOption(
"config",
["--config"],
config=False,
help=(
"Load that configuration file. "
"Defaults to gcovr.cfg in the --root directory."
),
),
GcovrConfigOption(
"respect_exclusion_markers",
["--no-markers"],
help=(
"Turn off exclusion markers. Any exclusion markers "
"specified in source files will be ignored."
),
action="store_false",
),
GcovrConfigOption(
"fail_under_line",
["--fail-under-line"],
type=check_percentage,
metavar="MIN",
help=(
"Exit with a status of 2 "
"if the total line coverage is less than MIN. "
"Can be ORed with exit status of '--fail-under-branch' option."
),
default=0.0,
),
GcovrConfigOption(
"fail_under_branch",
["--fail-under-branch"],
type=check_percentage,
metavar="MIN",
help=(
"Exit with a status of 4 "
"if the total branch coverage is less than MIN. "
"Can be ORed with exit status of '--fail-under-line' option."
),
default=0.0,
),
GcovrConfigOption(
"source_encoding",
["--source-encoding"],
help=(
"Select the source file encoding. "
"Defaults to the system default encoding ({default!s})."
),
default=getpreferredencoding(),
),
GcovrConfigOption(
"output",
["-o", "--output"],
group="output_options",
help=(
"Print output to this filename. Defaults to stdout. "
"Individual output formats can override this."
),
type=OutputOrDefault,
default=None,
),
GcovrConfigOption(
"show_branch",
["-b", "--branches"],
config="txt-branch",
group="output_options",
help=(
"Report the branch coverage instead of the line coverage. "
"For text report only."
),
action="store_true",
),
GcovrConfigOption(
"show_decision",
["--decisions"],
group="output_options",
help="Report the decision coverage. For HTML and JSON report.",
action="store_true",
),
GcovrConfigOption(
"sort_uncovered",
["-u", "--sort-uncovered"],
group="output_options",
help=(
"Sort entries by increasing number of uncovered lines. "
"For text and HTML report."
),
action="store_true",
),
GcovrConfigOption(
"sort_percent",
["-p", "--sort-percentage"],
group="output_options",
help=(
"Sort entries by increasing percentage of uncovered lines. "
"For text and HTML report."
),
action="store_true",
),
GcovrConfigOption(
"txt",
["--txt"],
group="output_options",
metavar="OUTPUT",
help="Generate a text report. OUTPUT is optional and defaults to --output.",
nargs="?",
type=OutputOrDefault,
default=None,
const=OutputOrDefault(None),
),
GcovrConfigOption(
"cobertura",
["--cobertura", "-x", "--xml"],
group="output_options",
metavar="OUTPUT",
help=(
"Generate a Cobertura XML report. "
"OUTPUT is optional and defaults to --output."
),
nargs="?",
type=OutputOrDefault,
default=None,
const=OutputOrDefault(None),
),
GcovrConfigOption(
"cobertura_pretty",
["--cobertura-pretty", "--xml-pretty"],
group="output_options",
help=(
"Pretty-print the Cobertura XML report. "
"Implies --cobertura. Default: {default!s}."
),
action="store_true",
),
GcovrConfigOption(
"html",
["--html"],
group="output_options",
metavar="OUTPUT",
help="Generate a HTML report. OUTPUT is optional and defaults to --output.",
nargs="?",
type=OutputOrDefault,
default=None,
const=OutputOrDefault(None),
),
GcovrConfigOption(
"html_details",
["--html-details"],
group="output_options",
metavar="OUTPUT",
help=(
"Add annotated source code reports to the HTML report. "
"Implies --html. "
"OUTPUT is optional and defaults to --output."
),
nargs="?",
type=OutputOrDefault,
default=None,
const=OutputOrDefault(None),
),
GcovrConfigOption(
"html_details_syntax_highlighting",
["--html-details-syntax-highlighting"],
group="output_options",
help="Use syntax highlighting in HTML details page. Enabled by default.",
action="store_const",
default=True,
const=True,
const_negate=False, # autogenerates --no-NAME with action const=False
),
GcovrConfigOption(
"html_theme",
["--html-theme"],
group="output_options",
type=str,
choices=CssRenderer.get_themes(),
metavar="THEME",
help=(
"Override the default color theme for the HTML report. "
"Default is {default!s}."
),
default=CssRenderer.get_default_theme(),
),
GcovrConfigOption(
"html_css",
["--html-css"],
group="output_options",
type=check_input_file,
metavar="CSS",
help="Override the default style sheet for the HTML report.",
default=None,
),
GcovrConfigOption(
"html_title",
["--html-title"],
group="output_options",
metavar="TITLE",
help="Use TITLE as title for the HTML report. Default is '{default!s}'.",
default="GCC Code Coverage Report",
),
GcovrConfigOption(
"html_medium_threshold",
["--html-medium-threshold"],
group="output_options",
type=check_percentage,
metavar="MEDIUM",
help=(
"If the coverage is below MEDIUM, the value is marked "
"as low coverage in the HTML report. "
"MEDIUM has to be lower than or equal to value of --html-high-threshold "
"and greater than 0. "
"If MEDIUM is equal to value of --html-high-threshold the report has "
"only high and low coverage. Default is {default!s}."
),
default=75.0,
),
GcovrConfigOption(
"html_high_threshold",
["--html-high-threshold"],
group="output_options",
type=check_percentage,
metavar="HIGH",
help=(
"If the coverage is below HIGH, the value is marked "
"as medium coverage in the HTML report. "
"HIGH has to be greater than or equal to value of --html-medium-threshold. "
"If HIGH is equal to value of --html-medium-threshold the report has "
"only high and low coverage. Default is {default!s}."
),
default=90.0,
),
GcovrConfigOption(
"html_tab_size",
["--html-tab-size"],
group="output_options",
help="Used spaces for a tab in a source file. Default is {default!s}",
type=int,
default=4,
),
GcovrConfigOption(
"relative_anchors",
["--html-absolute-paths"],
group="output_options",
help=(
"Use absolute paths to link the --html-details reports. "
"Defaults to relative links."
),
action="store_false",
),
GcovrConfigOption(
"html_encoding",
["--html-encoding"],
group="output_options",
help=(
"Override the declared HTML report encoding. "
"Defaults to {default!s}. "
"See also --source-encoding."
),
default="UTF-8",
),
GcovrConfigOption(
"html_self_contained",
["--html-self-contained"],
group="output_options",
help=(
"Control whether the HTML report bundles resources like CSS styles. "
"Self-contained reports can be sent via email, "
"but conflict with the Content Security Policy of some web servers. "
"Defaults to self-contained reports unless --html-details is used."
),
action="store_const",
default=None,
const=True,
const_negate=False,
),
GcovrConfigOption(
"print_summary",
["-s", "--print-summary"],
group="output_options",
help=(
"Print a small report to stdout "
"with line & function & branch percentage coverage. "
"This is in addition to other reports. "
"Default: {default!s}."
),
action="store_true",
),
GcovrConfigOption(
"sonarqube",
["--sonarqube"],
group="output_options",
metavar="OUTPUT",
help=(
"Generate sonarqube generic coverage report in this file name. "
"OUTPUT is optional and defaults to --output."
),
nargs="?",
type=OutputOrDefault,
default=None,
const=OutputOrDefault(None),
),
GcovrConfigOption(
"json",
["--json"],
group="output_options",
metavar="OUTPUT",
help="Generate a JSON report. OUTPUT is optional and defaults to --output.",
nargs="?",
type=OutputOrDefault,
default=None,
const=OutputOrDefault(None),
),
GcovrConfigOption(
"json_pretty",
["--json-pretty"],
group="output_options",
help="Pretty-print the JSON report. Implies --json. Default: {default!s}.",
action="store_true",
),
GcovrConfigOption(
"json_summary",
["--json-summary"],
group="output_options",
metavar="OUTPUT",
help=(
"Generate a JSON summary report. "
"OUTPUT is optional and defaults to --output."
),
nargs="?",
type=OutputOrDefault,
default=None,
const=OutputOrDefault(None),
),
GcovrConfigOption(
"json_summary_pretty",
["--json-summary-pretty"],
group="output_options",
help=(
"Pretty-print the JSON SUMMARY report."
"Implies --json-summary. Default: {default!s}."
),
action="store_true",