cppcheck: use file list and add -j option with available processors#73
Open
mdeweerd wants to merge 11 commits into
Open
cppcheck: use file list and add -j option with available processors#73mdeweerd wants to merge 11 commits into
mdeweerd wants to merge 11 commits into
Conversation
- Create a temporary file with the list of all files to check - Pass the file list to cppcheck using --file-list option - Automatically add -j option with number of available processors - Only add -j if not already provided in pre-commit arguments - Add unit tests for -j option behavior - Add integration test cases for -j and -j2 options
cppcheck cannot use unusedFunction check with -j (parallel processing). This fix ensures that when -j is added (either automatically or by user), the unusedFunction suppression is not included to avoid the conflict. The test was failing because cppcheck was printing: 'cppcheck: unusedFunction check can't be used with '-j' option. Disabling unusedFunction check.' This change removes the unusedFunction suppression when -j is present, allowing parallel processing to work correctly.
Add regex filters to remove warning messages about unusedFunction check conflicting with -j option in newer versions of cppcheck. Closes #
- Add --cppcheck-build-dir when using -j option to enable unusedFunction - Handle cases where -j is user-provided or auto-added - Ensure unusedFunction suppression is only added when safe - Use --file-list for passing multiple files to cppcheck This fixes the warning: 'cppcheck: unusedFunction check requires --cppcheck-build-dir to be active with -j.' Closes #
- When -j is 1 or not specified: suppress unusedFunction (no build dir needed) - When -j > 1 and user didn't provide --cppcheck-build-dir: add it automatically - When -j > 1 and user provided --cppcheck-build-dir: suppress unusedFunction - Only auto-add -j if num_cpus > 1 (skip for single-core systems) This ensures unusedFunction check works correctly in all scenarios. Closes #
- Create unique temporary directory with tempfile.mkdtemp(prefix='cppcheck_') - Store build dir path in self.cppcheck_build_dir for cleanup - Clean up temporary directory after cppcheck runs - Properly use add_if_missing for --cppcheck-build-dir option This ensures each cppcheck run gets its own unique build directory. Closes #
- Use shutil.rmtree() instead of os.rmdir() for recursive directory removal - Add cleanup_build_dir() method for proper cleanup - Call cleanup in finally block of run() method - Call cleanup in finally block of main() for exception safety - Ensures temp dir is removed even on KeyboardInterrupt or other exceptions Closes #
Since we now automatically add --cppcheck-build-dir when using -j > 1, we can safely always suppress unusedFunction just like the other suppressions (unmatchedSuppression, missingIncludeSystem). This fixes the test_cppcheck_default_args_added regression test. Closes #
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
In CI, I enabled
cppcheckcaching by adding the--cppcheck-build-diroption, but that did not work as every file was analysed in a separatecppcheckcall.The changes avoids splitting the analysis in multiple batches, and has all the files analysed in a single cppcheck call (which itself creates multiple subprocesses).
Summary of the changes
--file-listoption to pass multiple files to cppcheck in a single invocation-joption with number of available processors for parallel analysis--cppcheck-build-dirwhen using-j > 1to enableunusedFunctioncheck compatibilityunusedFunctionwarnings (now safe due to--cppcheck-build-dirhandling)tempfile.mkdtemp()shutil.rmtree()even on interruptionChanges
hooks/cppcheck.pyto use--file-listoption instead of running cppcheck once per file-j Noption with CPU count (only on multi-core systems)--cppcheck-build-dircreation when using-j > 1--suppress=unusedFunction(previously conditional)shutil.rmtree()tests/test_hooks.pyto handle cppcheck warning messagesExtra Info
--suppress=unusedFunction is no longer needed
As we add the
--cppcheck-build-dirwhen missing if-jis > 1, there is no longer an issue with the analysis.Verification
-jandunusedFunctionconflicts