(cmd, print_cmd=True)
| 401 | |
| 402 | |
| 403 | def __run_command(cmd, print_cmd=True): |
| 404 | if print_cmd: |
| 405 | print(cmd) |
| 406 | time_start = time.time() |
| 407 | if sys.platform == 'win32': |
| 408 | p = subprocess.Popen(shlex.split(cmd, comments=False, posix=False), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, errors='surrogateescape') |
| 409 | else: |
| 410 | p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, errors='surrogateescape', preexec_fn=os.setsid) |
| 411 | try: |
| 412 | stdout, stderr = p.communicate(timeout=CPPCHECK_TIMEOUT) |
| 413 | return_code = p.returncode |
| 414 | p = None |
| 415 | except subprocess.TimeoutExpired: |
| 416 | import psutil |
| 417 | return_code = RETURN_CODE_TIMEOUT |
| 418 | # terminate all the child processes so we get messages about which files were hanging |
| 419 | child_procs = psutil.Process(p.pid).children(recursive=True) |
| 420 | if len(child_procs) > 0: |
| 421 | for child in child_procs: |
| 422 | child.terminate() |
| 423 | try: |
| 424 | # call with timeout since it might get stuck e.g. gcc-arm-none-eabi |
| 425 | stdout, stderr = p.communicate(timeout=5) |
| 426 | p = None |
| 427 | except subprocess.TimeoutExpired: |
| 428 | pass |
| 429 | finally: |
| 430 | if p: |
| 431 | os.killpg(os.getpgid(p.pid), signal.SIGTERM) # Send the signal to all the process groups |
| 432 | stdout, stderr = p.communicate() |
| 433 | p = None |
| 434 | time_stop = time.time() |
| 435 | elapsed_time = time_stop - time_start |
| 436 | return return_code, stdout, stderr, elapsed_time |
| 437 | |
| 438 | |
| 439 | def scan_package(cppcheck_path, source_path, libraries, capture_callstack=True, enable='style,information', debug_warnings=True, check_level=None, extra_args=None): |
no outgoing calls
no test coverage detected