fix #11824: Option --max-configs has no effect if -D is used #7424
fix #11824: Option --max-configs has no effect if -D is used #7424clock999 wants to merge 1 commit intodanmar:mainfrom
Conversation
|
This needs a very thorough review as well as tests and documentation (in general and documenting this behavior change). As mentioned in the ticket we might need to fix other things first. We might also need to print some messages/error if certain configurations are incompatible (I have not looked at it at all yet). |
|
Basically I agree with the idea. If You can add an example that clarify this in the manual also: |
|
I would also like to see some regression tests. |
danmar
left a comment
There was a problem hiding this comment.
I don't remember why we have added Settings::force and Settings::checkAllConfigurations. Isn't it enough with just Settings::maxConfigs?
Imho testcmdlineparser.cpp should test that when --max-config=2 is used then Settings::maxConfigs will be 2 no matter if -D has been used or not.
| Timer::run("Preprocessor::getConfigs", mSettings.showtime, &s_timerResults, [&]() { | ||
| configurations = preprocessor.getConfigs(tokens1); | ||
| }); | ||
| Timer::run("Preprocessor::getConfigs", mSettings.showtime, &s_timerResults, [&]() { |
There was a problem hiding this comment.
This code will always execute Preprocessor::getConfigs even if max configs is 1.
I think that has been grown historically. It is also possible that part of this is cleaned up with #7293. The duplicated and differing logic in the CLI and GUI code make things a bit awkward. |
yes.. if we can unify logic that would make me happy.. :-) |
Working on it... |
Hi firewave, If it is ok, I’d like to complish this PR. So if the document for how the configs should be handled is ready, could you please let me know that. Thanks a lot! |
|
@clock999 sorry for late response. do you want to continue working on this? I would like that we have consistent proper behavior when --max-configs is used. |
Hi Danmar, We will have 4 checks. That is just our current behavior in fact. So if using the options '--max-configs=3 -DAAA', we just need to keep the behavior the same with using --force, and generate 3 checks which is just configured by the --max-configs. If the user want to only check the user-defined config, he can use --max-configs=1. |
|
I think maybe we should remove Settings::checkAllConfigurations. Maybe GUI should only accept the raw user input to set the Settings, but not edit the Settings. As I understand, the values of the items of the Settings should all be read only, which are only decided by the user input. The Settings items on the UI shown to the user for selecting should be consistent with the CLI options, or can be directly converted to corresponding options. Since 'settings.maxConfigs = 1;' is used, why still setting 'settings.checkAllConfigurations = false;'? Maybe I missed some points. The '-D configuration' and 'the given configuration' are different? If we are using the GUI, can we still be able to have '-D configuration'? |
|
I updated an original version, and will update it further. |
this is more or less correct. For these preprocessor settings it is correct. Removing / renaming Settings members is not a big deal.. we can do that easily. And I am not sure why we have that checkAllConfigurations. |
This is the expected behavior imho
this sounds reasonable the
to be clear, I expect that this command: should only check "AAA" configuration and nothing else. If |
|
Hi Danmar, While setting the checkAllConfigurations, I see there is a comment "If importing a project, only check the given configuration". With running "cppcheck --project=test/cli/helloworld/test.cppcheck", the expected result is that SOME_CONFIG is not checked, that is defined in the main.c. |
Spontanously I feel that:
Yes.. unless a compile_commands.json file is imported by the project. |
|
Hi Danmar, test.cppcheck: If running 'cppcheck --project=helloworld/test.cppcheck', do you think we should have below output: But why NOT: Why whether import a compile_commands.json or not will impact the behavior of checking the configs. Seems it is not related with that. |
In my humble opinion, when you import a compile_commands.json it is expected that we check the files and explicit configurations provided in the compile_commands.json. The Cppcheck analysis should match the compilation as much as we can in this case.. If |
Also if there is a -D in a command in the json file then I believe we will check the exact provided configuration and the extra SOME_CONFIG is not checked. And the result could be that if some of the commands have a -D and other don't then we could get that extra configurations are checked in some files and not in other files.. |
|
Hi Danmar,
I tested the 3 ways. Each of the three will add the defined config to the Settings::userDefines. They have the same behavior. test.cppcheck Running: |
|
Hi Danmar,
Do you have any further suggestion for this? I think maybe we can use this submit to do the fix for this bug. |
no that was what I did not want in my comment #7424 (comment) In my opinion we should check the explicit configuration provided in the |
|
Hi Danmar, test.cppcheck helloworld/main.cpp: Run the command line: That is to say we have no user defined config at all, and we have a compile_commands.json imported. Do you think we should only check the ABC1, or just run the check with an empty config define string. Actually, when getting the extracted the configs, we put an empty string on the first of the list. I am not sure if I am using the correct word when saying the 'extracted the configs'. I just mean the configs returned by getConfigs. |
I would like an "empty config string" in this case because that will match the compilation. |
0bdf0a7 to
446a97f
Compare
|
Hi Danmar, |
danmar
left a comment
There was a problem hiding this comment.
I thought there would be some update in the manual.. is it clear? Since we've had so much discussions I would think it should be updated.
| filename = os.path.join('helloworld', 'main.c') | ||
| assert ret == 0, stdout | ||
| assert stdout == 'Checking %s ...\n' % filename | ||
| assert stdout == ('Checking %s ...\n' |
There was a problem hiding this comment.
ehm.. there is not much testing added for all these changes.
do you feel confident that all the cases you listed are tested properly? It might be interesting to add specific tests that are only meant to check that --max-configs, --force, -D, --project=.. results in correct behavior
|
|
||
| static std::pair<std::string, std::string> getNameAndVersion(const std::string& productName); | ||
|
|
||
| std::string importCompileDBFile; |
There was a problem hiding this comment.
this can be changed to a bool as far as I see.
000fe9b to
75bd24e
Compare
| 'Checking %s: AAA=1;A2...\n' | ||
| 'Checking %s: AAA=1;A3...\n' % (test_file, test_file, test_file, test_file, test_file)) | ||
|
|
||
| args = [ |
There was a problem hiding this comment.
This is a promising start. I would also like to see tests that check what happens when a --project=compile_commands.json is used.
c29d0f3 to
5d5dafe
Compare
|
|
well those CI failures needs some minor tweaks I assume? |



I have checked the comments on the ticket of the bug. And I simply summarized my logic of checking the configs as below.