Files
Udisk-backup-win64/tools/build_exe.ps1
T

34 lines
1.1 KiB
PowerShell

# Build a single-file Windows exe.
#
# powershell -ExecutionPolicy Bypass -File tools\build_exe.ps1
#
# Output: dist\U盘备份工具.exe
# Requires: python -m pip install pyinstaller
param(
[string]$Name = "U盘备份工具"
)
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
$work = Join-Path $root "build"
$dist = Join-Path $root "dist"
Write-Host "Building $Name ..."
Push-Location $root
try {
python -m PyInstaller --noconfirm --clean --onefile --windowed --icon (Join-Path $root "icon.ico") --name $Name --version-file (Join-Path $PSScriptRoot "version_info.txt") --distpath $dist --workpath $work --specpath $work (Join-Path $root "usb_backup.py")
if ($LASTEXITCODE -ne 0) { throw "PyInstaller failed with exit code $LASTEXITCODE" }
} finally {
Pop-Location
}
$exe = Join-Path $dist "$Name.exe"
if (-not (Test-Path $exe)) { throw "missing $exe" }
$size = [math]::Round((Get-Item $exe).Length / 1MB, 2)
$hash = (Get-FileHash $exe -Algorithm SHA256).Hash
Write-Host ""
Write-Host "OK: $exe ($size MB)"
Write-Host "SHA256: $hash"