build_support_windows.ps1 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. $CIWorkflow = "${CheckoutDir}/.github/workflows/main.yml"
  2. $CIDepsVersion = Get-Content ${CIWorkflow} | Select-String "[ ]+DEPS_VERSION_WIN: '([0-9\-]+)'" | ForEach-Object{$_.Matches.Groups[1].Value}
  3. $CIQtVersion = Get-Content ${CIWorkflow} | Select-String "[ ]+QT_VERSION_WIN: '([0-9\.]+)'" | ForEach-Object{$_.Matches.Groups[1].Value}
  4. $CIObsVersion = Get-Content ${CIWorkflow} | Select-String "[ ]+OBS_VERSION: '([0-9\.]+)'" | ForEach-Object{$_.Matches.Groups[1].Value}
  5. function Write-Status {
  6. param(
  7. [parameter(Mandatory=$true)]
  8. [string] $output
  9. )
  10. if (!($Quiet.isPresent)) {
  11. if (Test-Path env:CI) {
  12. Write-Host "[${ProductName}] ${output}"
  13. } else {
  14. Write-Host -ForegroundColor blue "[${ProductName}] ${output}"
  15. }
  16. }
  17. }
  18. function Write-Info {
  19. param(
  20. [parameter(Mandatory=$true)]
  21. [string] $output
  22. )
  23. if (!($Quiet.isPresent)) {
  24. if (Test-Path env:CI) {
  25. Write-Host " + ${output}"
  26. } else {
  27. Write-Host -ForegroundColor DarkYellow " + ${output}"
  28. }
  29. }
  30. }
  31. function Write-Step {
  32. param(
  33. [parameter(Mandatory=$true)]
  34. [string] $output
  35. )
  36. if (!($Quiet.isPresent)) {
  37. if (Test-Path env:CI) {
  38. Write-Host " + ${output}"
  39. } else {
  40. Write-Host -ForegroundColor green " + ${output}"
  41. }
  42. }
  43. }
  44. function Write-Error {
  45. param(
  46. [parameter(Mandatory=$true)]
  47. [string] $output
  48. )
  49. if (Test-Path env:CI) {
  50. Write-Host " + ${output}"
  51. } else {
  52. Write-Host -ForegroundColor red " + ${output}"
  53. }
  54. }
  55. function Test-CommandExists {
  56. param(
  57. [parameter(Mandatory=$true)]
  58. [string] $Command
  59. )
  60. $CommandExists = $false
  61. $OldActionPref = $ErrorActionPreference
  62. $ErrorActionPreference = "stop"
  63. try {
  64. if (Get-Command $Command) {
  65. $CommandExists = $true
  66. }
  67. } Catch {
  68. $CommandExists = $false
  69. } Finally {
  70. $ErrorActionPreference = $OldActionPref
  71. }
  72. return $CommandExists
  73. }
  74. function Ensure-Directory {
  75. param(
  76. [parameter(Mandatory=$true)]
  77. [string] $Directory
  78. )
  79. if (!(Test-Path $Directory)) {
  80. $null = New-Item -ItemType Directory -Force -Path $Directory
  81. }
  82. Set-Location -Path $Directory
  83. }
  84. $BuildDirectory = "$(if (Test-Path Env:BuildDirectory) { $env:BuildDirectory } else { $BuildDirectory })"
  85. $BuildConfiguration = "$(if (Test-Path Env:BuildConfiguration) { $env:BuildConfiguration } else { $BuildConfiguration })"
  86. $BuildArch = "$(if (Test-Path Env:BuildArch) { $env:BuildArch } else { $BuildArch })"
  87. $OBSBranch = "$(if (Test-Path Env:OBSBranch) { $env:OBSBranch } else { $OBSBranch })"
  88. $WindowsDepsVersion = "$(if (Test-Path Env:WindowsDepsVersion ) { $env:WindowsDepsVersion } else { $CIDepsVersion })"
  89. $WindowsQtVersion = "$(if (Test-Path Env:WindowsQtVersion ) { $env:WindowsQtVersion } else { $CIQtVersion }")
  90. $CmakeSystemVersion = "$(if (Test-Path Env:CMAKE_SYSTEM_VERSION) { $Env:CMAKE_SYSTEM_VERSION } else { "10.0.18363.657" })"
  91. $OBSVersion = "$(if ( Test-Path Env:OBSVersion ) { $env:ObsVersion } else { $CIObsVersion })"
  92. function Install-Windows-Dependencies {
  93. Write-Status "Checking Windows build dependencies"
  94. $ObsBuildDependencies = @(
  95. @("7z", "7zip"),
  96. @("cmake", "cmake --install-arguments 'ADD_CMAKE_TO_PATH=System'"),
  97. @("iscc", "innosetup")
  98. )
  99. if(!(Test-CommandExists "choco")) {
  100. Set-ExecutionPolicy AllSigned
  101. Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
  102. }
  103. Foreach($Dependency in $ObsBuildDependencies) {
  104. if($Dependency -is [system.array]) {
  105. $Command = $Dependency[0]
  106. $ChocoName = $Dependency[1]
  107. } else {
  108. $Command = $Dependency
  109. $ChocoName = $Dependency
  110. }
  111. if(!(Test-CommandExists "${Command}")) {
  112. Invoke-Expression "choco install -y ${ChocoName}"
  113. }
  114. }
  115. $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
  116. }