feat(realtime): 多源观测追踪与启动配置文件支持 - 协议版本升至 3,Target 新增 sources 字段保留各接收器独立观测 - Store 改为按接收器维护 SourceObservation,基于 received_at_ms 独立执行 TTL 过期,过期后自动 refresh 选取最新有效位置 - refresh() 按时间排序源观测,优先选取有坐标的最近记录 - rid-shared 新增 SourceObservation 结构体 - Observation 验证内联 target_id 规则,长度不超过 192 - DeviceTelemetry 扩展 raw_identity、raw_position、 coordinate_system、position_unverified、relative_height_m - 项目级 config.json 支持版本化配置与 sqlite.busy_timeout_ms, 优先级:环境变量 > config.json > 旧版 maps/config.json - web-worker 传递 sources 与 position_source 至前端 - 首页标题更新为"凌空智巡无人机监测系统" ```
109 lines
7.3 KiB
PowerShell
109 lines
7.3 KiB
PowerShell
param([string]$OutputRoot)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
. (Join-Path $PSScriptRoot 'rust-env.ps1')
|
|
$ridRepo = Split-Path $PSScriptRoot -Parent
|
|
if (-not $OutputRoot) { $OutputRoot = Join-Path $ridRepo 'dist' }
|
|
$ridOutputRoot = [IO.Path]::GetFullPath($OutputRoot)
|
|
$ridDestination = Join-Path $ridOutputRoot 'FPV-RID-Rust'
|
|
$ridWhitelist = @('fpv-rid-registry.exe', 'rid-map-downloader.exe', 'map-downloader-LICENSE.txt', '启动Rust版.cmd', '使用说明.md', 'config.example.json', 'third-party-licenses.txt', 'dependency-licenses.txt', 'build-info.json', 'SHA256SUMS.txt')
|
|
|
|
function Assert-CleanDestination {
|
|
if (Test-Path -LiteralPath $ridDestination) {
|
|
foreach ($ridEntry in Get-ChildItem -LiteralPath $ridDestination -Force) {
|
|
if ($ridEntry.PSIsContainer -or ($ridEntry.Name -notin $ridWhitelist -and $ridEntry.Name -ne 'qrcode-LICENSE.txt') -or
|
|
($ridEntry.Attributes -band [IO.FileAttributes]::ReparsePoint)) {
|
|
throw "发布目录含运行数据或非发布文件,已停止打包并保留原内容:$($ridEntry.FullName)。请通过 -OutputRoot 指定单独的输出目录。"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function Get-RidSourceManifest {
|
|
$ridInputs = @('Cargo.toml','Cargo.lock','rust-toolchain.toml','build.rs','config.example.json') | ForEach-Object { Get-Item -LiteralPath (Join-Path $ridRepo $_) }
|
|
$ridInputs += @('src','crates','xtask','scripts','.cargo') | ForEach-Object { Get-ChildItem -LiteralPath (Join-Path $ridRepo $_) -Recurse -File }
|
|
@($ridInputs | Sort-Object FullName | ForEach-Object { [ordered]@{path=$_.FullName.Substring($ridRepo.Length + 1).Replace('\','/');sha256=(Get-FileHash -LiteralPath $_.FullName -Algorithm SHA256).Hash} })
|
|
}
|
|
|
|
# Refuse a used deployment folder before building or changing any published files.
|
|
Assert-CleanDestination
|
|
& (Join-Path $PSScriptRoot 'build-map-downloader.ps1')
|
|
$ridStageRoot = Join-Path $ridOutputRoot ('.package-' + [guid]::NewGuid().ToString('N'))
|
|
$ridStage = Join-Path $ridStageRoot 'FPV-RID-Rust'
|
|
$ridTemporaryZip = Join-Path $ridStageRoot 'release.zip'
|
|
Push-Location $ridRepo
|
|
$ridBuildLock = $null
|
|
$ridOldBuildOwner = $env:RID_PACKAGE_BUILD
|
|
try {
|
|
$ridBuildLock = [IO.File]::Open((Join-Path $ridRepo '.build.lock'), [IO.FileMode]::OpenOrCreate, [IO.FileAccess]::ReadWrite, [IO.FileShare]::None)
|
|
$env:RID_PACKAGE_BUILD = '1'
|
|
$ridInitialManifest = @(Get-RidSourceManifest)
|
|
$ridInitialManifestJson = ConvertTo-Json -InputObject $ridInitialManifest -Depth 5 -Compress
|
|
cargo xtask web
|
|
if ($LASTEXITCODE -ne 0) { throw 'Rust frontend build failed' }
|
|
cargo build --release --locked -p fpv-rid-registry
|
|
if ($LASTEXITCODE -ne 0) { throw 'Release build failed' }
|
|
$ridMetadata = cargo metadata --locked --format-version 1 --no-deps | ConvertFrom-Json
|
|
if ($LASTEXITCODE -ne 0) { throw 'Cargo metadata failed' }
|
|
New-Item -ItemType Directory -Force -Path $ridStage | Out-Null
|
|
Copy-Item -LiteralPath (Join-Path $ridMetadata.target_directory 'release/fpv-rid-registry-fullstack.exe') -Destination (Join-Path $ridStage 'fpv-rid-registry.exe')
|
|
Copy-Item -LiteralPath $env:RID_MAP_DOWNLOADER -Destination (Join-Path $ridStage 'rid-map-downloader.exe')
|
|
Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'map-downloader/LICENSE-upstream.txt') -Destination (Join-Path $ridStage 'map-downloader-LICENSE.txt')
|
|
Copy-Item -LiteralPath (Join-Path $ridRepo '启动Rust版.cmd') -Destination $ridStage
|
|
Copy-Item -LiteralPath (Join-Path $ridRepo 'doc/registry/rust/使用说明.md') -Destination $ridStage
|
|
Copy-Item -LiteralPath (Join-Path $ridRepo 'config.example.json') -Destination $ridStage
|
|
Copy-Item -LiteralPath (Join-Path $ridRepo 'crates/web-ui/public/vendor/LICENSE.txt') -Destination (Join-Path $ridStage 'third-party-licenses.txt')
|
|
$ridLicenses = cargo tree --workspace --locked --prefix none --format '{p} {l}'
|
|
if ($LASTEXITCODE -ne 0) { throw 'Dependency inventory failed' }
|
|
$ridLicenses | Set-Content -LiteralPath (Join-Path $ridStage 'dependency-licenses.txt') -Encoding utf8
|
|
Get-Content -LiteralPath (Join-Path $ridRepo 'crates/web-ui/public/vendor/LICENSE.txt') | Add-Content -LiteralPath (Join-Path $ridStage 'dependency-licenses.txt') -Encoding utf8
|
|
$ridSourceManifest = @(Get-RidSourceManifest)
|
|
if ((ConvertTo-Json -InputObject $ridSourceManifest -Depth 5 -Compress) -ne $ridInitialManifestJson) { throw '源码在构建期间发生变化,已停止发布并保留原发布包;请在源码稳定后重新构建。' }
|
|
$ridBuildInfo = [ordered]@{
|
|
builtAtUtc=[DateTime]::UtcNow.ToString('o')
|
|
gitRevision=(git rev-parse HEAD)
|
|
workingTreeDirty=[bool](git status --porcelain)
|
|
rust=(rustc --version)
|
|
trunk='0.22.0'
|
|
wasmBindgen='0.2.129'
|
|
executableSha256=(Get-FileHash -LiteralPath (Join-Path $ridStage 'fpv-rid-registry.exe') -Algorithm SHA256).Hash
|
|
sourceManifest=$ridSourceManifest
|
|
}
|
|
$ridBuildInfo | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $ridStage 'build-info.json') -Encoding utf8
|
|
$ridWhitelist | Where-Object { $_ -ne 'SHA256SUMS.txt' } | ForEach-Object {
|
|
'{0} {1}' -f (Get-FileHash -LiteralPath (Join-Path $ridStage $_) -Algorithm SHA256).Hash, $_
|
|
} | Set-Content -LiteralPath (Join-Path $ridStage 'SHA256SUMS.txt') -Encoding utf8
|
|
|
|
$ridActual = @(Get-ChildItem -LiteralPath $ridStage -Force)
|
|
if ($ridActual.Count -ne $ridWhitelist.Count -or @($ridActual | Where-Object { $_.PSIsContainer -or $_.Name -notin $ridWhitelist }).Count) {
|
|
throw 'Staging directory does not match the release whitelist'
|
|
}
|
|
# Only the fresh, checked staging tree is ever compressed.
|
|
Compress-Archive -LiteralPath $ridStage -DestinationPath $ridTemporaryZip
|
|
Assert-CleanDestination
|
|
New-Item -ItemType Directory -Force -Path $ridDestination | Out-Null
|
|
foreach ($ridName in $ridWhitelist) {
|
|
Copy-Item -LiteralPath (Join-Path $ridStage $ridName) -Destination (Join-Path $ridDestination $ridName)
|
|
}
|
|
$ridObsoleteLicense = Join-Path $ridDestination 'qrcode-LICENSE.txt'
|
|
if (Test-Path -LiteralPath $ridObsoleteLicense -PathType Leaf) { Remove-Item -LiteralPath $ridObsoleteLicense }
|
|
$ridZip = Join-Path $ridOutputRoot 'FPV-RID-Rust-Windows-x64.zip'
|
|
Move-Item -LiteralPath $ridTemporaryZip -Destination $ridZip -Force
|
|
'{0} FPV-RID-Rust-Windows-x64.zip' -f (Get-FileHash -LiteralPath $ridZip -Algorithm SHA256).Hash |
|
|
Set-Content -LiteralPath "$ridZip.sha256" -Encoding utf8
|
|
Write-Output $ridDestination
|
|
Write-Output $ridZip
|
|
} finally {
|
|
$env:RID_PACKAGE_BUILD = $ridOldBuildOwner
|
|
if ($ridBuildLock) { $ridBuildLock.Dispose() }
|
|
Pop-Location
|
|
# Clean only files this invocation created. Never recursively delete an output directory.
|
|
foreach ($ridName in $ridWhitelist) {
|
|
$ridOwnedFile = Join-Path $ridStage $ridName
|
|
if (Test-Path -LiteralPath $ridOwnedFile -PathType Leaf) { Remove-Item -LiteralPath $ridOwnedFile }
|
|
}
|
|
if (Test-Path -LiteralPath $ridTemporaryZip -PathType Leaf) { Remove-Item -LiteralPath $ridTemporaryZip }
|
|
if ((Test-Path -LiteralPath $ridStage -PathType Container) -and @(Get-ChildItem -LiteralPath $ridStage -Force).Count -eq 0) { Remove-Item -LiteralPath $ridStage }
|
|
if ((Test-Path -LiteralPath $ridStageRoot -PathType Container) -and @(Get-ChildItem -LiteralPath $ridStageRoot -Force).Count -eq 0) { Remove-Item -LiteralPath $ridStageRoot }
|
|
}
|