| 1251 | utils.delete_contents(shared.EMSCRIPTEN_TEMP_DIR) |
| 1252 | |
| 1253 | def run_process(self, cmd, check=True, **kwargs): |
| 1254 | # Wrapper around utils.run_process. This is desirable so that the tests |
| 1255 | # can fail (in the unittest sense) rather than error'ing. |
| 1256 | # In the long run it would nice to completely remove the dependency on |
| 1257 | # core emscripten code (shared.py) here. |
| 1258 | |
| 1259 | # Handle buffering for subprocesses. The python unittest buffering mechanism |
| 1260 | # will only buffer output from the current process (by overriding sys.stdout |
| 1261 | # and sys.stderr), not from sub-processes. |
| 1262 | stdout_buffering = 'stdout' not in kwargs and isinstance(sys.stdout, io.StringIO) |
| 1263 | stderr_buffering = 'stderr' not in kwargs and isinstance(sys.stderr, io.StringIO) |
| 1264 | if stdout_buffering: |
| 1265 | kwargs['stdout'] = PIPE |
| 1266 | if stderr_buffering: |
| 1267 | kwargs['stderr'] = PIPE |
| 1268 | |
| 1269 | try: |
| 1270 | rtn = utils.run_process(cmd, check=check, **kwargs) |
| 1271 | except subprocess.CalledProcessError as e: |
| 1272 | if check and e.returncode != 0: |
| 1273 | print(e.stdout) |
| 1274 | print(e.stderr) |
| 1275 | self.fail(f'subprocess exited with non-zero return code({e.returncode}): `{shlex.join(cmd)}`') |
| 1276 | |
| 1277 | if stdout_buffering: |
| 1278 | sys.stdout.write(rtn.stdout) |
| 1279 | # When we inject stdout/stderr buffering for our own internal purposes, we do not also want to |
| 1280 | # make it available on the returned object. |
| 1281 | # If we don't do this then callers would have access to rtn.stdout/rtn.stderr even when they |
| 1282 | # didn't request it (i.e. even when they did not pass stderr=PIPE), which can lead to tests |
| 1283 | # that pass in buffering mode, but fail without it. |
| 1284 | rtn.stdout = None |
| 1285 | if stderr_buffering: |
| 1286 | sys.stderr.write(rtn.stderr) |
| 1287 | rtn.stderr = None |
| 1288 | return rtn |
| 1289 | |
| 1290 | def emcc(self, filename, args=[], **kwargs): # noqa |
| 1291 | filename = maybe_test_file(filename) |