-
Notifications
You must be signed in to change notification settings - Fork 7
/
.run.ps1
75 lines (66 loc) · 1.92 KB
/
.run.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
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
. .\tools\Exec.ps1
. .\tools\Invoke-BatchFile.ps1
function getExternalArguments {
param ([String[]]$arguments)
[String[]]$extArgs = @()
$i = [array]::indexof($arguments, "--")
if ( $i -ne -1 ) {
$__, $extArgs = $arguments[$i..($arguments.length - 1)]
}
$extArgs
}
function loadBuildEnvironment {
$vswhere = Resolve-Path "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$vsDir = & $vswhere -latest `
-requires Microsoft.VisualStudio.Workload.NativeDesktop `
-property installationPath
if (-not $vsDir) {
throw 'Some of the required workloads/components of Visual Studio are not installed.'
}
Invoke-BatchFile "$vsDir\VC\Auxiliary\Build\vcvars64.bat"
}
if ($args.Length -lt 1) {
throw 'No task is specified.'
}
Set-Location $PSScriptRoot
$errorMsg = "Command execution failed"
switch -regex ($args[0]) {
'^init-vcpkg$' {
Set-Location vcpkg
Exec { .\bootstrap-vcpkg.bat } $errorMsg
Exec { .\vcpkg remove --outdated --recurse } $errorMsg
Exec { .\vcpkg install '@..\vcpkg.txt' --triplet=x64-windows } $errorMsg
break
}
'^cmake$' {
loadBuildEnvironment
New-Item build -ItemType Directory -Force
Set-Location build
$extArgs = getExternalArguments $args
Exec { cmake .. -GNinja $extArgs } $errorMsg
break
}
'^b(uild)?$' {
loadBuildEnvironment
Set-Location build
Exec { ninja } $errorMsg
break
}
'^r(un)?$' {
$bin = $args[1]
$extArgs = getExternalArguments $args
Exec { & .\build\$bin $extArgs } $errorMsg
break
}
'^t(est)?$' {
loadBuildEnvironment
Set-Location build
Exec { ctest -V } $errorMsg
break
}
default {
throw "Unknown task: '$($args[0])'"
}
}