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