build_support_windows.ps1 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. $CIWorkflow = "${CheckoutDir}/.github/workflows/main.yml"
  2. $WorkflowContent = Get-Content ${CIWorkflow}
  3. $CIDepsVersion = ${WorkflowContent} | Select-String "[ ]+DEPS_VERSION_WIN: '([0-9\-]+)'" | ForEach-Object{$_.Matches.Groups[1].Value}
  4. $CIQtVersion = ${WorkflowContent} | Select-String "[ ]+QT_VERSION_WIN: '([0-9\.]+)'" | ForEach-Object{$_.Matches.Groups[1].Value}
  5. $CIVlcVersion = ${WorkflowContent} | Select-String "[ ]+VLC_VERSION_WIN: '(.+)'" | ForEach-Object{$_.Matches.Groups[1].Value}
  6. $CICefVersion = ${WorkflowContent} | Select-String "[ ]+CEF_BUILD_VERSION_WIN: '([0-9\.]+)'" | ForEach-Object{$_.Matches.Groups[1].Value}
  7. $CIGenerator = ${WorkflowContent} | Select-String "[ ]+CMAKE_GENERATOR: '(.+)'" | ForEach-Object{$_.Matches.Groups[1].Value}
  8. function Write-Status {
  9. Param(
  10. [Parameter(Mandatory=$true)]
  11. [String] $Output
  12. )
  13. if (!($Quiet.isPresent)) {
  14. if (Test-Path Env:CI) {
  15. Write-Host "[${ProductName}] ${Output}"
  16. } else {
  17. Write-Host -ForegroundColor blue "[${ProductName}] ${Output}"
  18. }
  19. }
  20. }
  21. function Write-Info {
  22. Param(
  23. [Parameter(Mandatory=$true)]
  24. [String] $Output
  25. )
  26. if (!($Quiet.isPresent)) {
  27. if (Test-Path Env:CI) {
  28. Write-Host " + ${Output}"
  29. } else {
  30. Write-Host -ForegroundColor DarkYellow " + ${Output}"
  31. }
  32. }
  33. }
  34. function Write-Step {
  35. Param(
  36. [Parameter(Mandatory=$true)]
  37. [String] $Output
  38. )
  39. if (!($Quiet.isPresent)) {
  40. if (Test-Path Env:CI) {
  41. Write-Host " + ${Output}"
  42. } else {
  43. Write-Host -ForegroundColor green " + ${Output}"
  44. }
  45. }
  46. }
  47. function Write-Failure {
  48. Param(
  49. [Parameter(Mandatory=$true)]
  50. [String] $Output
  51. )
  52. if (Test-Path Env:CI) {
  53. Write-Host " + ${Output}"
  54. } else {
  55. Write-Host -ForegroundColor red " + ${Output}"
  56. }
  57. }
  58. function Test-CommandExists {
  59. Param(
  60. [Parameter(Mandatory=$true)]
  61. [String] $Command
  62. )
  63. $CommandExists = $false
  64. $OldActionPref = $ErrorActionPreference
  65. $ErrorActionPreference = "stop"
  66. try {
  67. if (Get-Command $Command) {
  68. $CommandExists = $true
  69. }
  70. } Catch {
  71. $CommandExists = $false
  72. } Finally {
  73. $ErrorActionPreference = $OldActionPref
  74. }
  75. return $CommandExists
  76. }
  77. function Ensure-Directory {
  78. Param(
  79. [Parameter(Mandatory=$true)]
  80. [String] $Directory
  81. )
  82. if (!(Test-Path $Directory)) {
  83. $null = New-Item -ItemType Directory -Force -Path $Directory
  84. }
  85. Set-Location -Path $Directory
  86. }
  87. $BuildDirectory = "$(if (Test-Path Env:BuildDirectory) { $env:BuildDirectory } else { $BuildDirectory })"
  88. $BuildConfiguration = "$(if (Test-Path Env:BuildConfiguration) { $env:BuildConfiguration } else { $BuildConfiguration })"
  89. $BuildArch = "$(if (Test-Path Env:BuildArch) { $env:BuildArch } else { $BuildArch })"
  90. $WindowsDepsVersion = "$(if (Test-Path Env:WindowsDepsVersion ) { $env:WindowsDepsVersion } else { $CIDepsVersion })"
  91. $WindowsQtVersion = "$(if (Test-Path Env:WindowsQtVersion ) { $env:WindowsQtVersion } else { $CIQtVersion })"
  92. $WindowsVlcVersion = "$(if (Test-Path Env:WindowsVlcVersion ) { $env:WindowsVlcVersion } else { $CIVlcVersion })"
  93. $WindowsCefVersion = "$(if (Test-Path Env:WindowsCefVersion ) { $env:WindowsCefVersion } else { $CICefVersion })"
  94. $CmakeSystemVersion = "$(if (Test-Path Env:CMAKE_SYSTEM_VERSION) { $Env:CMAKE_SYSTEM_VERSION } else { "10.0.18363.657" })"
  95. $CmakeGenerator = "$(if (Test-Path Env:CmakeGenerator) { $Env:CmakeGenerator } else { $CIGenerator })"
  96. function Install-Windows-Dependencies {
  97. $WingetFile = "$PSScriptRoot/Wingetfile"
  98. $Host64Bit = [System.Environment]::Is64BitOperatingSystem
  99. $Prefix = (${Env:ProgramFiles(x86)}, $Env:ProgramFiles)[$Host64Bit]
  100. $Paths = $Env:Path -split [System.IO.Path]::PathSeparator
  101. $WingetOptions = @('install', '--accept-package-agreements', '--accept-source-agreements')
  102. if ( $script:Quiet ) {
  103. $WingetOptions += '--silent'
  104. }
  105. Get-Content $WingetFile | ForEach-Object {
  106. $_, $Package, $_, $Path, $_, $Binary = $_ -replace ',','' -replace "'", '' -split ' '
  107. $FullPath = "${Prefix}\${Path}"
  108. if ( ( Test-Path $FullPath ) -and ! ( $Paths -contains $FullPath ) ) {
  109. $Paths += $FullPath
  110. $Env:Path = $Paths -join [System.IO.Path]::PathSeparator
  111. }
  112. Write-Step "Checking for command ${Binary}"
  113. $Found = Get-Command -ErrorAction SilentlyContinue $Binary
  114. if ( $Found ) {
  115. Write-Info "Found dependency ${Binary} as $($Found.Source)"
  116. } else {
  117. Write-Info "Installing package ${Package}"
  118. try {
  119. $Params = $WingetOptions + $Package
  120. winget @Params
  121. } catch {
  122. throw "Error while installing winget package ${Package}: $_"
  123. }
  124. }
  125. }
  126. }