2025-12-27 06:02:09 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""
|
|
|
|
|
Lightweight repository sanity checks suitable for GitHub Actions.
|
|
|
|
|
This is intentionally NOT a compiler for MQL5 (MetaEditor isn't available on CI).
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
MQL5_DIR = REPO_ROOT / "mt5" / "MQL5"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fail(msg: str) -> None:
|
|
|
|
|
print(f"ERROR: {msg}", file=sys.stderr)
|
|
|
|
|
raise SystemExit(1)
|
|
|
|
|
|
|
|
|
|
|
2026-02-17 10:37:20 +00:00
|
|
|
def validate_repository() -> list[Path]:
|
|
|
|
|
"""
|
|
|
|
|
⚡ Bolt: Optimized repository validation.
|
|
|
|
|
Performs discovery, size checks, and NUL byte detection in a single pass
|
|
|
|
|
using chunked reading to minimize memory footprint and syscalls.
|
|
|
|
|
"""
|
2025-12-27 06:02:09 +00:00
|
|
|
if not MQL5_DIR.exists():
|
|
|
|
|
fail(f"Missing directory: {MQL5_DIR}")
|
|
|
|
|
|
2026-02-17 10:37:20 +00:00
|
|
|
valid_files: list[Path] = []
|
|
|
|
|
|
|
|
|
|
# ⚡ Bolt: Use a single-pass loop for all checks.
|
|
|
|
|
# Recursive glob is efficient in Python 3.12.
|
|
|
|
|
for p in MQL5_DIR.rglob("*"):
|
|
|
|
|
if not p.is_file():
|
|
|
|
|
continue
|
2025-12-27 06:02:09 +00:00
|
|
|
|
2026-02-17 10:37:20 +00:00
|
|
|
suffix = p.suffix.lower()
|
|
|
|
|
if suffix not in {".mq5", ".mqh"}:
|
|
|
|
|
continue
|
2025-12-27 06:02:09 +00:00
|
|
|
|
2026-02-17 10:37:20 +00:00
|
|
|
# ⚡ Bolt: Get metadata once.
|
|
|
|
|
stat = p.stat()
|
|
|
|
|
sz = stat.st_size
|
2025-12-27 06:02:09 +00:00
|
|
|
|
2026-02-17 10:37:20 +00:00
|
|
|
# ⚡ Bolt: Early exit on size check before reading content.
|
2025-12-27 06:02:09 +00:00
|
|
|
if sz > 5_000_000:
|
|
|
|
|
fail(f"Unexpectedly large source file (>5MB): {p.relative_to(REPO_ROOT)} ({sz} bytes)")
|
|
|
|
|
|
2026-02-17 10:37:20 +00:00
|
|
|
# ⚡ Bolt: Use chunked reading for NUL byte detection.
|
|
|
|
|
# This keeps memory usage O(1) regardless of file size (up to 5MB).
|
|
|
|
|
with open(p, 'rb') as f:
|
|
|
|
|
has_nul = False
|
|
|
|
|
while True:
|
|
|
|
|
chunk = f.read(65536) # 64KB chunks
|
|
|
|
|
if not chunk:
|
|
|
|
|
break
|
|
|
|
|
if b"\x00" in chunk:
|
|
|
|
|
has_nul = True
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
if has_nul:
|
|
|
|
|
fail(f"NUL byte found in {p.relative_to(REPO_ROOT)}")
|
|
|
|
|
|
|
|
|
|
valid_files.append(p)
|
|
|
|
|
|
|
|
|
|
if not valid_files:
|
|
|
|
|
fail(f"No .mq5/.mqh files found under {MQL5_DIR}")
|
|
|
|
|
|
|
|
|
|
return sorted(valid_files)
|
|
|
|
|
|
2025-12-27 06:02:09 +00:00
|
|
|
|
|
|
|
|
def main() -> int:
|
2026-02-17 10:37:20 +00:00
|
|
|
# ⚡ Bolt: Consolidated logic into validate_repository()
|
|
|
|
|
files = validate_repository()
|
2025-12-27 06:02:09 +00:00
|
|
|
|
|
|
|
|
rel = [str(p.relative_to(REPO_ROOT)) for p in files]
|
|
|
|
|
print("OK: found source files:")
|
|
|
|
|
for r in rel:
|
|
|
|
|
print(f"- {r}")
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
raise SystemExit(main())
|