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-21 17:22:32 +00:00
|
|
|
# ⚡ Bolt: Consolidated file discovery and validation into a single pass for better performance.
|
|
|
|
|
def validate_files() -> list[Path]:
|
2025-12-27 06:02:09 +00:00
|
|
|
if not MQL5_DIR.exists():
|
|
|
|
|
fail(f"Missing directory: {MQL5_DIR}")
|
2026-02-21 17:22:32 +00:00
|
|
|
|
2025-12-27 06:02:09 +00:00
|
|
|
files: list[Path] = []
|
2026-02-21 17:22:32 +00:00
|
|
|
# ⚡ Bolt: Recursive globs like rglob('*') followed by suffix filtering are generally
|
|
|
|
|
# more efficient as they avoid repeated traversals of the file system tree.
|
2025-12-27 06:02:09 +00:00
|
|
|
for p in MQL5_DIR.rglob("*"):
|
|
|
|
|
if p.is_file() and p.suffix.lower() in {".mq5", ".mqh"}:
|
2026-02-21 17:22:32 +00:00
|
|
|
# ⚡ Bolt: Early size check using metadata only to avoid opening large files.
|
|
|
|
|
sz = p.stat().st_size
|
|
|
|
|
if sz > 5_000_000:
|
|
|
|
|
fail(f"Unexpectedly large source file (>5MB): {p.relative_to(REPO_ROOT)} ({sz} bytes)")
|
|
|
|
|
|
|
|
|
|
# ⚡ Bolt: Use chunked binary reading to detect NUL bytes with constant memory footprint.
|
|
|
|
|
# This is significantly faster and more memory-efficient than reading the whole file.
|
|
|
|
|
with open(p, "rb") as f:
|
|
|
|
|
while chunk := f.read(65536): # 64KB chunks
|
|
|
|
|
if b"\x00" in chunk:
|
|
|
|
|
fail(f"NUL byte found in {p.relative_to(REPO_ROOT)}")
|
|
|
|
|
|
2025-12-27 06:02:09 +00:00
|
|
|
files.append(p)
|
2026-02-21 17:22:32 +00:00
|
|
|
|
2025-12-27 06:02:09 +00:00
|
|
|
if not files:
|
|
|
|
|
fail(f"No .mq5/.mqh files found under {MQL5_DIR}")
|
|
|
|
|
|
2026-02-21 17:22:32 +00:00
|
|
|
return sorted(files)
|
2025-12-27 06:02:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> int:
|
2026-02-21 17:22:32 +00:00
|
|
|
# ⚡ Bolt: Replaced multi-pass check functions with a single-pass validator.
|
|
|
|
|
files = validate_files()
|
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())
|