cppcheck: use file list and add -j option with available processors#73
cppcheck: use file list and add -j option with available processors#73mdeweerd wants to merge 1 commit into
Conversation
|
Hi mdewweerd, Thanks for writing this up. The core idea of a single cppcheck invocation instead of one-per-file is a genuine improvement and I appreciate the thorough writeup. A few things are blocking merge for me, in roughly descending order of importance. I've generated this with my SOTA model of choice, but feel free to push back if it's missing the mark. The unusedFunction failing on a partial set of files due to how pre-commit stages files makes suppressing this flag seem like the correct behavior. I ran the PR head (
|
fddd8b8 to
1b4abb7
Compare
1. Dropping
|
|
Thanks for the revision. This addresses most of the review. #1 is fixed (dropping There are two # cppcheck.py:77-78 (set_j_value)
self.cppcheck_build_dir = tempfile.mkdtemp(prefix="cppcheck_") # dir A
self.args.extend(["-j", str(num_cpus)]) # note: --cppcheck-build-dir is NOT addedThen # cppcheck.py:91-95
has_build_dir = any(arg.startswith("--cppcheck-build-dir") for arg in self.args) # False — A was never added
if not has_build_dir:
self.cppcheck_build_dir = tempfile.mkdtemp(prefix="cppcheck_") # dir B, reference to A is now lost
self.add_if_missing([f"--cppcheck-build-dir={self.cppcheck_build_dir}"])
Minimal repro — invoke the hook exactly as pre-commit does and count what's left behind: T=$(python3 -c 'import tempfile;print(tempfile.gettempdir())')
before=$(ls -d "$T"/cppcheck_* 2>/dev/null | wc -l)
printf 'int add(int a,int b){return a+b;}\n' > "$T/helper.c"
for i in 1 2 3; do python3 -m hooks.cppcheck cppcheck-hook "$T/helper.c" >/dev/null 2>&1; done
echo "leaked: $(( $(ls -d "$T"/cppcheck_* 2>/dev/null | wc -l) - before ))"I see Three commits, three orphaned temp dirs will create one per invocation, indefinitely. This isn't that big of a deal because these will be cleaned on restart, but it's cruft we don't need to create. The fix is small: drop the |
- Add parallel processing support with -j option (defaults to # processors) - Implement temporary build directory for parallel processing (when -j > 1) - Update default arguments for cppcheck (unusedFunction check disabled, no need ot ignore) - Improve error handling and cleanup (cppcheck) - Update tests to verify parallel processing functionality
1b4abb7 to
126c17f
Compare
|
I removed the mkdtemp from set_j_option and reinforced checks prior to creating the directory. |
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