Setup-Host.ps1 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. if ( ! ( Test-Path function:Expand-ArchiveExt ) ) {
  12. . $PSScriptRoot/Expand-ArchiveExt.ps1
  13. }
  14. Install-BuildDependencies -WingetFile "${ScriptHome}/.Wingetfile"
  15. if ( $script:Target -eq '' ) { $script:Target = $script:HostArchitecture }
  16. $script:QtVersion = $BuildSpec.platformConfig."windows-${script:Target}".qtVersion
  17. $script:VisualStudioVersion = $BuildSpec.platformConfig."windows-${script:Target}".visualStudio
  18. $script:PlatformSDK = $BuildSpec.platformConfig."windows-${script:Target}".platformSDK
  19. if ( ! ( ( $script:SkipAll ) -or ( $script:SkipDeps ) ) ) {
  20. ('prebuilt', "qt${script:QtVersion}") | ForEach-Object {
  21. $_Dependency = $_
  22. $_Version = $BuildSpec.dependencies."${_Dependency}".version
  23. $_BaseUrl = $BuildSpec.dependencies."${_Dependency}".baseUrl
  24. $_Label = $BuildSpec.dependencies."${_Dependency}".label
  25. $_Hash = $BuildSpec.dependencies."${_Dependency}".hashes."windows-${script:Target}"
  26. if ( $BuildSpec.dependencies."${_Dependency}".PSobject.Properties.Name -contains "pdb-hashes" ) {
  27. $_PdbHash = $BuildSpec.dependencies."${_Dependency}".'pdb-hashes'."$windows-${script:Target}"
  28. }
  29. if ( $_Version -eq '' ) {
  30. throw "No ${_Dependency} spec found in ${script:BuildSpecFile}."
  31. }
  32. Log-Information "Setting up ${_Label}..."
  33. Push-Location -Stack BuildTemp
  34. Ensure-Location -Path "$(Resolve-Path -Path "${ProjectRoot}/..")/obs-build-dependencies"
  35. switch -wildcard ( $_Dependency ) {
  36. prebuilt {
  37. $_Filename = "windows-deps-${_Version}-${script:Target}.zip"
  38. $_Uri = "${_BaseUrl}/${_Version}/${_Filename}"
  39. $_Target = "plugin-deps-${_Version}-qt${script:QtVersion}-${script:Target}"
  40. $script:DepsVersion = ${_Version}
  41. }
  42. "qt*" {
  43. $_Filename = "windows-deps-qt${script:QtVersion}-${_Version}-${script:Target}.zip"
  44. $_Uri = "${_BaseUrl}/${_Version}/${_Filename}"
  45. $_Target = "plugin-deps-${_Version}-qt${script:QtVersion}-${script:Target}"
  46. }
  47. }
  48. if ( ! ( Test-Path -Path $_Filename ) ) {
  49. $Params = @{
  50. UserAgent = 'NativeHost'
  51. Uri = $_Uri
  52. OutFile = $_Filename
  53. UseBasicParsing = $true
  54. ErrorAction = 'Stop'
  55. }
  56. Invoke-WebRequest @Params
  57. Log-Status "Downloaded ${_Label} for ${script:Target}."
  58. } else {
  59. Log-Status "Found downloaded ${_Label}."
  60. }
  61. $_FileHash = Get-FileHash -Path $_Filename -Algorithm SHA256
  62. if ( $_FileHash.Hash.ToLower() -ne $_Hash ) {
  63. throw "Checksum of downloaded ${_Label} does not match specification. Expected '${_Hash}', 'found $(${_FileHash}.Hash.ToLower())'"
  64. }
  65. Log-Status "Checksum of downloaded ${_Label} matches."
  66. if ( ! ( ( $script:SkipAll ) -or ( $script:SkipUnpack ) ) ) {
  67. Push-Location -Stack BuildTemp
  68. Ensure-Location -Path $_Target
  69. Expand-ArchiveExt -Path "../${_Filename}" -DestinationPath . -Force
  70. Pop-Location -Stack BuildTemp
  71. }
  72. Pop-Location -Stack BuildTemp
  73. }
  74. }
  75. }
  76. function Get-HostArchitecture {
  77. $Host64Bit = [System.Environment]::Is64BitOperatingSystem
  78. $HostArchitecture = ('x86', 'x64')[$Host64Bit]
  79. return $HostArchitecture
  80. }
  81. $script:HostArchitecture = Get-HostArchitecture