Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI] Fix double clang-tidy config flags #3157

Merged
merged 1 commit into from
Jan 21, 2021

Conversation

bruntib
Copy link
Contributor

@bruntib bruntib commented Jan 21, 2021

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.

@bruntib bruntib added CLI 💻 Related to the command-line interface, such as the cmd, store, etc. commands bugfix 🔨 labels Jan 21, 2021
@bruntib bruntib added this to the release 6.16.0 milestone Jan 21, 2021
@bruntib bruntib requested a review from csordasmarton January 21, 2021 11:18
@bruntib bruntib force-pushed the clang_tidy_double_config branch from 5a578cd to ffefdba Compare January 21, 2021 12:29
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add this information to the --analyzer-config / --tidyargs options help messages that the options in --tidyargs are stonger.

tidyargs_file = os.path.join(self.test_dir, "tidyargs")
saargs_file = os.path.join(self.test_dir, "saargs")

build_log = [{"directory": self.test_dir,
"command": "cc -c " + source_file,
"command": "g++ -c " + source_file,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any test cases where you use the --analyzer-config and --tidyargs in the same command. So please create a new test case or extend an existing one with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I extended the content of analyzer/tests/functional/analyze/test_files/tidyargs file. Now it contains a -config flag. --analyzer-config also has some default value from earlier. The test is the fact that clang-tidy doesn't fail with these two provided and it also gives report on modernize- issues which is enabled in tidyargs.

Copy link
Contributor

@csordasmarton csordasmarton Jan 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I understand it but I would like to see a test for example where we set the clang-tidy:Checks and a clang-tidy:HeaderFilterRegex config option in the --analyzer-config option of the command line and in the --tidy-args I override for example the Checks option.

Comment on lines 338 to 348
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In python I always like to save indentation where it is possible. Here we can do the following thing:

Suggested change
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
if not extra_arg.startswith('-config'):
continue
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

# overwrite its value.
for i, extra_arg in enumerate(handler.analyzer_extra_arguments):
if extra_arg.startswith('-config'):
if extra_arg == '-config':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra comment could be useful here why do we need this condition.

@bruntib bruntib force-pushed the clang_tidy_double_config branch from ffefdba to 6750e99 Compare January 21, 2021 13:18
@bruntib bruntib requested a review from dkrupp as a code owner January 21, 2021 13:18
@bruntib bruntib requested a review from csordasmarton January 21, 2021 13:18
`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.
@bruntib bruntib force-pushed the clang_tidy_double_config branch from 6750e99 to 50b2a41 Compare January 21, 2021 14:38
Copy link
Contributor

@csordasmarton csordasmarton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@csordasmarton csordasmarton merged commit a06e188 into Ericsson:master Jan 21, 2021
@bruntib bruntib deleted the clang_tidy_double_config branch January 21, 2021 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix 🔨 CLI 💻 Related to the command-line interface, such as the cmd, store, etc. commands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants