Skip to content

Commit bbdccb4

Browse files
committed
better code to handle verbose
1 parent 3cf9988 commit bbdccb4

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

build.ps1

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,22 @@ param(
3737
[switch] $Bootstrap,
3838

3939
[Parameter(ParameterSetName='BuildAll')]
40-
[Parameter(ParameterSetName='BuildOne')]
4140
[switch] $Catalog
4241

4342

4443
)
4544

45+
BEGIN {
46+
$verboseWanted = $false
47+
if ( $PSBoundParameters['Verbose'] ) {
48+
$verboseWanted = $PSBoundParameters['Verbose'].ToBool()
49+
}
50+
}
51+
4652
END {
47-
Import-Module -Force (Join-Path $PSScriptRoot build.psm1)
53+
Import-Module -Force (Join-Path $PSScriptRoot build.psm1) -verbose:$false
4854
if ( $Clean -or $Clobber ) {
49-
Remove-Build
55+
Remove-Build -verbose:$false
5056
if ( $PSCmdlet.ParameterSetName -eq "Clean" ) {
5157
return
5258
}
@@ -55,16 +61,18 @@ END {
5561
$setName = $PSCmdlet.ParameterSetName
5662
switch ( $setName ) {
5763
"BuildAll" {
58-
Start-ScriptAnalyzerBuild -All -Configuration $Configuration -Verbose:$Verbose -Catalog:$Catalog
64+
Start-ScriptAnalyzerBuild -All -Configuration $Configuration -Verbose:$verboseWanted
65+
if ( $Catalog ) {
66+
$catalogFile = New-Catalog
67+
}
5968
}
6069
"BuildDocumentation" {
61-
Start-ScriptAnalyzerBuild -Documentation -Verbose:$Verbose -Catalog:$Catalog
70+
Start-ScriptAnalyzerBuild -Documentation -Verbose:$Verbose
6271
}
6372
"BuildOne" {
6473
$buildArgs = @{
6574
PSVersion = $PSVersion
6675
Configuration = $Configuration
67-
Verbose = $Verbose
6876
}
6977
Start-ScriptAnalyzerBuild @buildArgs
7078
}

build.psm1

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,29 +165,33 @@ function Start-ScriptAnalyzerBuild
165165
$foundVersion = Get-InstalledCLIVersion
166166
Write-Warning "No suitable dotnet CLI found, requires version '$requiredVersion' found only '$foundVersion'"
167167
}
168+
$verboseWanted = $false
169+
if ( $PSBoundParameters['Verbose'] ) {
170+
$verboseWanted = $PSBoundParameters['Verbose'].ToBool()
171+
}
168172
}
169173
END {
170174

171175
# Build docs either when -Documentation switch is being specified or the first time in a clean repo
172176
$documentationFileExists = Test-Path (Join-Path $PSScriptRoot 'out\PSScriptAnalyzer\en-us\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll-Help.xml')
173177
if ( $Documentation -or -not $documentationFileExists )
174178
{
175-
Write-Verbose -Verbose:$Verbose -Message "Start-DocumentationBuild"
176-
Start-DocumentationBuild
179+
Write-Verbose -Verbose:$verboseWanted -Message "Start-DocumentationBuild"
180+
Start-DocumentationBuild -Verbose:$verboseWanted
177181
}
178182

179183
if ( $All )
180184
{
181185
# Build all the versions of the analyzer
182186
foreach($psVersion in 3..7) {
183-
Start-ScriptAnalyzerBuild -Configuration $Configuration -PSVersion $psVersion -Verbose:$Verbose
187+
Start-ScriptAnalyzerBuild -Configuration $Configuration -PSVersion $psVersion -Verbose:$verboseWanted
184188
}
185189
return
186190
}
187191

188192
if (-not $profilesCopied)
189193
{
190-
Write-Verbose -Verbose:$Verbose -Message "Copy-CompatibilityProfiles"
194+
Write-Verbose -Verbose:$verboseWanted -Message "Copy-CompatibilityProfiles"
191195
Copy-CompatibilityProfiles
192196
# Set the variable in the caller's scope, so this will only happen once
193197
Set-Variable -Name profilesCopied -Value $true -Scope 1
@@ -258,7 +262,7 @@ function Start-ScriptAnalyzerBuild
258262
try {
259263
Push-Location $projectRoot/Rules
260264
$message = "Building ScriptAnalyzer for PSVersion '$PSVersion' using framework '$framework' and configuration '$Configuration'"
261-
Write-Verbose -Verbose:$Verbose -Message "$message"
265+
Write-Verbose -Verbose:$verboseWanted -Message "$message"
262266
Write-Progress "$message"
263267
if ( -not $script:DotnetExe ) {
264268
$script:DotnetExe = Get-DotnetExe
@@ -275,7 +279,7 @@ function Start-ScriptAnalyzerBuild
275279
# $buildOutput = & $script:DotnetExe build --framework $framework --configuration "$buildConfiguration" 2>&1
276280
$buildOutput = & $script:DotnetExe $dotnetArgs 2>&1
277281
if ( $LASTEXITCODE -ne 0 ) { throw "$buildOutput" }
278-
Write-Verbose -Verbose:$Verbose -message "$buildOutput"
282+
Write-Verbose -Verbose:$verboseWanted -message "$buildOutput"
279283
}
280284
catch {
281285
Write-Warning $_

0 commit comments

Comments
 (0)