build_windows_release.ps1 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. param(
  2. [Parameter(Mandatory=$true)][string]$QtRoot,
  3. [Parameter(Mandatory=$true)][string]$MingwRoot,
  4. [string]$ReleaseRoot = 'C:\Users\Administrator\delivery\XJKJ-STL-Qt-Clean-0.8.1.12'
  5. )
  6. $ErrorActionPreference = 'Stop'
  7. $ProgressPreference = 'SilentlyContinue'
  8. [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding
  9. $sourceRoot = Join-Path $ReleaseRoot '_build-src\qt-client'
  10. $appRoot = Join-Path $ReleaseRoot 'app'
  11. $evidenceRoot = Join-Path $ReleaseRoot 'evidence'
  12. $env:PATH = (Join-Path $MingwRoot 'bin') + ';' + (Join-Path $QtRoot 'bin') + ';' + $env:PATH
  13. New-Item -ItemType Directory -Force -Path $appRoot,$evidenceRoot | Out-Null
  14. # ZIP timestamps can be ahead of this machine's clock. Normalize only the
  15. # copied source metadata so qmake does not recursively regenerate Makefile.
  16. # Source bytes and the machine clock remain unchanged.
  17. $buildNow = (Get-Date).ToUniversalTime()
  18. Get-ChildItem -LiteralPath $sourceRoot -Recurse -File | Where-Object { $_.LastWriteTimeUtc -gt $buildNow } | ForEach-Object {
  19. $_.LastWriteTimeUtc = $buildNow.AddMinutes(-1)
  20. }
  21. function Invoke-Logged([string]$Tool,[string[]]$ToolArguments,[string]$WorkingDirectory,[string]$Label) {
  22. $outPath = Join-Path $evidenceRoot ($Label + '.stdout.log')
  23. $errPath = Join-Path $evidenceRoot ($Label + '.stderr.log')
  24. $process = Start-Process -FilePath $Tool -ArgumentList $ToolArguments -WorkingDirectory $WorkingDirectory `
  25. -NoNewWindow -Wait -PassThru -RedirectStandardOutput $outPath -RedirectStandardError $errPath
  26. if ($process.ExitCode -ne 0) {
  27. Get-Content -LiteralPath $errPath -Tail 30
  28. throw "$Label failed with exit code $($process.ExitCode)"
  29. }
  30. Write-Output "$Label passed"
  31. }
  32. $qmake = Join-Path $QtRoot 'bin\qmake.exe'
  33. $make = Join-Path $MingwRoot 'bin\mingw32-make.exe'
  34. foreach ($tool in @($qmake,$make)) {
  35. if (!(Test-Path -LiteralPath $tool)) { throw "Missing build tool: $tool" }
  36. }
  37. & $qmake -query | Out-File -Encoding utf8 (Join-Path $evidenceRoot 'windows-qmake-query.txt')
  38. & (Join-Path $MingwRoot 'bin\g++.exe') --version | Out-File -Encoding utf8 (Join-Path $evidenceRoot 'windows-compiler-version.txt')
  39. foreach ($kind in @('app','probe')) {
  40. $build = Join-Path $ReleaseRoot ('_build-src\build-' + $kind + '-win-release')
  41. New-Item -ItemType Directory -Force -Path $build | Out-Null
  42. if ($kind -eq 'app') {
  43. $project = Join-Path $sourceRoot 'DDR5_SLT_Monitor.pro'
  44. $executable = 'DDR5_SLT_Monitor.exe'
  45. } else {
  46. $project = Join-Path $sourceRoot 'tests\qt_clean_probe.pro'
  47. $executable = 'QtCleanProbe.exe'
  48. }
  49. Invoke-Logged $qmake @($project,'-spec','win32-g++','CONFIG+=release','CONFIG-=debug','CONFIG-=debug_and_release','CONFIG-=console') $build ('windows-' + $kind + '-qmake')
  50. Invoke-Logged $make @('-j4') $build ('windows-' + $kind + '-build')
  51. $built = Join-Path $build $executable
  52. if (!(Test-Path -LiteralPath $built)) { $built = Join-Path $build ('release\' + $executable) }
  53. if (!(Test-Path -LiteralPath $built)) { throw "Build did not produce $executable" }
  54. Copy-Item -LiteralPath $built -Destination (Join-Path $appRoot $executable) -Force
  55. }
  56. # The Qt 5.15.2 deployment tool rejected its matching MinGW plugins as debug.
  57. # Use an explicit, reviewable runtime from this exact build kit; validation runs
  58. # both Qt executables with the SDK and compiler directories removed from PATH.
  59. foreach ($library in @('Qt5Core.dll','Qt5Gui.dll','Qt5Widgets.dll','Qt5Network.dll',
  60. 'Qt5SerialPort.dll','Qt5WebSockets.dll','Qt5PrintSupport.dll',
  61. 'libEGL.dll','libGLESv2.dll','D3Dcompiler_47.dll','opengl32sw.dll')) {
  62. Copy-Item -LiteralPath (Join-Path $QtRoot ('bin\' + $library)) -Destination $appRoot -Force
  63. }
  64. foreach ($library in @('libgcc_s_seh-1.dll','libstdc++-6.dll','libwinpthread-1.dll')) {
  65. Copy-Item -LiteralPath (Join-Path $MingwRoot ('bin\' + $library)) -Destination $appRoot -Force
  66. }
  67. foreach ($category in @('platforms','imageformats','printsupport','styles','bearer')) {
  68. $sourcePlugins = Join-Path $QtRoot ('plugins\' + $category)
  69. if (Test-Path -LiteralPath $sourcePlugins) {
  70. $destination = Join-Path $appRoot $category
  71. New-Item -ItemType Directory -Force -Path $destination | Out-Null
  72. Copy-Item -Path (Join-Path $sourcePlugins '*.dll') -Destination $destination -Force
  73. }
  74. }
  75. Copy-Item -LiteralPath (Join-Path $sourceRoot 'config.json') -Destination (Join-Path $appRoot 'config.json') -Force
  76. $utf8 = New-Object System.Text.UTF8Encoding($false)
  77. [IO.File]::WriteAllText((Join-Path $appRoot 'qt.conf'), "[Paths]`r`nPrefix=.`r`nPlugins=.`r`n", $utf8)
  78. $ports = @{ serialPorts = @(
  79. @{port='';serialNumber='';baud=115200},
  80. @{port='';serialNumber='';baud=115200},
  81. @{port='';serialNumber='';baud=115200},
  82. @{port='';serialNumber='';baud=115200}
  83. )} | ConvertTo-Json -Depth 5
  84. [IO.File]::WriteAllText((Join-Path $appRoot 'port.json'), $ports + "`r`n", $utf8)
  85. $planPath = Join-Path $appRoot 'qt-plans.json'
  86. [IO.File]::WriteAllText($planPath, "{`"version`":1,`"stations`":{}}`r`n", $utf8)
  87. $files = Get-ChildItem -LiteralPath $appRoot -Recurse -File | ForEach-Object {
  88. @{ path = $_.FullName.Substring($appRoot.Length + 1).Replace('\','/'); bytes = $_.Length;
  89. sha256 = (Get-FileHash -LiteralPath $_.FullName -Algorithm SHA256).Hash.ToLowerInvariant() }
  90. }
  91. $result = @{
  92. passed = $true; build_host = $env:COMPUTERNAME; architecture = 'x86_64'; qt_root = $QtRoot;
  93. compiler_root = $MingwRoot; app_directory = $appRoot;
  94. backend_url = 'ws://192.168.2.79:8080/ws?view=qt-clean'; files = @($files)
  95. } | ConvertTo-Json -Depth 8
  96. [IO.File]::WriteAllText((Join-Path $evidenceRoot 'windows-build-deployment.json'), $result + "`r`n", $utf8)
  97. Write-Output $result