Add Quirrel script checks and a GUI build command
Compile the upstream Quirrel checker with MSVC and invoke syntax and static analysis for each input file. Treat reported errors and warnings as failures because the checker can return a zero exit code for them. Split the command line by purpose and add GUI pack construction from declared edits and injected scripts. Verify the checker against stock scripts and invalid inputs, and confirm that patch checks still run.
This commit is contained in:
1 parent
8fa50b7804
commit
b6d72f4792
8 files changed
+290
-16
No files matched your search
@@ -0,0 +1,46 @@
|
||||
"""Run the Quirrel syntax checker over script files.
|
||||
|
||||
Each file is parsed and run through Quirrel's static analyzer (`-syntax-check -sa`), in its
|
||||
own process so a failure is attributed to exactly one file and one bad file cannot hide the
|
||||
others. Analyzer warnings (unused bindings, suspicious expressions) count as failures: the
|
||||
files we check are our own, and we keep them clean.
|
||||
|
||||
Not covered: names that are not defined anywhere. Quirrel reports those only when it fully
|
||||
compiles a file, and full compilation resolves imports, which needs the game's native modules.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ScriptFailure:
|
||||
path: Path
|
||||
message: str
|
||||
|
||||
|
||||
def check_scripts(checker: Path, files: list[Path]) -> list[ScriptFailure]:
|
||||
"""Return one ScriptFailure per file that does not parse; an empty list means all passed."""
|
||||
failures: list[ScriptFailure] = []
|
||||
for path in files:
|
||||
completed = subprocess.run([str(checker), "-syntax-check", "-sa", str(path)], capture_output=True, text=True)
|
||||
output = (completed.stderr + completed.stdout).strip()
|
||||
if completed.returncode != 0 or _reports_problem(output):
|
||||
failures.append(ScriptFailure(path, output or f"exit code {completed.returncode}"))
|
||||
return failures
|
||||
|
||||
|
||||
def _reports_problem(output: str) -> bool:
|
||||
# sq.exe exits with 0 even when parsing fails; it then prints "Error [...]" on stderr.
|
||||
# Analyzer findings start with "WARNING:".
|
||||
return any(line.startswith(("Error [", "WARNING:")) for line in output.splitlines())
|
||||
|
||||
|
||||
def find_scripts(roots: list[Path]) -> list[Path]:
|
||||
"""Expand directories into the .nut files under them; files are taken as given."""
|
||||
found: list[Path] = []
|
||||
for root in roots:
|
||||
found.extend(sorted(root.rglob("*.nut")) if root.is_dir() else [root])
|
||||
return found
|
||||
Reference in new issue
Block a user