Setup-Host.ps1 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. function Setup-Host {
  2. if ( ! ( Test-Path function:Log-Output ) ) {
  3. . $PSScriptRoot/Logger.ps1
  4. }
  5. if ( ! ( Test-Path function:Ensure-Location ) ) {
  6. . $PSScriptRoot/Ensure-Location.ps1
  7. }
  8. if ( ! ( Test-Path function:Install-BuildDependencies ) ) {
  9. . $PSScriptRoot/Install-BuildDependencies.ps1
  10. }
  11. Install-BuildDependencies -WingetFile "${ScriptHome}/.Wingetfile"
  12. if ( $script:Target -eq '' ) { $script:Target = $script:HostArchitecture }
  13. Push-Location -Stack BuildTemp
  14. Log-Information 'Setting up obs-deps...'
  15. $DepsVersion = $BuildSpec.dependencies.'obs-deps'."windows-${script:Target}".version
  16. $DepsHash = $BuildSpec.dependencies.'obs-deps'."windows-${script:Target}".hash
  17. if ( ${DepsVersion} -eq '' ) {
  18. throw 'No obs-deps version found in buildspec.json.'
  19. }
  20. Log-Status 'Found obs-deps specification.'
  21. Ensure-Location -Path "$(Resolve-Path -Path "${ProjectRoot}/..")/obs-build-dependencies"
  22. if ( ! ( Test-Path -Path "windows-deps-${DepsVersion}-${script:Target}.zip" ) ) {
  23. $Params = @{
  24. UserAgent = 'NativeHost'
  25. Uri = "https://github.com/obsproject/obs-deps/releases/download/win-${DepsVersion}/windows-deps-${DepsVersion}-${script:Target}.zip"
  26. OutFile = "windows-deps-${DepsVersion}-${script:Target}.zip"
  27. UseBasicParsing = $true
  28. ErrorAction = 'Stop'
  29. }
  30. Invoke-WebRequest @Params
  31. Log-Status "Downloaded obs-deps for ${script:Target}."
  32. } else {
  33. Log-Status 'Found downloaded obs-deps.'
  34. }
  35. $FileHash = Get-FileHash -Path "windows-deps-${DepsVersion}-${script:Target}.zip" -Algorithm SHA256
  36. if ( $FileHash.Hash.ToLower() -ne $DepsHash ) {
  37. throw "Checksum mismatch of obs-deps download. Expected '${DepsHash}', found '$(${FileHash}.Hash.ToLower())'"
  38. }
  39. Log-Status 'Checksum of downloaded obs-deps matches.'
  40. Ensure-Location -Path "plugin-deps-${Target}"
  41. if ( ! ( Test-Path function:Expand-ArchiveExt ) ) {
  42. . $PSScriptRoot/Expand-ArchiveExt.ps1
  43. }
  44. Log-Information 'Extracting obs-deps...'
  45. Expand-ArchiveExt -Path "../windows-deps-${DepsVersion}-${script:Target}.zip" -DestinationPath . -Force
  46. Pop-Location -Stack BuildTemp
  47. Push-Location -Stack BuildTemp
  48. Log-Information 'Setting up Qt...'
  49. $QtVersion = $BuildSpec.dependencies.'obs-deps-qt'."windows-${script:Target}".version
  50. $QtHash = $BuildSpec.dependencies.'obs-deps-qt'."windows-${script:Target}".hash
  51. if ( ${QtVersion} -eq '' ) {
  52. throw 'No Qt version found in buildspec.json.'
  53. }
  54. Log-Status 'Found Qt specification.'
  55. Ensure-Location -Path "$(Resolve-Path -Path "${ProjectRoot}/..")/obs-build-dependencies"
  56. if ( ! ( Test-Path -Path "windows-deps-qt-${DepsVersion}-${script:Target}.zip" ) ) {
  57. $Params = @{
  58. UserAgent = 'NativeHost'
  59. Uri = "https://cdn-fastly.obsproject.com/downloads/windows-deps-qt-${DepsVersion}-${script:Target}.zip"
  60. OutFile = "windows-deps-qt-${DepsVersion}-${script:Target}.zip"
  61. UseBasicParsing = $true
  62. ErrorAction = 'Stop'
  63. }
  64. Invoke-WebRequest @Params
  65. Log-Status "Downloaded Qt for ${script:Target}."
  66. } else {
  67. Log-Status 'Found downloaded Qt.'
  68. }
  69. $FileHash = Get-FileHash -Path "windows-deps-qt-${DepsVersion}-${script:Target}.zip" -Algorithm SHA256
  70. if ( $FileHash.Hash.ToLower() -ne ${QtHash} ) {
  71. throw "Checksum mismatch of Qt download. Expected '${QtHash}', found '$(${FileHash}.Hash.ToLower())'"
  72. }
  73. Log-Status 'Checksum of downloaded Qt matches.'
  74. Ensure-Location -Path "plugin-deps-${Target}"
  75. Log-Information 'Extracting Qt...'
  76. Expand-ArchiveExt -Path "../windows-deps-qt-${DepsVersion}-${script:Target}.zip" -DestinationPath . -Force
  77. Pop-Location -Stack BuildTemp
  78. }
  79. function Get-HostArchitecture {
  80. $Host64Bit = [System.Environment]::Is64BitOperatingSystem
  81. $HostArchitecture = ('x86', 'x64')[$Host64Bit]
  82. return $HostArchitecture
  83. }
  84. $script:HostArchitecture = Get-HostArchitecture