Try to compile, link to an executable, and run a program built from 'body' and 'headers'. Returns the exit status code of the program and its output.
(self, body, headers=None, include_dirs=None,
libraries=None, library_dirs=None,
lang="c", use_tee=None)
| 438 | return check_gcc_version_at_least(self, major, minor, patchlevel) |
| 439 | |
| 440 | def get_output(self, body, headers=None, include_dirs=None, |
| 441 | libraries=None, library_dirs=None, |
| 442 | lang="c", use_tee=None): |
| 443 | """Try to compile, link to an executable, and run a program |
| 444 | built from 'body' and 'headers'. Returns the exit status code |
| 445 | of the program and its output. |
| 446 | """ |
| 447 | # 2008-11-16, RemoveMe |
| 448 | warnings.warn("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n" |
| 449 | "Usage of get_output is deprecated: please do not \n" |
| 450 | "use it anymore, and avoid configuration checks \n" |
| 451 | "involving running executable on the target machine.\n" |
| 452 | "+++++++++++++++++++++++++++++++++++++++++++++++++\n", |
| 453 | DeprecationWarning, stacklevel=2) |
| 454 | self._check_compiler() |
| 455 | exitcode, output = 255, '' |
| 456 | try: |
| 457 | grabber = GrabStdout() |
| 458 | try: |
| 459 | src, obj, exe = self._link(body, headers, include_dirs, |
| 460 | libraries, library_dirs, lang) |
| 461 | grabber.restore() |
| 462 | except Exception: |
| 463 | output = grabber.data |
| 464 | grabber.restore() |
| 465 | raise |
| 466 | exe = os.path.join('.', exe) |
| 467 | try: |
| 468 | # specify cwd arg for consistency with |
| 469 | # historic usage pattern of exec_command() |
| 470 | # also, note that exe appears to be a string, |
| 471 | # which exec_command() handled, but we now |
| 472 | # use a list for check_output() -- this assumes |
| 473 | # that exe is always a single command |
| 474 | output = subprocess.check_output([exe], cwd='.') |
| 475 | except subprocess.CalledProcessError as exc: |
| 476 | exitstatus = exc.returncode |
| 477 | output = '' |
| 478 | except OSError: |
| 479 | # preserve the EnvironmentError exit status |
| 480 | # used historically in exec_command() |
| 481 | exitstatus = 127 |
| 482 | output = '' |
| 483 | else: |
| 484 | output = filepath_from_subprocess_output(output) |
| 485 | if hasattr(os, 'WEXITSTATUS'): |
| 486 | exitcode = os.WEXITSTATUS(exitstatus) |
| 487 | if os.WIFSIGNALED(exitstatus): |
| 488 | sig = os.WTERMSIG(exitstatus) |
| 489 | log.error('subprocess exited with signal %d' % (sig,)) |
| 490 | if sig == signal.SIGINT: |
| 491 | # control-C |
| 492 | raise KeyboardInterrupt |
| 493 | else: |
| 494 | exitcode = exitstatus |
| 495 | log.info("success!") |
| 496 | except (CompileError, LinkError): |
| 497 | log.info("failure.") |
no test coverage detected