From bab8916e46917d75179fc1dff49d012e56e7a0e3 Mon Sep 17 00:00:00 2001 From: Alexander Kraus Date: Mon, 15 Apr 2024 20:48:07 +0200 Subject: [PATCH] Added Crinkler support to entropy. --- shader_minifier/entropy.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/shader_minifier/entropy.py b/shader_minifier/entropy.py index 0735ea0..36e3887 100644 --- a/shader_minifier/entropy.py +++ b/shader_minifier/entropy.py @@ -23,6 +23,7 @@ QVariant, ) from time import sleep +from traceback import print_exc class LinkerType(IntEnum): @@ -81,9 +82,38 @@ def _run(self: Self) -> int: if result.returncode == 0: output: str = result.stdout.decode('utf-8').strip() - [data_size, _, _] = parse("{} + {} = {}", output) + data_size: Optional[float] = None + parsed: bool = False + + # Attempt to parse Cold output format. + try: + [data_size, _, _] = parse( + "{} + {} = {}", + output, + ) + parsed = True + except: + pass + + # Attempt to parse Crinkler output format. + lines: List[str] = list(filter( + lambda line: line.lstrip().startswith("Ideal compressed size of data:"), + output.splitlines(), + )) + if len(lines) != 0: + [data_size] = parse( + "Ideal compressed size of data: {}", + lines[0].lstrip().rstrip(), + ) + parsed = True + + if not parsed: + print("Could not parse build output:") + print(output) + self._versions[hash] = data_size except: + print_exc() self._versions[hash] = 'Errored' self.built.emit(self)