提交 37764733 编写于 作者: J Jared Parsons 提交者: Jared Parsons

Stop clearing LastExitCode

The clearing of $LastExitCode in our Exec function is masking failures
of windows commands.  Cannot understand why this is the case but easy to
demonstrate in practice.
上级 e6c7c941
......@@ -11,29 +11,35 @@ $ErrorActionPreference="Stop"
# fails.
#
# Original sample came from: http://jameskovacs.com/2010/02/25/the-exec-problem/
function Exec([scriptblock]$cmd, [string]$errorMessage = "Error executing command: " + $cmd) {
# Clear LastExitCode before invoking the script so a windows command failure
# before doesn't carry over. Can happen if the expression is pure powershell
# and not wrapping a windows command.
$lastexitcode = 0
$output = & $cmd
function Exec([scriptblock]$cmd, [switch]$echo = $false) {
if ($echo) {
& $cmd
}
else {
$output = & $cmd
}
# Need to check both of these cases for errors as they represent different items
# - $?: did the powershell script block throw an error
# - $lastexitcode: did a windows command executed by the script block end in error
if ((-not $?) -or ($lastexitcode -ne 0)) {
Write-Host $output
throw $errorMessage
if (-not $echo) {
Write-Host $output
}
throw "Command failed to execute: $cmd"
}
}
function Exec-Echo([scriptblock]$cmd) {
Exec $cmd -echo:$true
}
# Handy function for executing Invoke-Expression and reliably throwing an
# error if the expression, or the command it invoked, fails
#
# Original sample came from: http://jameskovacs.com/2010/02/25/the-exec-problem/
function Exec-Expression([string]$expr) {
Exec { Invoke-Expression $expr }
Exec { Invoke-Expression $expr } -echo:$true
}
# Ensure that NuGet is installed and return the path to the
......
......@@ -87,7 +87,7 @@ try {
Redirect-Temp
if ($testBuildCorrectness) {
Exec { & ".\build\scripts\test-build-correctness.ps1" $repoDir $configDir }
Exec-Echo { & ".\build\scripts\test-build-correctness.ps1" -config $buildConfiguration }
exit 0
}
......
......@@ -11,51 +11,47 @@
[CmdletBinding(PositionalBinding=$false)]
param(
[string]$sourcePath = $null,
[string]$binariesPath = $null
[string]$config = "",
[string]$msbuild = ""
)
Set-StrictMode -version 2.0
$ErrorActionPreference="Stop"
function Get-PackagesPath {
$packagesPath = $env:NUGET_PACKAGES
if ($packagesPath -eq $null) {
$packagesPath = Join-Path $env:UserProfile ".nuget\packages\"
}
return $packagesPath
}
Push-Location $sourcePath
try {
. (Join-Path $PSScriptRoot "build-utils.ps1")
Push-Location $repoDir
# Need to parse out the current NuGet package version of Structured Logger
[xml]$deps = Get-Content (Join-Path $sourcePath "build\Targets\Dependencies.props")
[xml]$deps = Get-Content (Join-Path $repoDir "build\Targets\Dependencies.props")
$structuredLoggerVersion = $deps.Project.PropertyGroup.MicrosoftBuildLoggingStructuredLoggerVersion
$packagesPath = Get-PackagesPath
$structuredLoggerPath = Join-Path $packagesPath "Microsoft.Build.Logging.StructuredLogger\$structuredLoggerVersion\lib\net46\StructuredLogger.dll"
$logPath = Join-Path $binariesPath "build.xml"
$structuredLoggerPath = Join-Path (Get-PackagesDir) "Microsoft.Build.Logging.StructuredLogger\$structuredLoggerVersion\lib\net46\StructuredLogger.dll"
$configDir = Join-Path $binariesDir $config
$logPath = Join-Path $configDir "build.xml"
if ($msbuild -eq "") {
$msbuild = Ensure-MSBuild
}
Write-Host "Building Roslyn.sln with logging support"
Exec { & msbuild /v:m /m /logger:StructuredLogger`,$structuredLoggerPath`;$logPath /nodeReuse:false /p:DeployExtension=false Roslyn.sln }
Exec-Echo { & $msbuild /v:m /m /logger:StructuredLogger`,$structuredLoggerPath`;$logPath /nodeReuse:false /p:DeployExtension=false Roslyn.sln }
Write-Host ""
# Verify the state of our various build artifacts
Write-Host "Running BuildBoss"
$buildBossPath = Join-Path $binariesPath "Exes\BuildBoss\BuildBoss.exe"
Exec { & $buildBossPath Roslyn.sln Compilers.sln src\Samples\Samples.sln CrossPlatform.sln "build\Targets" $logPath }
$buildBossPath = Join-Path $configDir "Exes\BuildBoss\BuildBoss.exe"
Exec-Echo { & $buildBossPath Roslyn.sln Compilers.sln src\Samples\Samples.sln CrossPlatform.sln "build\Targets" $logPath }
Write-Host ""
# Verify the state of our project.jsons
Write-Host "Running RepoUtil"
$repoUtilPath = Join-Path $binariesPath "Exes\RepoUtil\RepoUtil.exe"
Exec { & $repoUtilPath verify }
$repoUtilPath = Join-Path $configDir "Exes\RepoUtil\RepoUtil.exe"
Exec-Echo { & $repoUtilPath verify }
Write-Host ""
# Verify the state of our generated syntax files
Write-Host "Checking generated compiler files"
Exec { & (Join-Path $PSScriptRoot "generate-compiler-code.ps1") -test }
Exec-Echo { & (Join-Path $PSScriptRoot "generate-compiler-code.ps1") -test }
exit 0
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册