util/glsl2spirv: simplify subprocess handling
authorDylan Baker <dylan.c.baker@intel.com>
Tue, 1 Nov 2022 20:02:41 +0000 (13:02 -0700)
committerMarge Bot <emma+marge@anholt.net>
Thu, 10 Nov 2022 21:14:17 +0000 (21:14 +0000)
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 <luis.strano@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19449>

src/util/glsl2spirv.py

index d3851de..bf17f71 100644 (file)
@@ -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)