Skip to content

Commit

Permalink
[CLI] Fix double clang-tidy config flags
Browse files Browse the repository at this point in the history
`clang-tidy` can be given config options via --analyzer-config and
-config in --tidyargs. --analyzer-config also has a default value, so in
case --tidyargs also contains a -config flag then both is given to
clang-tidy which thus fails.
  • Loading branch information
bruntib committed Jan 21, 2021
1 parent a6b3f78 commit 5a578cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions analyzer/codechecker_analyzer/analyzers/clangtidy/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,23 @@ def construct_config_handler(cls, args, context):
if m.group('analyzer') == cls.ANALYZER_NAME:
analyzer_config[m.group('key')] = m.group('value')

# If both --analyzer-config and -config (in --tidyargs) is given then
# these need to be merged. Since "HeaderFilterRegex" has a default
# value in --analyzer-config, we take --tidyargs stronger so user can
# overwrite its value.
for i, extra_arg in enumerate(handler.analyzer_extra_arguments):
if extra_arg.startswith('-config'):
if extra_arg == '-config':
arg = handler.analyzer_extra_arguments[i + 1]
arg_num = 2
else:
arg = extra_arg[len('-config='):]
arg_num = 1

analyzer_config.update(json.loads(arg))
del handler.analyzer_extra_arguments[i:i + arg_num]
break

# TODO: This extra "isinsrance" check is needed for
# CodeChecker checkers --checker-config. This command also
# runs this function in order to construct a config handler.
Expand Down
1 change: 1 addition & 0 deletions analyzer/tests/functional/analyze/test_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ def test_tidyargs_saargs(self):
out, _ = process.communicate()

self.assertIn("division by zero", out)
self.assertIn("modernize-avoid-bind", out)

analyze_cmd = [self._codechecker_cmd, "analyze", build_json,
"-o", report_dir, "--saargs", saargs_file]
Expand Down
2 changes: 1 addition & 1 deletion analyzer/tests/functional/analyze/test_files/tidyargs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--extra-arg=-DTIDYARGS
--extra-arg=-DTIDYARGS '-config={"Checks": "modernize-*"}'

0 comments on commit 5a578cd

Please sign in to comment.