Repository navigation
Expand file tree
/
Copy pathbuild.ps1
More file actions
287 lines (244 loc) · 9.36 KB
/
Copy pathbuild.ps1
File metadata and controls
287 lines (244 loc) · 9.36 KB
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
[CmdletBinding()]
param(
[ValidateSet('Debug', 'Release')]
[string]$Configuration = 'Release',
[ValidateSet('x64', 'ARM64')]
[string[]]$Platforms = @('x64', 'ARM64'),
[switch]$SkipNative,
[switch]$SkipNativeTests,
[switch]$SkipManagedTests,
[switch]$SkipPack,
[ValidateSet('quiet', 'minimal', 'normal', 'detailed', 'diagnostic')]
[string]$Verbosity = 'minimal',
[string]$MSBuildPath
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function Resolve-MSBuildPath {
param(
[string]$ExplicitPath
)
if ($ExplicitPath) {
if (Test-Path -LiteralPath $ExplicitPath -PathType Leaf) {
return (Resolve-Path -LiteralPath $ExplicitPath).Path
}
throw "MSBuild was not found at '$ExplicitPath'."
}
$programFilesX86 = [Environment]::GetFolderPath('ProgramFilesX86')
$vswherePath = Join-Path $programFilesX86 'Microsoft Visual Studio\Installer\vswhere.exe'
if (Test-Path -LiteralPath $vswherePath -PathType Leaf) {
$queries = @(
@('-latest', '-products', '*', '-requires', 'Microsoft.Component.MSBuild', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64', '-find', 'MSBuild\Current\Bin\MSBuild.exe'),
@('-latest', '-products', '*', '-requires', 'Microsoft.Component.MSBuild', '-find', 'MSBuild\Current\Bin\MSBuild.exe')
)
foreach ($query in $queries) {
$matches = & $vswherePath @query
foreach ($match in $matches) {
if ($match -and (Test-Path -LiteralPath $match -PathType Leaf)) {
return $match
}
}
}
}
$programFiles = [Environment]::GetFolderPath('ProgramFiles')
$commonInstallRoots = @(
(Join-Path $programFiles 'Microsoft Visual Studio\18'),
(Join-Path $programFiles 'Microsoft Visual Studio\2022')
)
$editions = @('Community', 'Professional', 'Enterprise', 'BuildTools', 'Preview')
foreach ($root in $commonInstallRoots) {
foreach ($edition in $editions) {
$candidate = Join-Path $root "$edition\MSBuild\Current\Bin\MSBuild.exe"
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
return $candidate
}
}
}
throw @"
Could not find Visual Studio MSBuild.
Install Visual Studio with the "Desktop development with C++" workload, or pass -MSBuildPath with the full path to MSBuild.exe.
This repo contains C++ projects, so dotnet build alone cannot build the native layer.
"@
}
function Invoke-Process {
param(
[Parameter(Mandatory)]
[string]$FilePath,
[AllowEmptyCollection()]
[string[]]$Arguments = @()
)
Write-Host "> $FilePath $($Arguments -join ' ')"
& $FilePath @Arguments
if ($LASTEXITCODE -ne 0) {
throw "Command failed with exit code $LASTEXITCODE."
}
}
function Resolve-VSTestPath {
param(
[string]$MSBuild
)
$msbuildDirectory = Split-Path -Path $MSBuild -Parent
$vsRoot = Split-Path -Path (Split-Path -Path (Split-Path -Path $msbuildDirectory -Parent) -Parent) -Parent
$candidate = Join-Path $vsRoot 'Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe'
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
return $candidate
}
return $null
}
function Resolve-DumpBinPath {
param(
[string]$MSBuild
)
$msbuildDirectory = Split-Path -Path $MSBuild -Parent
$vsRoot = Split-Path -Path (Split-Path -Path (Split-Path -Path $msbuildDirectory -Parent) -Parent) -Parent
$vcToolsRoot = Join-Path $vsRoot 'VC\Tools\MSVC'
$candidate = Get-ChildItem -LiteralPath $vcToolsRoot -Recurse -File -Filter 'dumpbin.exe' |
Where-Object { $_.FullName.EndsWith('\bin\Hostx64\x64\dumpbin.exe', [StringComparison]::OrdinalIgnoreCase) } |
Sort-Object -Property FullName -Descending |
Select-Object -First 1
if ($candidate) {
return $candidate.FullName
}
throw 'Could not find the x64-hosted dumpbin.exe required for native binary verification.'
}
$repoRoot = $PSScriptRoot
$msbuild = Resolve-MSBuildPath -ExplicitPath $MSBuildPath
$packageOutput = Join-Path $repoRoot 'artifacts\packages'
$solutionDirProperty = "/p:SolutionDir=$repoRoot\"
Write-Host "Using MSBuild: $msbuild"
Write-Host 'Using stable package version from Directory.Version.props.'
$vcpkgBootstrap = Join-Path $repoRoot 'vcpkg\bootstrap-vcpkg.bat'
$vcpkgExe = Join-Path $repoRoot 'vcpkg\vcpkg.exe'
if ((Test-Path -LiteralPath $vcpkgBootstrap -PathType Leaf) -and -not (Test-Path -LiteralPath $vcpkgExe -PathType Leaf)) {
Invoke-Process -FilePath $vcpkgBootstrap -Arguments @()
}
if (-not $SkipNative) {
foreach ($platform in $Platforms) {
foreach ($nativeProject in @(
'src\CaptureKit.Windows.Native.Recording\CaptureKit.Windows.Native.Recording.vcxproj',
'src\CaptureKit.Windows.Native.Screenshot\CaptureKit.Windows.Native.Screenshot.vcxproj'
)) {
Invoke-Process -FilePath $msbuild -Arguments @(
(Join-Path $repoRoot $nativeProject),
'/restore',
'/m',
'/nologo',
"/v:$Verbosity",
"/p:Configuration=$Configuration",
"/p:Platform=$platform",
$solutionDirProperty
)
}
}
$dumpBin = Resolve-DumpBinPath -MSBuild $msbuild
foreach ($platform in $Platforms) {
Invoke-Process -FilePath 'powershell' -Arguments @(
'-NoProfile',
'-ExecutionPolicy',
'Bypass',
'-File',
(Join-Path $repoRoot 'tools\Verify-NativeBinaries.ps1'),
'-DumpBinPath',
$dumpBin,
'-ArtifactRoot',
(Join-Path $repoRoot 'artifacts'),
'-Configuration',
$Configuration,
'-Platforms',
$platform
)
}
}
Invoke-Process -FilePath 'dotnet' -Arguments @(
'build',
(Join-Path $repoRoot 'src\CaptureKit.Abstractions\CaptureKit.Abstractions.csproj'),
'-c',
$Configuration
)
Invoke-Process -FilePath 'dotnet' -Arguments @(
'build',
(Join-Path $repoRoot 'src\CaptureKit.Windows\CaptureKit.Windows.csproj'),
'-c',
$Configuration
)
if (-not $SkipNativeTests -and -not $SkipNative -and $Platforms -contains 'x64') {
Invoke-Process -FilePath $msbuild -Arguments @(
(Join-Path $repoRoot 'tests\CaptureKit.Windows.Native.Tests\CaptureKit.Windows.Native.Tests.vcxproj'),
'/restore',
'/m',
'/nologo',
"/v:$Verbosity",
"/p:Configuration=$Configuration",
'/p:Platform=x64',
$solutionDirProperty
)
$vsTest = Resolve-VSTestPath -MSBuild $msbuild
if (-not $vsTest) {
throw 'Could not find vstest.console.exe for native test execution.'
}
$nativeTestDll = Get-ChildItem -Path $repoRoot -Recurse -File -Filter 'CaptureKit.Windows.Native.Tests.dll' |
Where-Object { $_.FullName -match "\\x64\\$Configuration\\" } |
Select-Object -First 1
if (-not $nativeTestDll) {
throw 'Could not find CaptureKit.Windows.Native.Tests.dll after building native tests.'
}
Invoke-Process -FilePath $vsTest -Arguments @($nativeTestDll.FullName, '/Platform:x64')
}
if (-not $SkipManagedTests) {
Invoke-Process -FilePath 'dotnet' -Arguments @(
'test',
(Join-Path $repoRoot 'tests\CaptureKit.Windows.Tests\CaptureKit.Windows.Tests.csproj'),
'-c',
$Configuration
)
}
if (-not $SkipPack) {
New-Item -ItemType Directory -Force -Path $packageOutput | Out-Null
Invoke-Process -FilePath 'dotnet' -Arguments @(
'pack',
(Join-Path $repoRoot 'src\CaptureKit.Abstractions\CaptureKit.Abstractions.csproj'),
'-c',
$Configuration,
'--no-build',
'-o',
$packageOutput
)
Invoke-Process -FilePath 'dotnet' -Arguments @(
'pack',
(Join-Path $repoRoot 'src\CaptureKit.Windows\CaptureKit.Windows.csproj'),
'-c',
$Configuration,
'--no-build',
'-o',
$packageOutput
)
if (-not $SkipNative) {
[xml] $versionProps = Get-Content -LiteralPath (Join-Path $repoRoot 'Directory.Version.props')
$packageVersion = [string] $versionProps.Project.PropertyGroup.CaptureKitVersion
if ([string]::IsNullOrWhiteSpace($packageVersion)) {
throw 'Could not read CaptureKitVersion from Directory.Version.props.'
}
$packageFilePattern = "CaptureKit.Windows.$packageVersion.nupkg"
$captureKitPackage = Get-ChildItem -LiteralPath $packageOutput -File -Filter $packageFilePattern |
Sort-Object -Property LastWriteTimeUtc -Descending |
Select-Object -First 1
if (-not $captureKitPackage) {
throw "Could not find the CaptureKit.Windows package matching '$packageFilePattern'."
}
foreach ($platform in $Platforms) {
Invoke-Process -FilePath 'powershell' -Arguments @(
'-NoProfile',
'-ExecutionPolicy',
'Bypass',
'-File',
(Join-Path $repoRoot 'tools\Verify-NuGetPackage.ps1'),
'-PackagePath',
$captureKitPackage.FullName,
'-DumpBinPath',
$dumpBin,
'-Platforms',
$platform
)
}
}
}