Skip to content

Commit 98915ea

Browse files
committed
Fix toolchain version sorting and docs
1 parent c1d8e09 commit 98915ea

3 files changed

Lines changed: 53 additions & 5 deletions

File tree

Build/Agent/FwBuildEnvironment.psm1

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,27 @@ function Get-PreferredVcToolBinPath {
2828
return $null
2929
}
3030

31+
$versionSort = {
32+
$parsedVersion = [version]'0.0'
33+
$isVersion = [version]::TryParse($_.Name, [ref]$parsedVersion)
34+
if ($isVersion) {
35+
return $parsedVersion
36+
}
37+
38+
return [version]'0.0'
39+
}
40+
41+
$sortProperties = @(
42+
@{ Expression = {
43+
$parsedVersion = [version]'0.0'
44+
[version]::TryParse($_.Name, [ref]$parsedVersion)
45+
}; Descending = $true }
46+
@{ Expression = $versionSort; Descending = $true }
47+
@{ Expression = { $_.Name }; Descending = $true }
48+
)
49+
3150
$preferred = Get-ChildItem -Path $toolsRoot -Directory -ErrorAction SilentlyContinue |
32-
Sort-Object Name -Descending |
51+
Sort-Object -Property $sortProperties |
3352
ForEach-Object { Join-Path $_.FullName 'bin\HostX64\x64' } |
3453
Where-Object { Test-Path $_ } |
3554
Select-Object -First 1

Build/Agent/Verify-FwDependencies.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
.DESCRIPTION
66
Checks for required tools and SDKs needed to build FieldWorks.
77
Can be run locally for testing or called from GitHub Actions workflows.
8+
By default, the script writes host output only and does not emit result objects.
9+
Use -PassThru when a caller needs structured results returned on the pipeline.
810
911
Expected dependencies (typically pre-installed on windows-latest):
1012
- Visual Studio 2022 with Desktop & C++ workloads
@@ -24,7 +26,8 @@
2426
If specified, prints the full per-dependency section headers and success details instead of the compact summary-only output.
2527
2628
.PARAMETER PassThru
27-
If specified, returns the dependency result objects for scripting callers instead of writing them implicitly.
29+
If specified, returns the dependency result objects for scripting callers.
30+
Without -PassThru, the script is quiet-by-default and writes host output only.
2831
2932
.EXAMPLE
3033
# Quick check
@@ -45,6 +48,9 @@
4548
.EXAMPLE
4649
# Capture structured results for automation
4750
$results = .\Build\Agent\Verify-FwDependencies.ps1 -IncludeOptional -PassThru
51+
52+
.NOTES
53+
Behavioral change: this script no longer emits dependency result objects unless -PassThru is specified.
4854
#>
4955

5056
[CmdletBinding()]
@@ -217,7 +223,7 @@ $results += Test-Dependency -Name "WiX Toolset (v6 via NuGet)" -Required "Option
217223
throw "Installer project not found: $wixProj"
218224
}
219225

220-
[xml]$wixProjXml = Get-Content -LiteralPath $wixProj
226+
[xml]$wixProjXml = Get-Content -LiteralPath $wixProj -Raw
221227
$projectNode = $wixProjXml.Project
222228
$hasWixSdk = $false
223229

Build/Src/FwBuildTasks/Make.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ private static string FindVisualStudioToolPath(string vcInstallDir, string toolN
121121
return null;
122122

123123
string[] versionDirs = Directory.GetDirectories(toolsRoot);
124-
Array.Sort(versionDirs, StringComparer.OrdinalIgnoreCase);
125-
Array.Reverse(versionDirs);
124+
Array.Sort(versionDirs, CompareVersionDirectories);
126125

127126
foreach (string versionDir in versionDirs)
128127
{
@@ -144,6 +143,30 @@ private static string FindVisualStudioToolPath(string vcInstallDir, string toolN
144143
return null;
145144
}
146145

146+
private static int CompareVersionDirectories(string left, string right)
147+
{
148+
string leftName = Path.GetFileName(left);
149+
string rightName = Path.GetFileName(right);
150+
151+
Version leftVersion;
152+
Version rightVersion;
153+
bool leftIsVersion = Version.TryParse(leftName, out leftVersion);
154+
bool rightIsVersion = Version.TryParse(rightName, out rightVersion);
155+
156+
if (leftIsVersion && rightIsVersion)
157+
{
158+
int versionComparison = rightVersion.CompareTo(leftVersion);
159+
if (versionComparison != 0)
160+
return versionComparison;
161+
}
162+
else if (leftIsVersion != rightIsVersion)
163+
{
164+
return rightIsVersion.CompareTo(leftIsVersion);
165+
}
166+
167+
return StringComparer.OrdinalIgnoreCase.Compare(rightName, leftName);
168+
}
169+
147170
private void CheckToolPath()
148171
{
149172
string path = Environment.GetEnvironmentVariable("PATH");

0 commit comments

Comments
 (0)