build_qt_exe.ps1 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. $ErrorActionPreference = "Stop"
  2. $RootDir = Split-Path -Parent $PSScriptRoot
  3. Set-Location $RootDir
  4. $PythonBin = if ($env:PYTHON_BIN) { $env:PYTHON_BIN } else { ".\.venv\Scripts\python.exe" }
  5. if (-not (Test-Path $PythonBin)) {
  6. Write-Error "Python executable not found: $PythonBin"
  7. }
  8. if ($env:PYINSTALLER_BIN) {
  9. $PyInstallerBin = $env:PYINSTALLER_BIN
  10. if (-not (Test-Path $PyInstallerBin)) {
  11. Write-Error "PyInstaller executable not found: $PyInstallerBin"
  12. }
  13. $PyInstallerDescription = $PyInstallerBin
  14. } else {
  15. & $PythonBin -c "import PyInstaller" *> $null
  16. if ($LASTEXITCODE -ne 0) {
  17. Write-Error "PyInstaller is not installed in: $PythonBin`nInstall it with: uv pip install --python .\.venv\Scripts\python.exe pyinstaller"
  18. }
  19. $PyInstallerDescription = "$PythonBin -m PyInstaller"
  20. }
  21. $Version = (& $PythonBin -c "from pathlib import Path; import tomllib; print(tomllib.loads(Path('pyproject.toml').read_text(encoding='utf-8'))['project']['version'])").Trim()
  22. $ArchName = if ([Environment]::Is64BitOperatingSystem) { "x86_64" } else { "x86" }
  23. $MainOutput = "dist/mlog-tool-qt.exe"
  24. $VersionedOutput = "dist/mlog-tool-qt-v$Version-windows-$ArchName.exe"
  25. Write-Host "Building Qt executable with $PyInstallerDescription"
  26. $ResetQtPlatform = $false
  27. if (-not $env:QT_QPA_PLATFORM) {
  28. $env:QT_QPA_PLATFORM = "offscreen"
  29. $ResetQtPlatform = $true
  30. }
  31. try {
  32. if ($env:PYINSTALLER_BIN) {
  33. & $PyInstallerBin --noconfirm --clean mlog_tool_qt.spec
  34. } else {
  35. & $PythonBin -m PyInstaller --noconfirm --clean mlog_tool_qt.spec
  36. }
  37. if ($LASTEXITCODE -ne 0) {
  38. exit $LASTEXITCODE
  39. }
  40. Copy-Item $MainOutput $VersionedOutput -Force
  41. }
  42. finally {
  43. if ($ResetQtPlatform) {
  44. Remove-Item Env:QT_QPA_PLATFORM -ErrorAction SilentlyContinue
  45. }
  46. }
  47. Write-Host ""
  48. Write-Host "Build finished:"
  49. Write-Host " $MainOutput"
  50. Write-Host " $VersionedOutput"