Skip to content

Instantly share code, notes, and snippets.

@firewave
Last active February 11, 2022 16:33
Show Gist options
  • Save firewave/beaf1c53a9cd5de01cf4ab3c1e526547 to your computer and use it in GitHub Desktop.
Save firewave/beaf1c53a9cd5de01cf4ab3c1e526547 to your computer and use it in GitHub Desktop.
Cppcheck version compare
#!/usr/bin/env python
import os.path
import subprocess
from distutils.version import StrictVersion
input_file = 's:/___temp/input.cpp'
directory = 'c:/Apps/cppcheck_versions'
versions = []
for filename in os.listdir(directory):
f = os.path.join(directory, filename)
if not os.path.isdir(f):
continue
versions.append(filename)
versions.sort(key=StrictVersion)
for version in versions:
exe = os.path.join(directory, version, 'cppcheck')
cmd = exe
cmd += ' --enable=all '
if StrictVersion(version) >= StrictVersion('1.48'):
cmd += '--suppress=missingInclude --suppress=unusedFunction --suppress=unmatchedSuppression '
if StrictVersion(version) >= StrictVersion('1.49'):
cmd += '--inconclusive '
cmd += input_file
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=None, universal_newlines=True)
try:
comm = p.communicate(timeout=2)
except subprocess.TimeoutExpired:
print('timeout')
p.kill()
comm = p.communicate()
print(version)
print(p.returncode)
print(comm[0] + '\n' + comm[1])
@firewave
Copy link
Author

@chrchr-github
Copy link

Sorry, I don't get it. What is this?

@firewave
Copy link
Author

@chrchr-github
I threw this together to run code against multiple versions of Cppcheck.

directory contains versioned folders with the respective Cppcheck release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment