build_qt_exe.ps1 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. $PyInstallerBin = if ($env:PYINSTALLER_BIN) { $env:PYINSTALLER_BIN } else { ".\.venv\Scripts\pyinstaller.exe" }
  6. if (-not (Test-Path $PythonBin)) {
  7. Write-Error "Python executable not found: $PythonBin"
  8. }
  9. if (-not (Test-Path $PyInstallerBin)) {
  10. Write-Error "PyInstaller executable not found: $PyInstallerBin`nInstall it with: uv pip install --python .\.venv\Scripts\python.exe pyinstaller"
  11. }
  12. $Version = (& $PythonBin -c "from pathlib import Path; import tomllib; print(tomllib.loads(Path('pyproject.toml').read_text(encoding='utf-8'))['project']['version'])").Trim()
  13. $ArchName = if ([Environment]::Is64BitOperatingSystem) { "x86_64" } else { "x86" }
  14. $MainOutput = "dist/mlog-tool-qt.exe"
  15. $VersionedOutput = "dist/mlog-tool-qt-v$Version-windows-$ArchName.exe"
  16. Write-Host "Building Qt executable with $PyInstallerBin"
  17. $ResetQtPlatform = $false
  18. if (-not $env:QT_QPA_PLATFORM) {
  19. $env:QT_QPA_PLATFORM = "offscreen"
  20. $ResetQtPlatform = $true
  21. }
  22. try {
  23. & $PyInstallerBin --noconfirm --clean mlog_tool_qt.spec
  24. if ($LASTEXITCODE -ne 0) {
  25. exit $LASTEXITCODE
  26. }
  27. Copy-Item $MainOutput $VersionedOutput -Force
  28. }
  29. finally {
  30. if ($ResetQtPlatform) {
  31. Remove-Item Env:QT_QPA_PLATFORM -ErrorAction SilentlyContinue
  32. }
  33. }
  34. Write-Host ""
  35. Write-Host "Build finished:"
  36. Write-Host " $MainOutput"
  37. Write-Host " $VersionedOutput"