forked from terrafx/terrafx.interop.mimalloc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
149 lines (122 loc) · 4.74 KB
/
build.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
[CmdletBinding(PositionalBinding=$false)]
Param(
[ValidateSet("<auto>", "amd64", "x64", "x86", "arm64", "arm")][string] $architecture = "",
[switch] $build,
[switch] $ci,
[ValidateSet("Debug", "Release")][string] $configuration = "Debug",
[switch] $help,
[switch] $pack,
[switch] $restore,
[string] $solution = "",
[switch] $test,
[ValidateSet("quiet", "minimal", "normal", "detailed", "diagnostic")][string] $verbosity = "minimal",
[Parameter(ValueFromRemainingArguments=$true)][String[]] $properties
)
Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
function Build() {
$logFile = Join-Path -Path $LogDir -ChildPath "$configuration\build.binlog"
& dotnet build -c "$configuration" --no-restore -v "$verbosity" /p:Platform="Any CPU" /bl:"$logFile" /err "$properties" "$solution"
if ($LastExitCode -ne 0) {
throw "'Build' failed for '$solution'"
}
}
function Create-Directory([string[]] $Path) {
if (!(Test-Path -Path $Path)) {
New-Item -Path $Path -Force -ItemType "Directory" | Out-Null
}
}
function Help() {
Write-Host -Object "Common settings:"
Write-Host -Object " -configuration <value> Build configuration (Debug, Release)"
Write-Host -Object " -verbosity <value> Msbuild verbosity (q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic])"
Write-Host -Object " -help Print help and exit"
Write-Host -Object ""
Write-Host -Object "Actions:"
Write-Host -Object " -restore Restore dependencies"
Write-Host -Object " -build Build solution"
Write-Host -Object " -test Run all tests in the solution"
Write-Host -Object " -pack Package build artifacts"
Write-Host -Object ""
Write-Host -Object "Advanced settings:"
Write-Host -Object " -solution <value> Path to solution to build"
Write-Host -Object " -ci Set when running on CI server"
Write-Host -Object " -architecture <value> Test Architecture (<auto>, amd64, x64, x86, arm64, arm)"
Write-Host -Object ""
Write-Host -Object "Command line arguments not listed above are passed through to MSBuild."
Write-Host -Object "The above arguments can be shortened as much as to be unambiguous (e.g. -co for configuration, -t for test, etc.)."
}
function Pack() {
$logFile = Join-Path -Path $LogDir -ChildPath "$configuration\pack.binlog"
& dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /p:Platform="Any CPU" /bl:"$logFile" /err "$properties" "$solution"
if ($LastExitCode -ne 0) {
throw "'Pack' failed for '$solution'"
}
}
function Restore() {
$logFile = Join-Path -Path $LogDir -ChildPath "$configuration\restore.binlog"
& dotnet restore -v "$verbosity" /p:Platform="Any CPU" /bl:"$logFile" /err "$properties" "$solution"
if ($LastExitCode -ne 0) {
throw "'Restore' failed for '$solution'"
}
}
function Test() {
$logFile = Join-Path -Path $LogDir -ChildPath "$configuration\test.binlog"
& dotnet test -c "$configuration" --no-build --no-restore -v "$verbosity" /p:Platform="Any CPU" /bl:"$logFile" /err "$properties" "$solution"
if ($LastExitCode -ne 0) {
throw "'Test' failed for '$solution'"
}
}
try {
if ($help) {
Help
exit 0
}
if ($ci) {
$build = $true
$pack = $true
$restore = $true
$test = $true
if ($architecture -eq "") {
$architecture = "<auto>"
}
}
$RepoRoot = Join-Path -Path $PSScriptRoot -ChildPath ".."
if ($solution -eq "") {
$solution = Join-Path -Path $RepoRoot -ChildPath "TerraFX.Interop.Mimalloc.sln"
}
$ArtifactsDir = Join-Path -Path $RepoRoot -ChildPath "artifacts"
Create-Directory -Path $ArtifactsDir
$LogDir = Join-Path -Path $ArtifactsDir -ChildPath "log"
Create-Directory -Path $LogDir
if ($architecture -ne "") {
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
$env:DOTNET_MULTILEVEL_LOOKUP = 0
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
$DotNetInstallScript = Join-Path -Path $ArtifactsDir -ChildPath "dotnet-install.ps1"
Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile $DotNetInstallScript -UseBasicParsing
$DotNetInstallDirectory = Join-Path -Path $ArtifactsDir -ChildPath "dotnet"
Create-Directory -Path $DotNetInstallDirectory
& $DotNetInstallScript -Channel 8.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture
$env:PATH="$DotNetInstallDirectory;$env:PATH"
}
if ($restore) {
Restore
}
if ($build) {
Build
}
if ($test) {
Test
}
if ($pack) {
Pack
}
}
catch {
Write-Host -Object $_
Write-Host -Object $_.Exception
Write-Host -Object $_.ScriptStackTrace
exit 1
}