forked from obsproject/obs-deps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build-Dependencies.ps1
245 lines (200 loc) · 6.87 KB
/
Build-Dependencies.ps1
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
[CmdletBinding()]
param(
[ValidateSet('Debug', 'RelWithDebInfo', 'Release', 'MinSizeRel')]
[string] $Configuration = 'Release',
[string[]] $Dependencies,
[ValidateSet('x86', 'x64')]
[string] $Target,
[switch] $Clean,
[switch] $Quiet,
[switch] $Shared,
[switch] $SkipAll,
[switch] $SkipBuild,
[switch] $SkipDeps,
[switch] $SkipUnpack,
[switch] $VSPrerelease
)
$ErrorActionPreference = "Stop"
if ( $DebugPreference -eq "Continue" ) {
$VerbosePreference = "Continue"
$InformationPreference = "Continue"
}
if ( $PSVersionTable.PSVersion -lt '7.2.0' ) {
Write-Warning 'The obs-deps PowerShell build script requires PowerShell Core 7.2+. Install or upgrade your PowerShell version: https://aka.ms/pscore6'
exit 0
}
function Run-Stages {
$Stages = @('Setup')
if ( ( $SkipAll ) -or ( $SkipBuild ) ) {
$Stages += @('Install', 'Fixup')
} else {
if ( $Clean ) {
$Stages += 'Clean'
}
$Stages += @(
'Patch'
'Configure'
'Build'
'Install'
'Fixup'
)
}
Log-Debug $DependencyFiles
$DependencyFiles | Sort | ForEach-Object {
$Dependency = $_
$Version = 0
$Uri = ''
$Hash = ''
$Path = ''
$Versions = @()
$Hashes = @()
$Uris = @()
$Patches = @()
$Options = @{}
$Targets = @($script:Target)
. $Dependency
if ( ! ( $Targets.contains($Target) ) ) {
$Stages | ForEach-Object {
Log-Debug "Removing function $_"
Remove-Item -ErrorAction 'SilentlyContinue' function:$_
$script:StageName = ''
}
return
}
if ( $Version -eq '' ) { $Version = $Versions[$Target] }
if ( $Uri -eq '' ) { $Uri = $Uris[$Target] }
if ( $Hash -eq '' ) { $Hash = $Hashes[$Target] }
if ( $Path -eq '' ) { $Path = [System.IO.Path]::GetFileNameWithoutExtension($Uri) }
Log-Output 'Initializing build'
$Stages | ForEach-Object {
$Stage = $_
$script:StageName = $Name
try {
Push-Location -Stack BuildTemp
if ( Test-Path function:$Stage ) {
. $Stage
}
} catch {
Pop-Location -Stack BuildTemp
Log-Error "Error during build step ${Stage} - $_"
} finally {
$StageName = ''
Pop-Location -Stack BuildTemp
}
}
$Stages | ForEach-Object {
Log-Debug "Removing function $_"
Remove-Item -ErrorAction 'SilentlyContinue' function:$_
$script:StageName = ''
}
if ( Test-Path "$PSScriptRoot/licenses/${Name}" ) {
Log-Information "Install license files"
$null = New-Item -ItemType Directory -Path "$($ConfigData.OutputPath)/licenses" -ErrorAction SilentlyContinue
Copy-Item -Path "$PSScriptRoot/licenses/${Name}" -Recurse -Force -Destination "$($ConfigData.OutputPath)/licenses"
}
}
}
function Package-Dependencies {
if ( $script:PackageName -like 'qt*' ) {
$ArchiveFileName = "windows-deps-${PackageName}-${CurrentDate}-${Target}-${Configuration}.zip"
} else {
$ArchiveFileName = "windows-${PackageName}-${CurrentDate}-${Target}.zip"
}
Push-Location -Stack BuildTemp
Set-Location $ConfigData.OutputPath
Log-Information "Cleanup unnecessary files"
$Items = @(
"./bin/bison.exe"
"./bin/libiconv2.dll"
"./bin/libintl3.dll"
"./bin/m4.exe"
"./bin/pcre2*"
"./bin/regex2.dll"
"./cmake/pcre2*"
"./include/pcre2*"
"./lib/pcre2*"
"./lib/pkgconfig/libpcre2*"
"./man1/pcre2*"
"./man3/pcre2*"
"./share/bison"
"./share/doc/pcre2"
)
Remove-Item -ErrorAction 'SilentlyContinue' -Path $Items -Force -Recurse
$Params = @{
ErrorAction = "SilentlyContinue"
Path = @(
"share/obs-deps"
)
ItemType = "Directory"
Force = $true
}
New-Item @Params *> $null
"$(Get-Date -Format "yyyy-MM-dd")" > share/obs-deps/VERSION
Log-Information "Package dependencies"
$Params = @{
Path = (Get-ChildItem -Path $(Get-Location))
DestinationPath = $ArchiveFileName
CompressionLevel = "Optimal"
}
Log-Information "Create archive ${ArchiveFileName}"
Compress-Archive @Params
Move-Item -Force -Path $ArchiveFileName -Destination ..
Pop-Location -Stack BuildTemp
}
function Build-Main {
trap {
Write-Host '---------------------------------------------------------------------------------------------------'
Write-Host -NoNewLine '[OBS-DEPS] '
Write-Host -ForegroundColor Red 'Error(s) occurred:'
Write-Host '---------------------------------------------------------------------------------------------------'
Write-Error $_
exit 2
}
$script:PackageName = ((Get-Item $PSCommandPath).Basename).Split('-')[1]
if ( $script:PackageName -eq 'Dependencies' ) {
$script:PackageName = 'deps'
}
if ( $Dependencies -eq 'qt5' ) {
$script:PackageName = 'qt5'
} elseif ( $Dependencies -eq 'qt6' ) {
$script:PackageName = 'qt6'
}
$UtilityFunctions = Get-ChildItem -Path $PSScriptRoot/utils.pwsh/*.ps1 -Recurse
foreach($Utility in $UtilityFunctions) {
Write-Debug "Loading $($Utility.FullName)"
. $Utility.FullName
}
Bootstrap
$SubDir = ''
if ( $script:PackageName -like 'qt*' ) {
$SubDir = 'deps.qt'
} else {
$SubDir = 'deps.windows'
}
if ( $Dependencies.Count -eq 0 ) {
$DependencyFiles = Get-ChildItem -Path $PSScriptRoot/${SubDir}/*.ps1 -File -Recurse
} else {
$DependencyFiles = $Dependencies | ForEach-Object {
$Item = $_
try {
Get-ChildItem $PSScriptRoot/${SubDir}/*$Item.ps1
} catch {
throw "Script for requested dependency ${Item} not found"
}
}
}
Log-Debug "Using found dependency scripts:`n${DependencyFiles}"
Push-Location -Stack BuildTemp
Ensure-Location $WorkRoot
Run-Stages
Pop-Location -Stack BuildTemp
if ( $Dependencies.Count -eq 0 -or $script:PackageName -like 'qt*' ) {
Package-Dependencies
}
Write-Host '---------------------------------------------------------------------------------------------------'
Write-Host -NoNewLine '[OBS-DEPS] '
Write-Host -ForegroundColor Green 'All done'
Write-Host "Built Dependencies: $(if ( $Dependencies -eq $null ) { 'All' } else { $Dependencies })"
Write-Host '---------------------------------------------------------------------------------------------------'
}
Build-Main