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 <luis.strano@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19449>
This commit is contained in:
Dylan Baker
2022-11-01 13:02:41 -07:00
committed by Marge Bot
parent 87c83c041a
commit 5488fa80dd

View 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)