Files

91 lines
3.7 KiB
PowerShell

[CmdletBinding()]
param(
[switch]$SkipClient,
[switch]$SkipHost,
[switch]$CleanArtifacts,
[ValidateSet('zh-cn', 'en-us')]
[string]$Culture = 'zh-cn'
)
$ErrorActionPreference = 'Stop'
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
$artifacts = Join-Path $repoRoot 'artifacts'
$windowsScript = Join-Path $repoRoot 'packaging/windows/package-installer.ps1'
$windowsPreviewScript = Join-Path $repoRoot 'packaging/windows/package-preview.ps1'
$hostScript = Join-Path $repoRoot 'packaging/windows-host/package-host.ps1'
$portableHostScript = Join-Path $repoRoot 'packaging/windows-host/package-portable-host.ps1'
$previousRustFlags = $env:RUSTFLAGS
$staticRustFlags = '-C target-feature=+crt-static'
function Invoke-ChildBuild {
param(
[Parameter(Mandatory)][string]$Name,
[Parameter(Mandatory)][string]$Script,
[string[]]$Arguments = @()
)
if (-not (Test-Path -LiteralPath $Script -PathType Leaf)) {
throw "$Name script is missing: $Script"
}
Write-Host "==> $Name" -ForegroundColor Cyan
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $Script @Arguments
if ($LASTEXITCODE -ne 0) {
throw "$Name failed with exit code $LASTEXITCODE"
}
}
try {
if ($CleanArtifacts -and (Test-Path -LiteralPath $artifacts)) {
Write-Host "Cleaning artifacts: $artifacts" -ForegroundColor Yellow
Get-ChildItem -LiteralPath $artifacts -Force | Remove-Item -Recurse -Force
}
New-Item -ItemType Directory -Force -Path $artifacts | Out-Null
$env:RUSTFLAGS = $staticRustFlags
if (-not $SkipClient) {
Invoke-ChildBuild -Name 'Windows Client portable package' -Script $windowsPreviewScript
Invoke-ChildBuild -Name 'Windows Client installer' -Script $windowsScript -Arguments @('-Culture', $Culture)
}
if (-not $SkipHost) {
# Windows Agent is built with a static MSVC CRT and does not require VCRUNTIME140.dll.
$env:RUSTFLAGS = $staticRustFlags
Invoke-ChildBuild -Name 'Windows Host installer' -Script $hostScript -Arguments @('-Culture', $Culture)
Invoke-ChildBuild -Name 'Windows Host portable package' -Script $portableHostScript -Arguments @('-Culture', $Culture)
}
} finally {
if ($null -eq $previousRustFlags) {
Remove-Item Env:RUSTFLAGS -ErrorAction SilentlyContinue
} else {
$env:RUSTFLAGS = $previousRustFlags
}
}
Write-Host '==> Build outputs' -ForegroundColor Cyan
$artifactRootFull = ([IO.Path]::GetFullPath($artifacts)).TrimEnd('\') + '\'
$outputFiles = @()
$outputFiles += @(Get-ChildItem -LiteralPath $artifacts -File -ErrorAction SilentlyContinue |
Where-Object Extension -In @('.msi', '.exe', '.zip'))
$portableHost = Join-Path $artifacts 'RemoteDesk-Host-portable'
if (Test-Path -LiteralPath $portableHost) {
$outputFiles += @(Get-ChildItem -LiteralPath $portableHost -File -ErrorAction SilentlyContinue |
Where-Object { $_.Extension -eq '.exe' -or $_.Name -eq 'manifest.json' })
}
$outputFiles |
Sort-Object FullName -Unique |
ForEach-Object {
$hash = (Get-FileHash -LiteralPath $_.FullName -Algorithm SHA256).Hash.ToLowerInvariant()
# Windows PowerShell 5.1/.NET Framework has no Path.GetRelativePath.
$fullPath = [IO.Path]::GetFullPath($_.FullName)
if ($fullPath.StartsWith($artifactRootFull, [StringComparison]::OrdinalIgnoreCase)) {
$relative = $fullPath.Substring($artifactRootFull.Length)
} else {
$relative = $_.Name
}
$relative = $relative.Replace('\', '/')
'{0} {1}' -f $hash, $relative
} | Set-Content -LiteralPath (Join-Path $artifacts 'BUILD-SHA256SUMS.txt') -Encoding ascii
Write-Host "SHA256 manifest: $(Join-Path $artifacts 'BUILD-SHA256SUMS.txt')" -ForegroundColor Green