Files
AndroidDeviceStreaming/scripts/build-installers.ps1
T

53 lines
3.4 KiB
PowerShell

param(
[ValidateSet('All','Avalonia','Flutter')][string]$Edition='All',
[string]$Compiler,
[switch]$SkipBuild,
[switch]$ReuseVersion
)
$ErrorActionPreference='Stop'
$root=Split-Path $PSScriptRoot -Parent
if (-not $Compiler) {
$candidates=@((Join-Path $root 'work/installer-tools/inno/ISCC.exe'),"${env:ProgramFiles(x86)}/Inno Setup 6/ISCC.exe", "$env:ProgramFiles/Inno Setup 7/ISCC.exe")
$Compiler=$candidates | Where-Object { Test-Path -LiteralPath $_ } | Select-Object -First 1
}
if (-not $Compiler) { throw 'Install Inno Setup 6/7 or specify -Compiler path/to/ISCC.exe' }
if ($SkipBuild -and -not $ReuseVersion) { throw 'SkipBuild requires ReuseVersion; new releases must rebuild their binaries' }
$versionArgs=@((Join-Path $PSScriptRoot 'release-version.py'))
if ($ReuseVersion) { $versionArgs+='--reuse' }
$version=(& python @versionArgs).Trim()
if ($LASTEXITCODE) { throw 'Release version update failed' }
if (-not $SkipBuild) {
& (Join-Path $PSScriptRoot 'build.ps1')
if ($LASTEXITCODE) { throw 'Backend build failed' }
}
$output=Join-Path $root 'bin/installers'
New-Item -ItemType Directory -Force -Path $output | Out-Null
foreach ($name in @('Avalonia','Flutter')) {
if ($Edition -ne 'All' -and $Edition -ne $name) { continue }
$folder=if ($name -eq 'Avalonia') { 'desktop-win-x64' } else { 'flutter-win-x64' }
$exe=if ($name -eq 'Avalonia') { 'Ads.Desktop.exe' } else { 'ads_manager.exe' }
if (-not $SkipBuild) {
$build=if ($name -eq 'Avalonia') { 'build-desktop.ps1' } else { 'build-flutter.ps1' }
& (Join-Path $PSScriptRoot $build)
if ($LASTEXITCODE) { throw "$name build failed" }
}
$source=Join-Path $root "bin/$folder"
if ($name -eq 'Flutter') {
$crt=Get-ChildItem "$env:ProgramFiles/Microsoft Visual Studio/2022/*/VC/Redist/MSVC/*/x64/Microsoft.VC143.CRT" -Directory -ErrorAction SilentlyContinue | Sort-Object FullName -Descending | Select-Object -First 1
if ($crt) { Copy-Item -Path (Join-Path $crt.FullName '*.dll') -Destination $source -Force }
foreach ($runtime in @('msvcp140.dll','vcruntime140.dll','vcruntime140_1.dll')) {
if (-not (Test-Path -LiteralPath (Join-Path $source $runtime))) { throw "Missing redistributable C++ runtime: $runtime" }
}
}
& (Join-Path $PSScriptRoot 'copy-windows-usb-driver.ps1') -Destination $source
if (-not (Test-Path -LiteralPath (Join-Path $source 'ads-usb.exe'))) { Copy-Item -LiteralPath (Join-Path $root 'bin/ads-usb.exe') -Destination $source }
foreach ($file in @($exe,'adsctl.exe','ads-agent.exe','ads-client.exe','tools/scrcpy/adb.exe','tools/scrcpy/scrcpy.exe')) {
if (-not (Test-Path -LiteralPath (Join-Path $source $file))) { throw "Missing payload: $folder/$file" }
}
if (Get-ChildItem -LiteralPath $source -Recurse -File -Filter '*.env') { throw 'Credential file found in release payload; remove it before packaging' }
& $Compiler "/DVersion=$version" "/DEdition=$name" "/DExecutable=$exe" "/DSource=$source" "/DOutput=$output" (Join-Path $root 'deploy/windows/desktop-installer.iss')
if ($LASTEXITCODE) { throw "$name installer compilation failed" }
$package=Join-Path $output "ADS-$name-$version-win-x64-Setup.exe"
(Get-FileHash -LiteralPath $package -Algorithm SHA256).Hash.ToLowerInvariant()+' '+[IO.Path]::GetFileName($package) | Set-Content -LiteralPath ($package+'.sha256') -Encoding ascii
}