$ErrorActionPreference = "Stop" $RootDir = Split-Path -Parent $PSScriptRoot Set-Location $RootDir $PythonBin = if ($env:PYTHON_BIN) { $env:PYTHON_BIN } else { ".\.venv\Scripts\python.exe" } if (-not (Test-Path $PythonBin)) { Write-Error "Python executable not found: $PythonBin" } if ($env:PYINSTALLER_BIN) { $PyInstallerBin = $env:PYINSTALLER_BIN if (-not (Test-Path $PyInstallerBin)) { Write-Error "PyInstaller executable not found: $PyInstallerBin" } $PyInstallerDescription = $PyInstallerBin } else { & $PythonBin -c "import PyInstaller" *> $null if ($LASTEXITCODE -ne 0) { Write-Error "PyInstaller is not installed in: $PythonBin`nInstall it with: uv pip install --python .\.venv\Scripts\python.exe pyinstaller" } $PyInstallerDescription = "$PythonBin -m PyInstaller" } $Version = (& $PythonBin -c "from pathlib import Path; import tomllib; print(tomllib.loads(Path('pyproject.toml').read_text(encoding='utf-8'))['project']['version'])").Trim() $ArchName = if ([Environment]::Is64BitOperatingSystem) { "x86_64" } else { "x86" } $MainOutput = "dist/mlog-tool-qt.exe" $VersionedOutput = "dist/mlog-tool-qt-v$Version-windows-$ArchName.exe" Write-Host "Building Qt executable with $PyInstallerDescription" $ResetQtPlatform = $false if (-not $env:QT_QPA_PLATFORM) { $env:QT_QPA_PLATFORM = "offscreen" $ResetQtPlatform = $true } try { if ($env:PYINSTALLER_BIN) { & $PyInstallerBin --noconfirm --clean mlog_tool_qt.spec } else { & $PythonBin -m PyInstaller --noconfirm --clean mlog_tool_qt.spec } if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } Copy-Item $MainOutput $VersionedOutput -Force } finally { if ($ResetQtPlatform) { Remove-Item Env:QT_QPA_PLATFORM -ErrorAction SilentlyContinue } } Write-Host "" Write-Host "Build finished:" Write-Host " $MainOutput" Write-Host " $VersionedOutput"