Files
matrix-screen-controller/发布更新相关/镜像编辑器/编辑器源代码/build_windows.ps1
T

70 lines
3.0 KiB
PowerShell

param(
[string]$Python = "python",
[string]$BuildEnvironment = ""
)
$ErrorActionPreference = "Stop"
$sourceRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$buildRoot = Join-Path $sourceRoot ".build"
$programRoot = [System.IO.Path]::GetFullPath((Join-Path $sourceRoot "..\编辑器程序"))
if ($BuildEnvironment) {
$pythonExe = [System.IO.Path]::GetFullPath((Join-Path $BuildEnvironment "Scripts\python.exe"))
if (-not (Test-Path -LiteralPath $pythonExe)) {
throw "指定的构建环境不存在:$BuildEnvironment"
}
} else {
$venvRoot = Join-Path $sourceRoot ".build-venv"
$pythonExe = Join-Path $venvRoot "Scripts\python.exe"
if (-not (Test-Path -LiteralPath $pythonExe)) {
& $Python -m venv $venvRoot
}
& $pythonExe -m pip install --disable-pip-version-check --requirement (Join-Path $sourceRoot "requirements-build.txt")
}
& $pythonExe -c "import PyInstaller, PySide6; assert PyInstaller.__version__ == '6.22.2'; assert PySide6.__version__ == '6.11.2'"
if ($LASTEXITCODE -ne 0) { throw "构建依赖版本校验失败" }
$env:PYTHONPATH = Join-Path $sourceRoot "src"
& $pythonExe -m unittest discover -s (Join-Path $sourceRoot "tests") -v
if ($LASTEXITCODE -ne 0) { throw "镜像编辑器单元测试失败" }
New-Item -ItemType Directory -Path $buildRoot -Force | Out-Null
$distRoot = Join-Path $buildRoot "dist"
$workRoot = Join-Path $buildRoot "work"
$specRoot = Join-Path $buildRoot "spec"
New-Item -ItemType Directory -Path $distRoot,$workRoot,$specRoot -Force | Out-Null
$originalPath = $env:PATH
try {
# Avoid collecting unrelated DLLs from the caller's PATH (for example another app's ICU build).
$env:PATH = "$env:SystemRoot\System32;$env:SystemRoot"
& $pythonExe -m PyInstaller `
--noconfirm `
--clean `
--onefile `
--console `
--hide-console=hide-early `
--name "核桃派镜像配置编辑器" `
--version-file (Join-Path $sourceRoot "windows_version_info.txt") `
--paths (Join-Path $sourceRoot "src") `
--distpath $distRoot `
--workpath $workRoot `
--specpath $specRoot `
(Join-Path $sourceRoot "editor_main.py")
if ($LASTEXITCODE -ne 0) { throw "PyInstaller 构建失败" }
} finally {
$env:PATH = $originalPath
}
$artifact = Join-Path $distRoot "核桃派镜像配置编辑器.exe"
if (-not (Test-Path -LiteralPath $artifact)) {
throw "PyInstaller 未生成目标 EXE"
}
New-Item -ItemType Directory -Path $programRoot -Force | Out-Null
Copy-Item -LiteralPath $artifact -Destination (Join-Path $programRoot "核桃派镜像配置编辑器.exe") -Force
[System.IO.File]::WriteAllText((Join-Path $programRoot "VERSION"), "2.0.0`n", [System.Text.UTF8Encoding]::new($false))
$hash = (Get-FileHash -LiteralPath (Join-Path $programRoot "核桃派镜像配置编辑器.exe") -Algorithm SHA256).Hash.ToLowerInvariant()
[System.IO.File]::WriteAllText((Join-Path $programRoot "SHA256SUMS"), "$hash 核桃派镜像配置编辑器.exe`n", [System.Text.UTF8Encoding]::new($false))
Write-Output "已生成:$programRoot"