Skip to content

Commit 6889bc8

Browse files
authored
Miscellaneous improvements to build scripts (#1240)
* Refactor Build-SampleSet to remove warnings & support EWDK * Improved readability and logging on Build-Sample script
1 parent 57ecdd5 commit 6889bc8

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

Build-Sample.ps1

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,39 +147,42 @@ $myexit=0
147147
# If we fail at first, but succeed at either of next two attempts, then it is a sporadic failure.
148148
# If we even at third attempt fail, then it is a true failure.
149149
#
150-
for ($i=0; $i -le 2; $i++) {
150+
for ($i = 0; $i -lt 3; $i++)
151+
{
152+
$binLogFilePath = "$LogFilesDirectory\$SampleName.$Configuration.$Platform.$i.binlog"
151153
$errorLogFilePath = "$LogFilesDirectory\$SampleName.$Configuration.$Platform.$i.err"
152154
$warnLogFilePath = "$LogFilesDirectory\$SampleName.$Configuration.$Platform.$i.wrn"
153155
$OutLogFilePath = "$LogFilesDirectory\$SampleName.$Configuration.$Platform.$i.out"
154156

155-
msbuild $solutionFile -clp:Verbosity=m -t:rebuild -property:Configuration=$Configuration -property:Platform=$Platform -p:TargetVersion=Windows10 -p:InfVerif_AdditionalOptions="$InfVerif_AdditionalOptions" -warnaserror -flp1:errorsonly`;logfile=$errorLogFilePath -flp2:WarningsOnly`;logfile=$warnLogFilePath -noLogo > $OutLogFilePath
156-
if ($env:WDS_WipeOutputs -ne $null)
157+
msbuild $solutionFile -clp:Verbosity=m -t:rebuild -property:Configuration=$Configuration -property:Platform=$Platform -p:TargetVersion=Windows10 -p:InfVerif_AdditionalOptions="$InfVerif_AdditionalOptions" -warnaserror -binaryLogger:LogFile=$binLogFilePath`;ProjectImports=None -flp1:errorsonly`;logfile=$errorLogFilePath -flp2:WarningsOnly`;logfile=$warnLogFilePath -noLogo > $OutLogFilePath
158+
if ($null -ne $env:WDS_WipeOutputs)
157159
{
158-
Write-Verbose ("WipeOutputs: "+$Directory+" "+(((Get-Volume ($DriveLetter=(Get-Item ".").PSDrive.Name)).SizeRemaining/1GB)))
159-
Get-ChildItem -path $Directory -Recurse -Include x64|Remove-Item -Recurse
160-
Get-ChildItem -path $Directory -Recurse -Include arm64|Remove-Item -Recurse
160+
Write-Verbose ("WipeOutputs: " + $Directory + " " + (((Get-Volume (Get-Item ".").PSDrive.Name).SizeRemaining / 1GB)))
161+
Get-ChildItem -path $Directory -Recurse -Include x64 | Remove-Item -Recurse
162+
Get-ChildItem -path $Directory -Recurse -Include arm64 | Remove-Item -Recurse
161163
}
162164
if ($LASTEXITCODE -eq 0)
163165
{
164166
# We succeeded building.
165-
# If at first attempt, then $myexit=0
166-
# If at later attempt, then $myexit=2
167+
# If it was at a later attempt, let the caller know with a different exit code.
167168
if ($i -eq 0)
168169
{
169-
$myexit=0
170+
$myexit = 0
170171
}
171172
else
172173
{
173-
$myexit=2
174+
$myexit = 2
174175
}
175-
break;
176+
# Remove binlog on success to save space; keep otherwise to diagnose issues.
177+
Remove-Item $binLogFilePath
178+
break;
176179
}
177180
else
178181
{
179182
# We failed building.
180183
# Let us sleep for a bit.
181184
# Then let the while loop do its thing and re-run.
182-
sleep 1
185+
Start-Sleep 1
183186
if ($Verbose)
184187
{
185188
Write-Warning "`u{274C} Build failed. Retrying to see if sporadic..."

Build-SampleSet.ps1

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $root = Get-Location
1414
if (-not $env:VSCMD_VER) {
1515
Import-Module (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*\Common7\Tools\Microsoft.VisualStudio.DevShell.dll")
1616
Enter-VsDevShell -VsInstallPath (Resolve-Path "$env:ProgramFiles\Microsoft Visual Studio\2022\*")
17-
cd $root
17+
Set-Location $root
1818
}
1919

2020
$ThrottleFactor = 5
@@ -97,19 +97,25 @@ else {
9797

9898
# Dump all environment variables so as to help debug error:
9999
Write-Output "Environment variables {"
100-
gci env:* | sort-object name
100+
Get-ChildItem env:* | Sort-Object name
101101
Write-Output "Environment variables }"
102102

103103
Write-Error "Could not determine build environment."
104104
exit 1
105105
}
106106
#
107107
# Get the WDK extension version from installed packages
108-
$wdk_extension_ver = ls "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select -ExpandProperty Name
108+
$wdk_extension_ver = Get-ChildItem "${env:ProgramData}\Microsoft\VisualStudio\Packages\Microsoft.Windows.DriverKit,version=*" | Select-Object -ExpandProperty Name
109109
$wdk_extension_ver = ([regex]'(\d+\.)(\d+\.)(\d+\.)(\d+)').Matches($wdk_extension_ver).Value
110110
if (-not $wdk_extension_ver) {
111-
Write-Error "No version of the WDK Visual Studio Extension could be found. The WDK Extension is not installed."
112-
exit 1
111+
# Be lenient with EWDK builds that do not include the package information
112+
if ($build_environment -match '^EWDK') {
113+
$wdk_extension_ver = "(package not found)"
114+
}
115+
else {
116+
Write-Error "No version of the WDK Visual Studio Extension could be found. The WDK Extension is not installed."
117+
exit 1
118+
}
113119
}
114120
#
115121
#
@@ -348,7 +354,7 @@ $Results = $jresult.Results
348354
Write-Output "Built all combinations."
349355
Write-Output ""
350356
Write-Output "Elapsed time: $min minutes, $seconds seconds."
351-
Write-Output ("Disk Remaining (GB): " + (((Get-Volume ($DriveLetter = (Get-Item ".").PSDrive.Name)).SizeRemaining / 1GB)))
357+
Write-Output ("Disk Remaining (GB): " + (((Get-Volume (Get-Item ".").PSDrive.Name).SizeRemaining / 1GB)))
352358
Write-Output ("Samples: " + $sampleSet.Count)
353359
Write-Output ("Configurations: " + $Configurations.Count + " (" + $Configurations + ")")
354360
Write-Output ("Platforms: " + $Platforms.Count + " (" + $Platforms + ")")

0 commit comments

Comments
 (0)