File: Setup-Host.ps1

package info (click to toggle)
obs-source-clone 0.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 492 kB
  • sloc: ansic: 948; makefile: 23; cpp: 16
file content (103 lines) | stat: -rwxr-xr-x 4,110 bytes parent folder | download | duplicates (39)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
function Setup-Host {
    if ( ! ( Test-Path function:Log-Output ) ) {
        . $PSScriptRoot/Logger.ps1
    }

    if ( ! ( Test-Path function:Ensure-Location ) ) {
        . $PSScriptRoot/Ensure-Location.ps1
    }

    if ( ! ( Test-Path function:Install-BuildDependencies ) ) {
        . $PSScriptRoot/Install-BuildDependencies.ps1
    }

    if ( ! ( Test-Path function:Expand-ArchiveExt ) ) {
        . $PSScriptRoot/Expand-ArchiveExt.ps1
    }

    Install-BuildDependencies -WingetFile "${ScriptHome}/.Wingetfile"

    if ( $script:Target -eq '' ) { $script:Target = $script:HostArchitecture }

    $script:QtVersion = $BuildSpec.platformConfig."windows-${script:Target}".qtVersion
    $script:VisualStudioVersion = $BuildSpec.platformConfig."windows-${script:Target}".visualStudio
    $script:PlatformSDK = $BuildSpec.platformConfig."windows-${script:Target}".platformSDK

    if ( ! ( ( $script:SkipAll ) -or ( $script:SkipDeps ) ) ) {
        ('prebuilt', "qt${script:QtVersion}") | ForEach-Object {
            $_Dependency = $_
            $_Version = $BuildSpec.dependencies."${_Dependency}".version
            $_BaseUrl = $BuildSpec.dependencies."${_Dependency}".baseUrl
            $_Label = $BuildSpec.dependencies."${_Dependency}".label
            $_Hash = $BuildSpec.dependencies."${_Dependency}".hashes."windows-${script:Target}"

            if ( $BuildSpec.dependencies."${_Dependency}".PSobject.Properties.Name -contains "pdb-hashes" ) {
                $_PdbHash = $BuildSpec.dependencies."${_Dependency}".'pdb-hashes'."$windows-${script:Target}"
            }

            if ( $_Version -eq '' ) {
                throw "No ${_Dependency} spec found in ${script:BuildSpecFile}."
            }

            Log-Information "Setting up ${_Label}..."

            Push-Location -Stack BuildTemp
            Ensure-Location -Path "$(Resolve-Path -Path "${ProjectRoot}/..")/obs-build-dependencies"

            switch -wildcard ( $_Dependency ) {
                prebuilt {
                    $_Filename = "windows-deps-${_Version}-${script:Target}.zip"
                    $_Uri = "${_BaseUrl}/${_Version}/${_Filename}"
                    $_Target = "plugin-deps-${_Version}-qt${script:QtVersion}-${script:Target}"
                    $script:DepsVersion = ${_Version}
                }
                "qt*" {
                    $_Filename = "windows-deps-qt${script:QtVersion}-${_Version}-${script:Target}.zip"
                    $_Uri = "${_BaseUrl}/${_Version}/${_Filename}"
                    $_Target = "plugin-deps-${_Version}-qt${script:QtVersion}-${script:Target}"
                }
            }

            if ( ! ( Test-Path -Path $_Filename ) ) {
                $Params = @{
                    UserAgent = 'NativeHost'
                    Uri = $_Uri
                    OutFile = $_Filename
                    UseBasicParsing = $true
                    ErrorAction = 'Stop'
                }

                Invoke-WebRequest @Params
                Log-Status "Downloaded ${_Label} for ${script:Target}."
            } else {
                Log-Status "Found downloaded ${_Label}."
            }

            $_FileHash = Get-FileHash -Path $_Filename -Algorithm SHA256

            if ( $_FileHash.Hash.ToLower() -ne $_Hash ) {
                throw "Checksum of downloaded ${_Label} does not match specification. Expected '${_Hash}', 'found $(${_FileHash}.Hash.ToLower())'"
            }
            Log-Status "Checksum of downloaded ${_Label} matches."

            if ( ! ( ( $script:SkipAll ) -or ( $script:SkipUnpack ) ) ) {
                Push-Location -Stack BuildTemp
                Ensure-Location -Path $_Target

                Expand-ArchiveExt -Path "../${_Filename}" -DestinationPath . -Force

                Pop-Location -Stack BuildTemp
            }
            Pop-Location -Stack BuildTemp
        }
    }
}

function Get-HostArchitecture {
    $Host64Bit = [System.Environment]::Is64BitOperatingSystem
    $HostArchitecture = ('x86', 'x64')[$Host64Bit]

    return $HostArchitecture
}

$script:HostArchitecture = Get-HostArchitecture