综合平台编程器项目的远程存储
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

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