forked from dotnet/pinvoke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
131 lines (113 loc) · 4.59 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
<#
.Synopsis
Acquires dependencies, builds, and tests this project.
.Description
If no actions are specified, the default is to run all actions.
.Parameter Restore
Restore NuGet packages.
.Parameter Build
Build the entire project. Requires that -Restore is or has been executed.
.Parameter Test
Run all built tests.
.Parameter Configuration
The configuration to build. Either "debug" or "release". The default is debug, or the Configuration environment variable if set.
.Parameter WarnAsError
Converts all build warnings to errors. Useful in preparation to sending a pull request.
.Parameter GeneratePInvokesTxt
Produces the LIBNAME.pinvokes.txt files along with the assemblies during the build.
.Parameter NoParallelTests
Do not execute tests in parallel.
#>
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='Medium')]
Param(
[switch]$Restore,
[switch]$Build,
[switch]$Test,
[Parameter()][ValidateSet('debug', 'release')]
[string]$Configuration = $env:configuration,
[switch]$WarnAsError = $true,
[switch]$GeneratePInvokesTxt,
[switch]$NoParallelTests
)
if (!$Configuration) { $Configuration = 'debug' }
$NothingToDo = !($Restore -or $Build -or $Test)
if ($NothingToDo) {
Write-Output "No actions specified. Applying default actions."
$Restore = $true
$Build = $true
$Test = $true
}
# External dependencies
$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/v3.3.0/nuget.exe"
# Path variables
$ProjectRoot = Split-Path -parent $PSCommandPath
$SolutionFolder = Join-Path $ProjectRoot src
$SolutionFile = Join-Path $SolutionFolder "PInvoke.sln"
$ToolsFolder = Join-Path $ProjectRoot tools
$BinFolder = Join-Path $ProjectRoot "bin"
$BinConfigFolder = Join-Path $BinFolder $Configuration
$BinTestsFolder = Join-Path $BinConfigFolder "tests"
$PackageRestoreRoot = Join-Path $env:userprofile '.nuget/packages/'
# Set script scope for external tool variables.
$MSBuildCommand = Get-Command MSBuild.exe -ErrorAction SilentlyContinue
Function Get-ExternalTools {
if (!$MSBuildCommand) {
Write-Error "Unable to find MSBuild.exe. Make sure you're running in a VS Developer Prompt."
exit 1;
}
}
Get-ExternalTools
if ($Restore -and $PSCmdlet.ShouldProcess($SolutionFile, "Restore packages")) {
Write-Output "Restoring NuGet packages..."
# Workaround NuGet/Home#4790 - this gets Nerdbank.GitVersioning into the package cache
& $MSBuildCommand.Path /t:restore /nologo /m "$SolutionFolder\Windows.Core\Windows.Core.csproj"
# Now do the simple thing that SHOULD be the only requirement
& $MSBuildCommand.Path /t:restore /nologo /m $SolutionFile
# Workaround NuGet/Home#4753
& $MSBuildCommand.Path /t:restore /nologo /m "$SolutionFolder\NtDll.Tests\NtDll.Tests.csproj"
& $MSBuildCommand.Path /t:restore /nologo /m "$SolutionFolder\WtsApi32.Tests\WtsApi32.Tests.csproj"
}
if ($Build -and $PSCmdlet.ShouldProcess($SolutionFile, "Build")) {
$buildArgs = @()
$buildArgs += $SolutionFile,'/nologo','/nr:false','/m','/v:minimal','/t:build,pack'
$buildArgs += '/fl','/flp:verbosity=normal;logfile=msbuild.log','/flp1:warningsonly;logfile=msbuild.wrn;NoSummary;verbosity=minimal','/flp2:errorsonly;logfile=msbuild.err;NoSummary;verbosity=minimal'
if ($GeneratePInvokesTxt) {
$buildArgs += '/p:GeneratePInvokesTxt=true'
}
Write-Output "Building..."
& $MSBuildCommand.Path $buildArgs
$fail = $false
$warnings = Get-Content msbuild.wrn
$errors = Get-Content msbuild.err
$WarningsPrompt = "$(($warnings | Measure-Object -Line).Lines) warnings during build"
$ErrorsPrompt = "$(($errors | Measure-Object -Line).Lines) errors during build"
if ($errors.length -gt 0) {
Write-Error $ErrorsPrompt
$fail = $true
} else {
Write-Output $ErrorsPrompt
}
if ($WarnAsError -and $warnings.length -gt 0) {
Write-Error $WarningsPrompt
$fail = $true
} elseif ($warnings.length -gt 0) {
Write-Warning $WarningsPrompt
} else {
Write-Output $WarningsPrompt
}
if ($fail) {
exit 3;
}
}
if ($Test -and $PSCmdlet.ShouldProcess('Test assemblies')) {
$TestAssemblies = Get-ChildItem -Recurse "$BinTestsFolder\*.Tests.dll"
Write-Output "Testing..."
$xunitRunner = Join-Path $PackageRestoreRoot 'xunit.runner.console/2.2.0/tools/xunit.console.x86.exe'
$xunitArgs = @()
$xunitArgs += $TestAssemblies
$xunitArgs += "-html","$BinTestsFolder\testresults.html","-xml","$BinTestsFolder\testresults.xml"
if (!$NoParallelTests) {
$xunitArgs += "-parallel","all"
}
& $xunitRunner $xunitArgs
}