提交 85441c39 编写于 作者: J Jared Parsons

Add Exec-Console function

The Exec-Console function is just like Exec-Command except that it re-uses the
current console. This allows for items like colored text to come through to the
console.
上级 59a1499a
...@@ -27,41 +27,36 @@ function Exec-Block([scriptblock]$cmd) { ...@@ -27,41 +27,36 @@ function Exec-Block([scriptblock]$cmd) {
} }
} }
# Handy function for executing a windows command which needs to go through function Exec-CommandCore([string]$command, [string]$commandArgs, [switch]$useConsole = $true) {
# windows command line parsing.
#
# Use this when the command arguments are stored in a variable. Particularly
# when the variable needs reparsing by the windows command line. Example:
#
# $args = "/p:ManualBuild=true Test.proj"
# Exec-Command $msbuild $args
#
function Exec-Command([string]$command, [string]$commandArgs) {
$startInfo = New-Object System.Diagnostics.ProcessStartInfo $startInfo = New-Object System.Diagnostics.ProcessStartInfo
$startInfo.FileName = $command $startInfo.FileName = $command
$startInfo.Arguments = $commandArgs $startInfo.Arguments = $commandArgs
$startInfo.RedirectStandardOutput = $true
$startInfo.UseShellExecute = $false $startInfo.UseShellExecute = $false
$startInfo.CreateNoWindow = $true
$startInfo.WorkingDirectory = Get-Location $startInfo.WorkingDirectory = Get-Location
if (-not $useConsole) {
$startInfo.RedirectStandardOutput = $true
$startInfo.CreateNoWindow = $true
}
$process = New-Object System.Diagnostics.Process $process = New-Object System.Diagnostics.Process
$process.StartInfo = $startInfo $process.StartInfo = $startInfo
$process.StartInfo.RedirectStandardOutput = $true;
$process.Start() | Out-Null $process.Start() | Out-Null
$finished = $false $finished = $false
try { try {
# The OutputDataReceived event doesn't fire as events are sent by the if (-not $useConsole) {
# process in powershell. Possibly due to subtlties of how Powershell # The OutputDataReceived event doesn't fire as events are sent by the
# manages the thread pool that I'm not aware of. Using blocking # process in powershell. Possibly due to subtlties of how Powershell
# reading here as an alternative which is fine since this blocks # manages the thread pool that I'm not aware of. Using blocking
# on completion already. # reading here as an alternative which is fine since this blocks
$out = $process.StandardOutput # on completion already.
while (-not $out.EndOfStream) { $out = $process.StandardOutput
$line = $out.ReadLine() while (-not $out.EndOfStream) {
Write-Output $line $line = $out.ReadLine()
Write-Output $line
}
} }
while (-not $process.WaitForExit(100)) { while (-not $process.WaitForExit(100)) {
...@@ -82,6 +77,29 @@ function Exec-Command([string]$command, [string]$commandArgs) { ...@@ -82,6 +77,29 @@ function Exec-Command([string]$command, [string]$commandArgs) {
} }
} }
# Handy function for executing a windows command which needs to go through
# windows command line parsing.
#
# Use this when the command arguments are stored in a variable. Particularly
# when the variable needs reparsing by the windows command line. Example:
#
# $args = "/p:ManualBuild=true Test.proj"
# Exec-Command $msbuild $args
#
function Exec-Command([string]$command, [string]$commandArgs) {
Exec-CommandCore -command $command -commandArgs $commandargs -useConsole:$false
}
# Functions exactly like Exec-Command but lets the process re-use the current
# console. This means items like colored output will function correctly.
#
# In general this command should be used in place of
# Exec-Command $msbuild $args | Out-Host
#
function Exec-Console([string]$command, [string]$commandArgs) {
Exec-CommandCore -command $command -commandArgs $commandargs -useConsole:$true
}
# Handy function for executing a powershell script in a clean environment with # Handy function for executing a powershell script in a clean environment with
# arguments. Prefer this over & sourcing a script as it will both use a clean # arguments. Prefer this over & sourcing a script as it will both use a clean
# environment and do proper error checking # environment and do proper error checking
......
...@@ -94,7 +94,7 @@ function Run-MSBuild([string]$buildArgs = "", [string]$logFile = "") { ...@@ -94,7 +94,7 @@ function Run-MSBuild([string]$buildArgs = "", [string]$logFile = "") {
} }
$args += " $buildArgs" $args += " $buildArgs"
Exec-Command $msbuild $args Exec-Console $msbuild $args
} }
# Create a bootstrap build of the compiler. Returns the directory where the bootstrap buil # Create a bootstrap build of the compiler. Returns the directory where the bootstrap buil
...@@ -174,7 +174,7 @@ function Test-XUnitCoreClr() { ...@@ -174,7 +174,7 @@ function Test-XUnitCoreClr() {
$args += " -xml $logFile" $args += " -xml $logFile"
Write-Host "Running CoreClr tests" Write-Host "Running CoreClr tests"
Exec-Command $corerun $args | Out-Host Exec-Console $corerun $args
} }
# Core function for running our unit / integration tests tests # Core function for running our unit / integration tests tests
...@@ -247,7 +247,7 @@ function Test-XUnit() { ...@@ -247,7 +247,7 @@ function Test-XUnit() {
} }
try { try {
Exec-Command $runTests $args | Out-Host Exec-Console $runTests $args
} }
finally { finally {
Get-Process "xunit*" -ErrorAction SilentlyContinue | Stop-Process Get-Process "xunit*" -ErrorAction SilentlyContinue | Stop-Process
...@@ -293,7 +293,7 @@ function Deploy-VsixViaTool() { ...@@ -293,7 +293,7 @@ function Deploy-VsixViaTool() {
$filePath = Join-Path $configDir $e $filePath = Join-Path $configDir $e
$fullArg = "$baseArgs $filePath" $fullArg = "$baseArgs $filePath"
Write-Host "`tInstalling $name" Write-Host "`tInstalling $name"
Exec-Command $vsixExe $fullArg | Out-Host Exec-Console $vsixExe $fullArg
} }
} }
......
...@@ -10,7 +10,7 @@ $ErrorActionPreference="Stop" ...@@ -10,7 +10,7 @@ $ErrorActionPreference="Stop"
function Run-Tool($tool, $toolArgs) { function Run-Tool($tool, $toolArgs) {
$toolName = Split-Path -leaf $tool $toolName = Split-Path -leaf $tool
Write-Host "Running $toolName" Write-Host "Running $toolName"
Exec-Command $tool $toolArgs | Out-Host Exec-Console $tool $toolArgs
} }
function Run-LanguageCore($language, $languageSuffix, $languageDir, $syntaxTool, $errorFactsTool, $generatedDir, $generatedTestDir) { function Run-LanguageCore($language, $languageSuffix, $languageDir, $syntaxTool, $errorFactsTool, $generatedDir, $generatedTestDir) {
......
...@@ -33,13 +33,13 @@ try { ...@@ -33,13 +33,13 @@ try {
} }
Write-Host "Building Roslyn.sln with logging support" Write-Host "Building Roslyn.sln with logging support"
Exec-Command $msbuild "/noconlog /v:m /m /p:Configuration=$config /logger:StructuredLogger,$structuredLoggerPath;$logPath /nodeReuse:false /p:DeployExtension=false $solution" Exec-Console $msbuild "/noconlog /v:m /m /p:Configuration=$config /logger:StructuredLogger,$structuredLoggerPath;$logPath /nodeReuse:false /p:DeployExtension=false $solution"
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 $configDir "Exes\BuildBoss\BuildBoss.exe" $buildBossPath = Join-Path $configDir "Exes\BuildBoss\BuildBoss.exe"
Exec-Command $buildBossPath "Roslyn.sln Compilers.sln src\Samples\Samples.sln CrossPlatform.sln build\Targets $logPath" Exec-Console $buildBossPath "Roslyn.sln Compilers.sln src\Samples\Samples.sln CrossPlatform.sln build\Targets $logPath"
Write-Host "" Write-Host ""
# Verify the state of our generated syntax files # Verify the state of our generated syntax files
......
...@@ -22,7 +22,7 @@ function Run-Build([string]$rootDir, [string]$pathMapBuildOption, [switch]$resto ...@@ -22,7 +22,7 @@ function Run-Build([string]$rootDir, [string]$pathMapBuildOption, [switch]$resto
# Clean out the previous run # Clean out the previous run
Write-Host "Cleaning the Binaries" Write-Host "Cleaning the Binaries"
Exec-Command $msbuild "/nologo /v:m /nodeReuse:false /t:clean Roslyn.sln" Exec-Console $msbuild "/nologo /v:m /nodeReuse:false /t:clean Roslyn.sln"
if ($restore) { if ($restore) {
Write-Host "Restoring the packages" Write-Host "Restoring the packages"
...@@ -30,7 +30,7 @@ function Run-Build([string]$rootDir, [string]$pathMapBuildOption, [switch]$resto ...@@ -30,7 +30,7 @@ function Run-Build([string]$rootDir, [string]$pathMapBuildOption, [switch]$resto
} }
Write-Host "Building the Solution" Write-Host "Building the Solution"
Exec-Command $msbuild "/nologo /v:m /nodeReuse:false /m /p:DebugDeterminism=true /p:BootstrapBuildPath=$script:bootstrapDir /p:Features=`"debug-determinism`" /p:UseRoslynAnalyzers=false $pathMapBuildOption Roslyn.sln" Exec-Console $msbuild "/nologo /v:m /nodeReuse:false /m /p:DebugDeterminism=true /p:BootstrapBuildPath=$script:bootstrapDir /p:Features=`"debug-determinism`" /p:UseRoslynAnalyzers=false $pathMapBuildOption Roslyn.sln"
} }
finally { finally {
Pop-Location Pop-Location
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册