#requires -Version 5.1
param([ValidateSet('Debug','Release')][string]$Configuration='Release', [string]$Destination, [switch]$IfNeeded, [string]$DotNetPath)
$ErrorActionPreference = 'Stop'
# Windows PowerShell exposes Get-FileHash as a module function. Import it in
# script scope before pipelines trigger cmdlet-only module auto-loading.
Import-Module (Join-Path $PSHOME 'Modules/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1') -ErrorAction Stop
$taskRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
if (-not $DotNetPath) {
$taskDotNetCommand = Get-Command dotnet -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
if ($taskDotNetCommand) { $DotNetPath = $taskDotNetCommand.Source }
else {
foreach ($taskProgramRoot in @($env:ProgramW6432, $env:ProgramFiles)) {
if ($taskProgramRoot) {
$taskDotNetCandidate = Join-Path $taskProgramRoot 'dotnet/dotnet.exe'
if (Test-Path -LiteralPath $taskDotNetCandidate -PathType Leaf) { $DotNetPath = $taskDotNetCandidate; break }
}
}
}
}
if (-not $DotNetPath -or -not (Test-Path -LiteralPath $DotNetPath -PathType Leaf)) { throw 'Cannot find the .NET SDK host. Pass -DotNetPath with the full path to dotnet.exe.' }
$DotNetPath = [IO.Path]::GetFullPath($DotNetPath)
$taskCache = Join-Path $taskRoot 'artifacts/bridge'
if (-not $Destination) { $Destination = $taskCache }
$Destination = [IO.Path]::GetFullPath($Destination)
New-Item -ItemType Directory -Path (Join-Path $taskRoot 'artifacts') -Force | Out-Null
# Player and Installer can build concurrently in Visual Studio. One producer
# updates the shared development bundle; each application gets its own copy.
$taskBuildLock = $null
$taskDeadline = [DateTime]::UtcNow.AddMinutes(3)
try {
while ($null -eq $taskBuildLock) {
try { $taskBuildLock = [IO.File]::Open((Join-Path $taskRoot 'artifacts/bridge-build.lock'), [IO.FileMode]::OpenOrCreate, [IO.FileAccess]::ReadWrite, [IO.FileShare]::None) }
catch [IO.IOException] {
if ([DateTime]::UtcNow -ge $taskDeadline) { throw 'Timed out waiting for another native component build.' }
Start-Sleep -Milliseconds 200
}
}
$taskVersionSource = Get-Content -LiteralPath (Join-Path $taskRoot 'Client/XFEWarframe.Client/Runtime/RuntimeControlServer.cs') -Raw
$taskVersionMatch = [regex]::Match($taskVersionSource, 'public\s+const\s+string\s+Version\s*=\s*"([^"]+)"')
if (-not $taskVersionMatch.Success) { throw 'Native component version is missing from the runtime contract.' }
$taskVersion = $taskVersionMatch.Groups[1].Value
$taskSdkVersion = & $DotNetPath --version
if ($LASTEXITCODE -ne 0) { throw 'Cannot read the .NET SDK version.' }
$taskInputs = @(
foreach ($taskDirectory in @('Client/XFEWarframe.Bridge','Client/XFEWarframe.Client','Client/Shared')) {
Get-ChildItem -LiteralPath (Join-Path $taskRoot $taskDirectory) -Recurse -File |
Where-Object { $_.Extension -in @('.cs','.csproj') -and $_.FullName -notmatch '[\\/](bin|obj|artifacts)[\\/]' }
}
foreach ($taskInput in @('Directory.Build.props','global.json','scripts/Build-Bridge.ps1',
'Client/XFEWarframe.Client/Bindings/ExperimentalAbi.json',
'Server/data/export/ExportWarframes.json','Server/data/world/supplementalSuits.json',
'Server/data/export/ExportAbilities.json','Server/data/export/ExportImages.json')) {
Get-Item -LiteralPath (Join-Path $taskRoot $taskInput)
}
) | Sort-Object FullName
$taskInputHashes = foreach ($taskInput in $taskInputs) {
$taskInput.FullName.Substring($taskRoot.TrimEnd([char[]]'\/').Length + 1) + ':' + (Get-FileHash -LiteralPath $taskInput.FullName -Algorithm SHA256).Hash
}
$taskSha256 = [Security.Cryptography.SHA256]::Create()
try {
$taskFingerprint = [BitConverter]::ToString($taskSha256.ComputeHash(
[Text.Encoding]::UTF8.GetBytes((@($Configuration, "$taskSdkVersion", $taskVersion) + $taskInputHashes) -join "`n"))).Replace('-', '')
} finally { $taskSha256.Dispose() }
$taskManifestPath = Join-Path $taskCache 'payload.json'
$taskStampPath = Join-Path $taskCache 'build-inputs.json'
$taskDllPath = Join-Path $taskCache 'XFEWarframe.Bridge.dll'
$taskCurrent = $false
if ($IfNeeded -and (Test-Path -LiteralPath $taskManifestPath) -and (Test-Path -LiteralPath $taskStampPath) -and (Test-Path -LiteralPath $taskDllPath)) {
try {
$taskManifest = Get-Content -LiteralPath $taskManifestPath -Raw | ConvertFrom-Json
$taskStamp = Get-Content -LiteralPath $taskStampPath -Raw | ConvertFrom-Json
$taskCurrent = $taskManifest.SchemaVersion -eq 1 -and $taskManifest.Version -eq $taskVersion -and
$taskStamp.fingerprint -eq $taskFingerprint -and
$taskManifest.Sha256 -eq (Get-FileHash -LiteralPath $taskDllPath -Algorithm SHA256).Hash
} catch { $taskCurrent = $false }
}
if (-not $taskCurrent) {
$taskBuildRoot = Join-Path $taskRoot ('artifacts/bridge-build/' + [Guid]::NewGuid().ToString('N'))
$taskStaging = Join-Path $taskBuildRoot 'payload'
& $DotNetPath publish (Join-Path $taskRoot 'Client/XFEWarframe.Bridge/XFEWarframe.Bridge.csproj') -c $Configuration -r win-x64 -o $taskStaging --nologo -v quiet (
'-p:XFEIntermediateRoot=' + (Join-Path $taskBuildRoot 'obj')) ('-p:OutputPath=' + (Join-Path $taskBuildRoot 'build') + [IO.Path]::DirectorySeparatorChar)
if ($LASTEXITCODE -ne 0) { throw 'NativeAOT bridge publish failed; install Visual Studio C++ desktop build tools.' }
$taskHash = (Get-FileHash -LiteralPath (Join-Path $taskStaging 'XFEWarframe.Bridge.dll') -Algorithm SHA256).Hash
@{SchemaVersion=1;Version=$taskVersion;Sha256=$taskHash} | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $taskStaging 'payload.json') -Encoding utf8
New-Item -ItemType Directory -Path $taskCache -Force | Out-Null
Copy-Item -LiteralPath (Join-Path $taskStaging 'XFEWarframe.Bridge.dll'),(Join-Path $taskStaging 'payload.json') -Destination $taskCache -Force
@{fingerprint=$taskFingerprint} | ConvertTo-Json | Set-Content -LiteralPath $taskStampPath -Encoding utf8
}
if (-not $Destination.Equals($taskCache, [StringComparison]::OrdinalIgnoreCase)) {
New-Item -ItemType Directory -Path $Destination -Force | Out-Null
Copy-Item -LiteralPath $taskDllPath,$taskManifestPath -Destination $Destination -Force
}
Write-Output "Native component $taskVersion ready: $Destination"
} finally { if ($taskBuildLock) { $taskBuildLock.Dispose() } }
#requires -Version 5.1
param([ValidateSet('Debug','Release')][string]$Configuration='Release', [string]$Destination, [switch]$IfNeeded, [string]$DotNetPath)
$ErrorActionPreference = 'Stop'
# Windows PowerShell exposes Get-FileHash as a module function. Import it in
# script scope before pipelines trigger cmdlet-only module auto-loading.
Import-Module (Join-Path $PSHOME 'Modules/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility.psd1') -ErrorAction Stop
$taskRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
if (-not $DotNetPath) {
$taskDotNetCommand = Get-Command dotnet -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
if ($taskDotNetCommand) { $DotNetPath = $taskDotNetCommand.Source }
else {
foreach ($taskProgramRoot in @($env:ProgramW6432, $env:ProgramFiles)) {
if ($taskProgramRoot) {
$taskDotNetCandidate = Join-Path $taskProgramRoot 'dotnet/dotnet.exe'
if (Test-Path -LiteralPath $taskDotNetCandidate -PathType Leaf) { $DotNetPath = $taskDotNetCandidate; break }
}
}
}
}
if (-not $DotNetPath -or -not (Test-Path -LiteralPath $DotNetPath -PathType Leaf)) { throw 'Cannot find the .NET SDK host. Pass -DotNetPath with the full path to dotnet.exe.' }
$DotNetPath = [IO.Path]::GetFullPath($DotNetPath)
$taskCache = Join-Path $taskRoot 'artifacts/bridge'
if (-not $Destination) { $Destination = $taskCache }
$Destination = [IO.Path]::GetFullPath($Destination)
New-Item -ItemType Directory -Path (Join-Path $taskRoot 'artifacts') -Force | Out-Null
# Player and Installer can build concurrently in Visual Studio. One producer
# updates the shared development bundle; each application gets its own copy.
$taskBuildLock = $null
$taskDeadline = [DateTime]::UtcNow.AddMinutes(3)
try {
while ($null -eq $taskBuildLock) {
try { $taskBuildLock = [IO.File]::Open((Join-Path $taskRoot 'artifacts/bridge-build.lock'), [IO.FileMode]::OpenOrCreate, [IO.FileAccess]::ReadWrite, [IO.FileShare]::None) }
catch [IO.IOException] {
if ([DateTime]::UtcNow -ge $taskDeadline) { throw 'Timed out waiting for another native component build.' }
Start-Sleep -Milliseconds 200
}
}
$taskVersionSource = Get-Content -LiteralPath (Join-Path $taskRoot 'Client/XFEWarframe.Client/Runtime/RuntimeControlServer.cs') -Raw
$taskVersionMatch = [regex]::Match($taskVersionSource, 'public\s+const\s+string\s+Version\s*=\s*"([^"]+)"')
if (-not $taskVersionMatch.Success) { throw 'Native component version is missing from the runtime contract.' }
$taskVersion = $taskVersionMatch.Groups[1].Value
$taskSdkVersion = & $DotNetPath --version
if ($LASTEXITCODE -ne 0) { throw 'Cannot read the .NET SDK version.' }
$taskInputs = @(
foreach ($taskDirectory in @('Client/XFEWarframe.Bridge','Client/XFEWarframe.Client','Client/Shared')) {
Get-ChildItem -LiteralPath (Join-Path $taskRoot $taskDirectory) -Recurse -File |
Where-Object { $_.Extension -in @('.cs','.csproj') -and $_.FullName -notmatch '[\\/](bin|obj|artifacts)[\\/]' }
}
foreach ($taskInput in @('Directory.Build.props','global.json','scripts/Build-Bridge.ps1',
'Client/XFEWarframe.Client/Bindings/ExperimentalAbi.json',
'Server/data/export/ExportWarframes.json','Server/data/world/supplementalSuits.json',
'Server/data/export/ExportAbilities.json','Server/data/export/ExportImages.json')) {
Get-Item -LiteralPath (Join-Path $taskRoot $taskInput)
}
) | Sort-Object FullName
$taskInputHashes = foreach ($taskInput in $taskInputs) {
$taskInput.FullName.Substring($taskRoot.TrimEnd([char[]]'\/').Length + 1) + ':' + (Get-FileHash -LiteralPath $taskInput.FullName -Algorithm SHA256).Hash
}
$taskSha256 = [Security.Cryptography.SHA256]::Create()
try {
$taskFingerprint = [BitConverter]::ToString($taskSha256.ComputeHash(
[Text.Encoding]::UTF8.GetBytes((@($Configuration, "$taskSdkVersion", $taskVersion) + $taskInputHashes) -join "`n"))).Replace('-', '')
} finally { $taskSha256.Dispose() }
$taskManifestPath = Join-Path $taskCache 'payload.json'
$taskStampPath = Join-Path $taskCache 'build-inputs.json'
$taskDllPath = Join-Path $taskCache 'XFEWarframe.Bridge.dll'
$taskCurrent = $false
if ($IfNeeded -and (Test-Path -LiteralPath $taskManifestPath) -and (Test-Path -LiteralPath $taskStampPath) -and (Test-Path -LiteralPath $taskDllPath)) {
try {
$taskManifest = Get-Content -LiteralPath $taskManifestPath -Raw | ConvertFrom-Json
$taskStamp = Get-Content -LiteralPath $taskStampPath -Raw | ConvertFrom-Json
$taskCurrent = $taskManifest.SchemaVersion -eq 1 -and $taskManifest.Version -eq $taskVersion -and
$taskStamp.fingerprint -eq $taskFingerprint -and
$taskManifest.Sha256 -eq (Get-FileHash -LiteralPath $taskDllPath -Algorithm SHA256).Hash
} catch { $taskCurrent = $false }
}
if (-not $taskCurrent) {
$taskBuildRoot = Join-Path $taskRoot ('artifacts/bridge-build/' + [Guid]::NewGuid().ToString('N'))
$taskStaging = Join-Path $taskBuildRoot 'payload'
& $DotNetPath publish (Join-Path $taskRoot 'Client/XFEWarframe.Bridge/XFEWarframe.Bridge.csproj') -c $Configuration -r win-x64 -o $taskStaging --nologo -v quiet (
'-p:XFEIntermediateRoot=' + (Join-Path $taskBuildRoot 'obj')) ('-p:OutputPath=' + (Join-Path $taskBuildRoot 'build') + [IO.Path]::DirectorySeparatorChar)
if ($LASTEXITCODE -ne 0) { throw 'NativeAOT bridge publish failed; install Visual Studio C++ desktop build tools.' }
$taskHash = (Get-FileHash -LiteralPath (Join-Path $taskStaging 'XFEWarframe.Bridge.dll') -Algorithm SHA256).Hash
@{SchemaVersion=1;Version=$taskVersion;Sha256=$taskHash} | ConvertTo-Json | Set-Content -LiteralPath (Join-Path $taskStaging 'payload.json') -Encoding utf8
New-Item -ItemType Directory -Path $taskCache -Force | Out-Null
Copy-Item -LiteralPath (Join-Path $taskStaging 'XFEWarframe.Bridge.dll'),(Join-Path $taskStaging 'payload.json') -Destination $taskCache -Force
@{fingerprint=$taskFingerprint} | ConvertTo-Json | Set-Content -LiteralPath $taskStampPath -Encoding utf8
}
if (-not $Destination.Equals($taskCache, [StringComparison]::OrdinalIgnoreCase)) {
New-Item -ItemType Directory -Path $Destination -Force | Out-Null
Copy-Item -LiteralPath $taskDllPath,$taskManifestPath -Destination $Destination -Force
}
Write-Output "Native component $taskVersion ready: $Destination"
} finally { if ($taskBuildLock) { $taskBuildLock.Dispose() } }