зеркало из https://github.com/dotnet/pinvoke.git
132 строки
4.6 KiB
PowerShell
132 строки
4.6 KiB
PowerShell
<#
|
|
.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
|
|
}
|