Skip to content

Commit

Permalink
Added Crinkler support to entropy.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStahL committed Apr 15, 2024
1 parent c51c2ec commit bab8916
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion shader_minifier/entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
QVariant,
)
from time import sleep
from traceback import print_exc


class LinkerType(IntEnum):
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit bab8916

Please sign in to comment.