video_monitor/deploy/windows/build.ps1

35 lines
1.7 KiB
PowerShell
Raw Normal View History

2026-09-04 18:16:14 +08:00
param(
[Parameter(Mandatory=$true)][string]$PublicKey,
[string]$Iscc,
[string]$Vcvars,
[switch]$PrepareEnvironment
)
$ErrorActionPreference = 'Stop'
$projectRoot = (Resolve-Path (Join-Path $PSScriptRoot '../..')).Path
$buildPython = Join-Path $projectRoot '.build-venv/Scripts/python.exe'
if ($PrepareEnvironment) {
$sourcePython = Join-Path $projectRoot '.venv/Scripts/python.exe'
if (-not (Test-Path -LiteralPath $sourcePython)) {
throw 'Create the CPU project environment from requirements-windows-cpu.lock.txt first.'
}
if (-not (Test-Path -LiteralPath $buildPython)) {
& $sourcePython -m venv (Join-Path $projectRoot '.build-venv')
if ($LASTEXITCODE -ne 0) { throw 'Build venv creation failed' }
}
# Copy a pinned runtime snapshot; no symlinks and no changes to the developer environment.
$sourceLib = Join-Path $projectRoot '.venv/Lib/site-packages'
$buildLib = Join-Path $projectRoot '.build-venv/Lib/site-packages'
& $sourcePython -c 'import shutil,sys;shutil.copytree(sys.argv[1],sys.argv[2],dirs_exist_ok=True)' $sourceLib $buildLib
if ($LASTEXITCODE -ne 0) { throw 'Runtime snapshot failed' }
& $buildPython -m pip install --no-deps -r (Join-Path $PSScriptRoot 'build-tools.lock.txt')
if ($LASTEXITCODE -ne 0) { throw 'Build tools installation failed' }
}
if (-not (Test-Path -LiteralPath $buildPython)) { throw 'Use -PrepareEnvironment for the first build.' }
& $buildPython -m pip check
if ($LASTEXITCODE -ne 0) { throw 'Dependency check failed' }
$buildArgs = @((Join-Path $PSScriptRoot 'build.py'),'--public-key',(Resolve-Path -LiteralPath $PublicKey).Path)
if ($Iscc) { $buildArgs += @('--iscc',$Iscc) }
if ($Vcvars) { $buildArgs += @('--vcvars',$Vcvars) }
& $buildPython @buildArgs
exit $LASTEXITCODE