From 5488fa80dde94e077d2aa09f6d854c10ebecbec3 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Nov 2022 13:02:41 -0700 Subject: [PATCH] util/glsl2spirv: simplify subprocess handling Since we're not doing anything fancy, we can just use `subprocess.run`. I've also removed the custom error class, we're not going to catch it, so just printing and exiting is fine. v2: - Print stdout as well as stderr in case of a glslang failure Reviewed-by: Luis Felipe Strano Moraes Part-of: --- src/util/glsl2spirv.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/util/glsl2spirv.py b/src/util/glsl2spirv.py index d3851de..bf17f71 100644 --- a/src/util/glsl2spirv.py +++ b/src/util/glsl2spirv.py @@ -24,6 +24,7 @@ from __future__ import annotations import argparse import subprocess +import sys import os import typing as T @@ -39,9 +40,6 @@ if T.TYPE_CHECKING: vn: str stage: str -class ShaderCompileError(RuntimeError): - def __init__(self, *args): - super(ShaderCompileError, self).__init__(*args) def get_args() -> Arguments: parser = argparse.ArgumentParser() @@ -164,17 +162,11 @@ def process_file(args: Arguments) -> None: cmd_list.append(copy_file) - with subprocess.Popen(" ".join(cmd_list), - shell = True, - stdout = subprocess.PIPE, - stderr = subprocess.PIPE, - stdin = subprocess.PIPE) as proc: - - out, err = proc.communicate(timeout=30) - - if proc.returncode != 0: - message = out.decode('utf-8') + '\n' + err.decode('utf-8') - raise ShaderCompileError(message.strip()) + ret = subprocess.run(cmd_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=30) + if ret.returncode != 0: + print(ret.stdout) + print(ret.stderr, file=sys.stderr) + sys.exit(1) if args.vn is not None: postprocess_file(args) -- 2.7.4