综合平台编程器项目的远程存储
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

127 righe
5.2 KiB

  1. [CmdletBinding()]
  2. param(
  3. [string]$OutputName = 'integrated_platform-win64'
  4. )
  5. Set-StrictMode -Version Latest
  6. $ErrorActionPreference = 'Stop'
  7. $projectRoot = Split-Path -Parent $PSScriptRoot
  8. $qtRoot = if ($env:QTDIR) { $env:QTDIR } else { 'D:\Qt5.15.2\5.15.2\mingw81_64' }
  9. $mingwBin = 'D:\Qt5.15.2\Tools\mingw810_64\bin'
  10. $qmakePath = Join-Path $qtRoot 'bin\qmake.exe'
  11. $makePath = Join-Path $mingwBin 'mingw32-make.exe'
  12. $pluginDirectory = Join-Path $qtRoot 'plugins'
  13. $platformPlugin = Join-Path $pluginDirectory 'platforms\qwindows.dll'
  14. $stylePlugin = Join-Path $pluginDirectory 'styles\qwindowsvistastyle.dll'
  15. $qtProjectFile = Join-Path $projectRoot 'app\integrated_platform.pro'
  16. $runtimeBuildRoot = Join-Path $projectRoot 'build\runtime-export'
  17. $buildDirectory = Join-Path $runtimeBuildRoot ([guid]::NewGuid().ToString('N'))
  18. $executablePath = Join-Path $buildDirectory 'release\integrated_platform.exe'
  19. $packageRoot = Join-Path $projectRoot 'build\package'
  20. foreach ($requiredPath in @($qmakePath, $makePath, $platformPlugin, $stylePlugin, $qtProjectFile)) {
  21. if (-not (Test-Path -LiteralPath $requiredPath)) {
  22. throw "未找到必要文件:$requiredPath"
  23. }
  24. }
  25. if ([string]::IsNullOrWhiteSpace($OutputName) -or
  26. $OutputName -in @('.', '..') -or
  27. $OutputName.IndexOfAny([System.IO.Path]::GetInvalidFileNameChars()) -ge 0 -or
  28. [System.IO.Path]::GetFileName($OutputName) -ne $OutputName) {
  29. throw "输出名称不是有效的 Windows 文件名:$OutputName"
  30. }
  31. $packageDirectory = Join-Path $packageRoot $OutputName
  32. $archivePath = Join-Path $packageRoot "$OutputName.zip"
  33. $resolvedProjectRoot = [System.IO.Path]::GetFullPath($projectRoot).TrimEnd('\')
  34. $resolvedPackageRoot = [System.IO.Path]::GetFullPath($packageRoot).TrimEnd('\')
  35. $resolvedPackageDirectory = [System.IO.Path]::GetFullPath($packageDirectory)
  36. if (-not $resolvedPackageRoot.StartsWith("$resolvedProjectRoot\build\", [System.StringComparison]::OrdinalIgnoreCase) -or
  37. [System.IO.Path]::GetDirectoryName($resolvedPackageDirectory) -ne $resolvedPackageRoot) {
  38. throw "打包目录必须是 build\package 的直接子目录:$resolvedPackageDirectory"
  39. }
  40. New-Item -ItemType Directory -Path $buildDirectory -Force | Out-Null
  41. New-Item -ItemType Directory -Path $packageRoot -Force | Out-Null
  42. $originalPath = $env:Path
  43. $env:Path = "$qtRoot\bin;$mingwBin;$env:Path"
  44. try {
  45. Push-Location $buildDirectory
  46. try {
  47. Write-Host 'RUNTIME_EXPORT_STAGE: qmake'
  48. & $qmakePath $qtProjectFile 'CONFIG+=release' 'CONFIG-=debug'
  49. if ($LASTEXITCODE -ne 0) {
  50. throw "qmake 执行失败,退出码:$LASTEXITCODE"
  51. }
  52. Write-Host 'RUNTIME_EXPORT_STAGE: compile'
  53. & $makePath -j2
  54. if ($LASTEXITCODE -ne 0) {
  55. throw "mingw32-make 执行失败,退出码:$LASTEXITCODE"
  56. }
  57. }
  58. finally {
  59. Pop-Location
  60. }
  61. if (-not (Test-Path -LiteralPath $executablePath)) {
  62. throw "未生成可执行文件:$executablePath"
  63. }
  64. if (Test-Path -LiteralPath $packageDirectory) {
  65. Remove-Item -LiteralPath $packageDirectory -Recurse -Force
  66. }
  67. if (Test-Path -LiteralPath $archivePath) {
  68. Remove-Item -LiteralPath $archivePath -Force
  69. }
  70. Write-Host 'RUNTIME_EXPORT_STAGE: package'
  71. New-Item -ItemType Directory -Path $packageDirectory | Out-Null
  72. $packagedExecutable = Join-Path $packageDirectory 'integrated_platform.exe'
  73. Copy-Item -LiteralPath $executablePath -Destination $packagedExecutable
  74. $runtimeFiles = @(
  75. 'Qt5Core.dll', 'Qt5Gui.dll', 'Qt5Network.dll',
  76. 'Qt5SerialBus.dll', 'Qt5SerialPort.dll', 'Qt5Widgets.dll',
  77. 'libgcc_s_seh-1.dll', 'libstdc++-6.dll', 'libwinpthread-1.dll'
  78. )
  79. foreach ($runtimeFile in $runtimeFiles) {
  80. $runtimeSource = Join-Path $(if ($runtimeFile -like 'Qt5*') { "$qtRoot\bin" } else { $mingwBin }) $runtimeFile
  81. if (-not (Test-Path -LiteralPath $runtimeSource)) {
  82. throw "未找到运行库:$runtimeSource"
  83. }
  84. Copy-Item -LiteralPath $runtimeSource -Destination $packageDirectory
  85. }
  86. $packagedPlatformDirectory = Join-Path $packageDirectory 'platforms'
  87. $packagedStyleDirectory = Join-Path $packageDirectory 'styles'
  88. New-Item -ItemType Directory -Path $packagedPlatformDirectory | Out-Null
  89. New-Item -ItemType Directory -Path $packagedStyleDirectory | Out-Null
  90. Copy-Item -LiteralPath $platformPlugin -Destination $packagedPlatformDirectory
  91. Copy-Item -LiteralPath $stylePlugin -Destination $packagedStyleDirectory
  92. Write-Host 'RUNTIME_EXPORT_STAGE: verify'
  93. foreach ($requiredOutput in @(
  94. $packagedExecutable,
  95. (Join-Path $packageDirectory 'Qt5Core.dll'),
  96. (Join-Path $packageDirectory 'Qt5SerialBus.dll'),
  97. (Join-Path $packagedPlatformDirectory 'qwindows.dll')
  98. )) {
  99. if (-not (Test-Path -LiteralPath $requiredOutput)) {
  100. throw "打包结果缺少必要文件:$requiredOutput"
  101. }
  102. }
  103. Compress-Archive -LiteralPath $packageDirectory -DestinationPath $archivePath -CompressionLevel Optimal
  104. Write-Host "打包完成"
  105. Write-Host "运行目录:$packageDirectory"
  106. Write-Host "压缩包:$archivePath"
  107. }
  108. finally {
  109. $env:Path = $originalPath
  110. }