综合平台编程器项目的远程存储
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.
 
 
 
 

89 rivejä
2.7 KiB

  1. [CmdletBinding()]
  2. param(
  3. [ValidateSet('Debug', 'Release')]
  4. [string]$Configuration = 'Debug',
  5. [switch]$SkipPerformance
  6. )
  7. Set-StrictMode -Version Latest
  8. $ErrorActionPreference = 'Stop'
  9. $projectRoot = Split-Path -Parent $PSScriptRoot
  10. $qtRoot = 'D:\Qt5.15.2\5.15.2\mingw81_64'
  11. $mingwBin = 'D:\Qt5.15.2\Tools\mingw810_64\bin'
  12. $qmakePath = Join-Path $qtRoot 'bin\qmake.exe'
  13. $makePath = Join-Path $mingwBin 'mingw32-make.exe'
  14. $configurationName = $Configuration.ToLowerInvariant()
  15. $testSourceRoot = Join-Path $projectRoot 'app\tests'
  16. $buildRoot = Join-Path $projectRoot "build\tests\$configurationName"
  17. foreach ($requiredPath in @($qmakePath, $makePath, $testSourceRoot)) {
  18. if (-not (Test-Path -LiteralPath $requiredPath)) {
  19. throw "未找到必要文件:$requiredPath"
  20. }
  21. }
  22. $targets = @(
  23. 'domain_tests',
  24. 'alarm_service_tests',
  25. 'hmi_editor_service_tests',
  26. 'logic_editor_service_tests',
  27. 'offline_simulation_service_tests',
  28. 'project_management_tests',
  29. 'register_monitor_service_tests',
  30. 'runtime_mode_service_tests',
  31. 'plc_runtime_tests',
  32. 'main_window_tests'
  33. )
  34. if (-not $SkipPerformance) {
  35. $targets += 'performance_tests'
  36. }
  37. $originalPath = $env:Path
  38. $originalPlatform = $env:QT_QPA_PLATFORM
  39. $env:Path = "$qtRoot\bin;$mingwBin;$env:Path"
  40. $env:QT_QPA_PLATFORM = 'offscreen'
  41. try {
  42. foreach ($target in $targets) {
  43. $projectFile = Join-Path $testSourceRoot "$target.pro"
  44. $buildDirectory = Join-Path $buildRoot $target
  45. $executablePath = Join-Path $buildDirectory "$configurationName\$target.exe"
  46. New-Item -ItemType Directory -Path $buildDirectory -Force | Out-Null
  47. Push-Location $buildDirectory
  48. try {
  49. & $qmakePath $projectFile "CONFIG+=$configurationName" "CONFIG-=$(if ($configurationName -eq 'debug') { 'release' } else { 'debug' })"
  50. if ($LASTEXITCODE -ne 0) {
  51. throw "qmake 失败:$target,退出码:$LASTEXITCODE"
  52. }
  53. & $makePath -j2
  54. if ($LASTEXITCODE -ne 0) {
  55. throw "构建失败:$target,退出码:$LASTEXITCODE"
  56. }
  57. if (-not (Test-Path -LiteralPath $executablePath)) {
  58. throw "未生成测试可执行文件:$executablePath"
  59. }
  60. Write-Host "运行 $target"
  61. & $executablePath
  62. if ($LASTEXITCODE -ne 0) {
  63. throw "测试失败:$target,退出码:$LASTEXITCODE"
  64. }
  65. }
  66. finally {
  67. Pop-Location
  68. }
  69. }
  70. }
  71. finally {
  72. $env:Path = $originalPath
  73. if ($null -eq $originalPlatform) {
  74. Remove-Item Env:QT_QPA_PLATFORM -ErrorAction SilentlyContinue
  75. } else {
  76. $env:QT_QPA_PLATFORM = $originalPlatform
  77. }
  78. }