MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / cppcheck_ex

Function cppcheck_ex

test/cli/testutils.py:168–248  ·  view source on GitHub ↗
(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_exe=None, timeout=None, tty=False)

Source from the content-addressed store, hash-verified

166
167# Run Cppcheck with args
168def cppcheck_ex(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_exe=None, timeout=None, tty=False):
169 exe = cppcheck_exe if cppcheck_exe else __lookup_cppcheck_exe()
170 assert exe is not None, 'no cppcheck binary found'
171
172 # do not inject arguments for calls with exclusive options
173 has_exclusive = bool({'--doc', '--errorlist', '-h', '--help', '--version'} & set(args))
174
175 if not has_exclusive and ('TEST_CPPCHECK_INJECT_J' in os.environ):
176 found_j = False
177 for arg in args:
178 if arg.startswith('-j'):
179 found_j = True
180 break
181 if not found_j:
182 arg_j = '-j' + str(os.environ['TEST_CPPCHECK_INJECT_J'])
183 args.append(arg_j)
184
185 if not has_exclusive and ('TEST_CPPCHECK_INJECT_CLANG' in os.environ):
186 found_clang = False
187 for arg in args:
188 if arg.startswith('--clang'):
189 found_clang = True
190 break
191 if not found_clang:
192 arg_clang = '--clang=' + str(os.environ['TEST_CPPCHECK_INJECT_CLANG'])
193 args.append(arg_clang)
194
195 if not has_exclusive and ('TEST_CPPCHECK_INJECT_EXECUTOR' in os.environ):
196 found_jn = False
197 found_executor = False
198 for arg in args:
199 if arg.startswith('-j') and arg != '-j1':
200 found_jn = True
201 continue
202 if arg.startswith('--executor'):
203 found_executor = True
204 continue
205 # only add '--executor' if we are actually using multiple jobs
206 if found_jn and not found_executor:
207 arg_executor = '--executor=' + str(os.environ['TEST_CPPCHECK_INJECT_EXECUTOR'])
208 args.append(arg_executor)
209
210 builddir_tmp = None
211
212 if not has_exclusive and ('TEST_CPPCHECK_INJECT_BUILDDIR' in os.environ):
213 found_builddir = False
214 for arg in args:
215 if arg.startswith('--cppcheck-build-dir=') or arg == '--no-cppcheck-build-dir':
216 found_builddir = True
217 break
218 if not found_builddir:
219 builddir_tmp = tempfile.TemporaryDirectory(prefix=str(os.environ['TEST_CPPCHECK_INJECT_BUILDDIR']))
220 arg_clang = '--cppcheck-build-dir=' + builddir_tmp.name
221 args.append(arg_clang)
222
223 logging.info(exe + ' ' + ' '.join(args))
224
225 run_subprocess = __run_subprocess_tty if tty else __run_subprocess

Calls 7

setFunction · 0.85
strFunction · 0.85
cleanupMethod · 0.80
__lookup_cppcheck_exeFunction · 0.70
joinMethod · 0.45
replaceMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected