|
13 | 13 | import contextlib
|
14 | 14 | import difflib
|
15 | 15 | import hashlib
|
| 16 | +import io |
16 | 17 | import itertools
|
17 | 18 | import logging
|
18 | 19 | import multiprocessing
|
@@ -1763,19 +1764,36 @@ def clear(self):
|
1763 | 1764 | if shared.EMSCRIPTEN_TEMP_DIR:
|
1764 | 1765 | utils.delete_contents(shared.EMSCRIPTEN_TEMP_DIR)
|
1765 | 1766 |
|
1766 |
| - def run_process(self, cmd, check=True, **args): |
| 1767 | + def run_process(self, cmd, check=True, **kwargs): |
1767 | 1768 | # Wrapper around shared.run_process. This is desirable so that the tests
|
1768 | 1769 | # can fail (in the unittest sense) rather than error'ing.
|
1769 | 1770 | # In the long run it would nice to completely remove the dependency on
|
1770 | 1771 | # core emscripten code (shared.py) here.
|
| 1772 | + |
| 1773 | + # Handle buffering for subprocesses. The python unittest buffering mechanism |
| 1774 | + # will only buffer output from the current process (by overwriding sys.stdout |
| 1775 | + # and sys.stderr), not from sub-processes. |
| 1776 | + stdout_buffering = 'stdout' not in kwargs and isinstance(sys.stdout, io.StringIO) |
| 1777 | + stderr_buffering = 'stderr' not in kwargs and isinstance(sys.stderr, io.StringIO) |
| 1778 | + if stdout_buffering: |
| 1779 | + kwargs['stdout'] = PIPE |
| 1780 | + if stderr_buffering: |
| 1781 | + kwargs['stderr'] = PIPE |
| 1782 | + |
1771 | 1783 | try:
|
1772 |
| - return shared.run_process(cmd, check=check, **args) |
| 1784 | + rtn = shared.run_process(cmd, check=check, **kwargs) |
1773 | 1785 | except subprocess.CalledProcessError as e:
|
1774 | 1786 | if check and e.returncode != 0:
|
1775 | 1787 | print(e.stdout)
|
1776 | 1788 | print(e.stderr)
|
1777 | 1789 | self.fail(f'subprocess exited with non-zero return code({e.returncode}): `{shlex.join(cmd)}`')
|
1778 | 1790 |
|
| 1791 | + if stdout_buffering: |
| 1792 | + sys.stdout.write(rtn.stdout) |
| 1793 | + if stderr_buffering: |
| 1794 | + sys.stderr.write(rtn.stderr) |
| 1795 | + return rtn |
| 1796 | + |
1779 | 1797 | def emcc(self, filename, args=[], output_filename=None, **kwargs): # noqa
|
1780 | 1798 | compile_only = '-c' in args or '-sSIDE_MODULE' in args
|
1781 | 1799 | cmd = [compiler_for(filename), filename] + self.get_cflags(compile_only=compile_only) + args
|
|
0 commit comments