package_windows_dev.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python3
  2. """Package the current Windows Qt dev build, verifying original UI bytes."""
  3. import argparse
  4. import hashlib
  5. import json
  6. from pathlib import Path
  7. import struct
  8. import zipfile
  9. VERSION = "0.8.1.11"
  10. UI_HASHES = {
  11. "src/mainwindow.ui": "e2ed5a4aaadf0d089eab4e4b6791357423482c2adb9ef7c8c7a01f0b1caddabd",
  12. "src/style/app.qss": "b4774ac879b64a07fbb361c5e763e0355ed4cb0051e37c412bec38dcbcba8558",
  13. "src/3rdparty/qcustomplot/qcustomplot.cpp": "364c095b6c1baeda33c43c44d19d15fae011319e3990985c7ac29e26d6ac8ef8",
  14. "src/3rdparty/qcustomplot/qcustomplot.h": "920646e8db6406a568bed52a121db6498a2c507a687400f3a559e3d840f1888c",
  15. "src/3rdparty/qcustomplot/GPL.txt": "8ceb4b9ee5adedde47b31e975c1d90c73ad27b6b165a1dcd80c7c545eb65b903",
  16. "src/resources.qrc": "91cd09e348aa59d0b41e2fb98be51a8fda05df311071b79d0c9ff14c7ea6abe9",
  17. "src/assets/logo-mark.png": "0906929e64e241e08f4de4d1726ce11ea3241dc9f5e60d41096309b817ef043f",
  18. }
  19. def digest(path):
  20. return hashlib.sha256(path.read_bytes()).hexdigest()
  21. def main():
  22. parser = argparse.ArgumentParser()
  23. parser.add_argument("--release", type=Path, required=True)
  24. release = parser.parse_args().release
  25. source = release / "_build-src" / "qt-client"
  26. app = release / "app"
  27. ui_results = {file: {"actual": digest(source / file), "expected": sha}
  28. for file, sha in UI_HASHES.items()}
  29. checks = {
  30. "ui_unchanged": all(row["actual"] == row["expected"] for row in ui_results.values()),
  31. "version_current": f'setApplicationVersion(QStringLiteral("{VERSION}"))' in
  32. (source / "src/main.cpp").read_text(encoding="utf-8"),
  33. "qt_clean_endpoint": json.loads((app / "config.json").read_text(encoding="utf-8"))
  34. .get("backend", {}).get("url") ==
  35. "ws://192.168.2.79:8080/ws?view=qt-clean",
  36. "runtime_dlls": all((app / dll).is_file() for dll in (
  37. "Qt5Core.dll", "Qt5Gui.dll", "Qt5Widgets.dll", "Qt5WebSockets.dll",
  38. "libgcc_s_seh-1.dll", "libstdc++-6.dll", "libwinpthread-1.dll")),
  39. }
  40. binaries = {}
  41. for name, expected_subsystem in (("DDR5_SLT_Monitor.exe", 2), ("QtCleanProbe.exe", 3)):
  42. path = app / name
  43. data = path.read_bytes()
  44. pointer = struct.unpack_from("<I", data, 0x3C)[0]
  45. machine = struct.unpack_from("<H", data, pointer + 4)[0]
  46. subsystem = struct.unpack_from("<H", data, pointer + 24 + 68)[0]
  47. checks[name] = machine == 0x8664 and subsystem == expected_subsystem
  48. binaries[name] = {"bytes": len(data), "sha256": digest(path)}
  49. if not all(checks.values()):
  50. print(json.dumps({"passed": False, "checks": checks, "ui_mismatches":
  51. {file: row for file, row in ui_results.items() if row["actual"] != row["expected"]}},
  52. ensure_ascii=False))
  53. raise SystemExit(1)
  54. archive = release / f"XJKJ-STL-Qt-Clean-Windows-x64-{VERSION}.zip"
  55. with zipfile.ZipFile(archive, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as target:
  56. for path in sorted(app.rglob("*")):
  57. if path.is_file():
  58. target.write(path, path.relative_to(release))
  59. print(json.dumps({"passed": True, "checks": checks, "ui_files_checked": len(UI_HASHES),
  60. "binaries": binaries, "archive": str(archive), "archive_bytes": archive.stat().st_size,
  61. "archive_sha256": digest(archive)}, ensure_ascii=False, indent=2))
  62. if __name__ == "__main__":
  63. main()