plate-config-app/build_exe.ps1
Danil Iarosh 35c9693740 fix: stabilize OTA updates in v2.0.2
- Исправлен перезапуск приложения после замены файлов и добавлено подтверждение запуска новой версии.
- Обеспечены откат при ошибке и корректное завершение фоновых задач.
- Исключены посторонние DLL из Windows-сборки, обновлены тесты и инструкция ручного перехода с v2.0.1.
2026-09-17 10:30:18 +03:00

118 lines
4.5 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

param(
[switch]$InstallBuildDeps,
[switch]$CleanOnly
)
$ErrorActionPreference = "Stop"
$projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $projectRoot
# ── Очистка артефактов сборки ──────────────────────────────────────
function Clean-Build {
$dirs = @("build", "dist")
foreach ($d in $dirs) {
$path = Join-Path $projectRoot $d
if (Test-Path $path) {
Remove-Item $path -Recurse -Force
Write-Host " Удалено: $d"
}
}
# __pycache__ в проекте (без .venv)
Get-ChildItem -Path $projectRoot -Directory -Filter "__pycache__" -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -notlike "*\.venv\*" } |
Sort-Object { $_.FullName.Length } -Descending |
ForEach-Object {
if (Test-Path -LiteralPath $_.FullName) {
Remove-Item -LiteralPath $_.FullName -Recurse -Force
Write-Host " Удалено: $($_.FullName -replace [regex]::Escape($projectRoot), '.')"
}
}
Write-Host "Очистка завершена."
}
Write-Host "=== Очистка ==="
Clean-Build
if ($CleanOnly) {
exit 0
}
# ── Виртуальное окружение ──────────────────────────────────────────
$venvPython = Join-Path $projectRoot ".venv\Scripts\python.exe"
if (-not (Test-Path $venvPython)) {
throw "Не найдено виртуальное окружение .venv. Создайте его перед сборкой."
}
if ($InstallBuildDeps) {
Write-Host ""
Write-Host "=== Установка зависимостей ==="
& $venvPython -m pip install --upgrade pip
& $venvPython -m pip install -r requirements-build.txt
}
# ── Сборка ─────────────────────────────────────────────────────────
Write-Host ""
Write-Host "=== Сборка EXE ==="
$pythonHome = (& $venvPython -c "import sys; print(sys.base_prefix)").Trim()
if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath $pythonHome -PathType Container)) {
throw "Не удалось определить каталог Python для сборки."
}
$buildPath = @(
(Split-Path -Parent $venvPython),
$pythonHome,
(Join-Path $pythonHome "DLLs"),
(Join-Path $env:SystemRoot "System32"),
$env:SystemRoot
) -join ";"
$originalPath = $env:PATH
try {
$env:PATH = $buildPath
& $venvPython -m PyInstaller --noconfirm --clean plate_config_app.spec
$buildExitCode = $LASTEXITCODE
} finally {
$env:PATH = $originalPath
}
if ($buildExitCode -ne 0) {
throw "PyInstaller завершился с ошибкой (код $buildExitCode)."
}
$builtExe = Join-Path $projectRoot "dist\plate_config_app.exe"
if (-not (Test-Path $builtExe)) {
throw "EXE не найден после сборки."
}
$exe = Join-Path $projectRoot "dist\plate_config_app-windows-x86_64.exe"
Move-Item -LiteralPath $builtExe -Destination $exe -Force
# ── Копирование ресурсных папок рядом с EXE ───────────────────────
Write-Host ""
Write-Host "=== Копирование ресурсов ==="
$resourceFolders = @("light_modes", "input_mappings", "commands")
foreach ($folder in $resourceFolders) {
$src = Join-Path $projectRoot $folder
$dst = Join-Path $projectRoot "dist\$folder"
if (Test-Path $src) {
Copy-Item $src -Destination $dst -Recurse -Force
Write-Host " Скопировано: $folder"
} else {
Write-Host " Пропущено (не найдено): $folder" -ForegroundColor Yellow
}
}
$archive = Join-Path $projectRoot "dist\plate_config_app-windows-x86_64.zip"
$archiveEntries = @($exe)
foreach ($folder in $resourceFolders) {
$resourcePath = Join-Path $projectRoot "dist\$folder"
if (Test-Path $resourcePath) {
$archiveEntries += $resourcePath
}
}
Compress-Archive -LiteralPath $archiveEntries -DestinationPath $archive -Force
$size = [math]::Round((Get-Item $exe).Length / 1MB, 1)
$archiveSize = [math]::Round((Get-Item $archive).Length / 1MB, 1)
Write-Host ""
Write-Host "Сборка завершена: $exe ($size MB)"
Write-Host "ZIP-архив: $archive ($archiveSize MB)"