Skip to content

Commit 0d0b212

Browse files
committed
Extracted MultiTarget/WinUI checks into dedicated Test-Component-Support.ps1 script
1 parent 26b8832 commit 0d0b212

3 files changed

Lines changed: 144 additions & 59 deletions

File tree

Build-Toolkit-Components.ps1

Lines changed: 12 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,6 @@ $MultiTargets = $MultiTargets | Where-Object { $_ -notin $ExcludeMultiTargets }
121121

122122
Write-Output "Building components '$Components' for MultiTargets: $MultiTargets"
123123

124-
if ($Components -eq @('all')) {
125-
$Components = @('**')
126-
}
127-
128124
if ($ExcludeComponents) {
129125
$Components = $Components | Where-Object { $_ -notin $ExcludeComponents }
130126
}
@@ -212,14 +208,9 @@ function Invoke-MSBuildWithBinlog {
212208
}
213209
}
214210

215-
# List of WinUI-0 (non-WinUI) compatible multitargets
216-
$WinUI0MultiTargets = @('netstandard')
217-
218-
# List of WinUI-2 compatible multitargets
219-
$WinUI2MultiTargets = @('uwp', 'wasm', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')
220-
221-
# List of WinUI-3 compatible multitargets
222-
$WinUI3MultiTargets = @('wasdk', 'wasm', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')
211+
if ($Components -eq @('all')) {
212+
$Components = @('**')
213+
}
223214

224215
# Components are built individually
225216
foreach ($ComponentName in $Components) {
@@ -236,59 +227,22 @@ foreach ($ComponentName in $Components) {
236227
# Get supported MultiTarget for this component
237228
$supportedMultiTargets = & $PSScriptRoot\MultiTarget\Get-MultiTargets.ps1 -component $componentName
238229

239-
# If WinUI 0 is requested, the component must not support WinUI 2 or WinUI 3 to be built.
240-
# If WinUI 2 or 3 is requested, the component have a target that supports WinUI 2 or 3 to be built.
241-
$isWinUI0Supported = $false
242-
$isWinUI2Supported = $false
243-
$isWinUI3Supported = $false
244-
245-
# Flag to check if any of the requested targets are supported by the component
246-
$isRequestedTargetSupported = $false
247-
248-
foreach ($requestedTarget in $MultiTargets) {
249-
if ($false -eq $isRequestedTargetSupported) {
250-
$isRequestedTargetSupported = $requestedTarget -in $supportedMultiTargets
251-
}
252-
}
253-
254-
foreach ($supportedMultiTarget in $supportedMultiTargets) {
255-
# Only build components that support WinUI 2
256-
if ($false -eq $isWinUI2Supported) {
257-
$isWinUI2Supported = $supportedMultiTarget -in $WinUI2MultiTargets;
258-
}
259-
260-
# Only build components that support WinUI 3
261-
if ($false -eq $isWinUI3Supported) {
262-
$isWinUI3Supported = $supportedMultiTarget -in $WinUI3MultiTargets;
263-
}
264-
265-
# Build components that support neither WinUI 2 nor WinUI 3 (e.g. netstandard only)
266-
if ($false -eq $isWinUI0Supported) {
267-
$isWinUI0Supported = $supportedMultiTarget -in $WinUI0MultiTargets -and -not ($isWinUI2Supported -or $isWinUI3Supported);
268-
}
269-
}
270-
271-
# If none of the requested targets are supported by the component, we can skip build to save time and avoid errors.
272-
if (-not $isRequestedTargetSupported) {
273-
Write-Warning "Skipping $componentName, none of the requested MultiTargets '$MultiTargets' are enabled for this component."
274-
continue
275-
}
276-
277-
if (-not $isWinUI0Supported -and $WinUIMajorVersion -eq 0) {
278-
Write-Warning "Skipping $componentName. WinUI is disabled and one of the supported MultiTargets '$supportedMultiTargets' supports WinUI."
279-
continue;
280-
}
281-
282-
if ((-not $isWinUI2Supported -and $WinUIMajorVersion -eq 2) -or (-not $isWinUI3Supported -and $WinUIMajorVersion -eq 3)) {
283-
Write-Warning "Skipping $componentName. WinUI $WinUIMajorVersion is enabled and not supported by any of the MultiTargets '$supportedMultiTargets'"
230+
$shouldBuild = & $PSScriptRoot\MultiTarget\Test-Component-Support.ps1 `
231+
-RequestedMultiTargets $MultiTargets `
232+
-SupportedMultiTargets $supportedMultiTargets `
233+
-Component $componentName `
234+
-WinUIMajorVersion $WinUIMajorVersion
235+
236+
if (-not $shouldBuild.IsSupported) {
237+
Write-Warning "Skipping $componentName. $($shouldBuild.Reason)"
284238
continue
285239
}
286240

287241
# Filter ExcludeMultiTargets out of supportedMultiTargets
288242
# For display purposes only. The actual build uses the EnabledMultiTargets.props + EnabledTargetFrameworks.props to calculate supported targets at build time.
289243
$supportedMultiTargets = $supportedMultiTargets | Where-Object { $_ -notin $ExcludeMultiTargets }
290-
291244
Write-Output "Building $componentName for MultiTargets '$supportedMultiTargets'"
245+
292246
Invoke-MSBuildWithBinlog $componentCsproj.FullName $EnableBinLogs $BinlogOutput
293247
}
294248
}

MultiTarget/Get-MultiTargets.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ if ($null -eq $regex -or $null -eq $regex.Matches -or $null -eq $regex.Matches.G
5050
}
5151

5252
$multiTargets = $regex.Matches.Groups[1].Value;
53-
return $multiTargets.Split(';');
53+
return $multiTargets.Split(';') | Where-Object { $_ -ne '' };
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<#
2+
.SYNOPSIS
3+
Tests WinUI support for a specific component and its requested MultiTargets.
4+
5+
.DESCRIPTION
6+
This script tests WinUI support for a specific component and its requested MultiTargets. It checks if the requested MultiTargets are supported by the component and if the WinUI version is compatible.
7+
8+
.PARAMETER SupportedMultiTargets
9+
Specifies known supported MultiTargets for the given component. Is retrieved if not specified.
10+
11+
.PARAMETER RequestedMultiTargets
12+
Specifies the MultiTarget TFM(s) to include for building the components. The default value is 'all'. If not specified, it will use the supported MultiTargets.
13+
14+
.PARAMETER Component
15+
Specifies the names of the components to build. Defaults to all components.
16+
17+
.PARAMETER WinUIMajorVersion
18+
Specifies the WinUI major version to use when building for Uno. Also decides the package id and dependency variant.
19+
20+
.EXAMPLE
21+
Build-Toolkit-Components -MultiTargets 'uwp', 'wasm' -DateForVersion '220101' -PreviewVersion 'local' -NupkgOutput 'C:\Output' -BinlogOutput 'C:\Logs' -EnableBinLogs -Components 'MyComponent1', 'MyComponent2' -ExcludeComponents 'MyComponent3' -Release -Verbose
22+
23+
Builds the 'MyComponent1' and 'MyComponent2' components for the 'uwp' and 'wasm' target frameworks with version '220101' and preview version 'local'. The 'MyComponent3' component will be excluded from building. The .nupkg files will be copied to 'C:\Output' and binlogs will be generated in 'C:\Logs'. The components will be built in Release configuration with detailed msbuild verbosity.
24+
25+
.NOTES
26+
Author: Arlo Godfrey
27+
Date: 6/6/2025
28+
#>
29+
Param (
30+
[ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')]
31+
[Alias("smt")]
32+
[string[]]$SupportedMultiTargets,
33+
34+
[ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')]
35+
[Alias("rmt")]
36+
[Parameter(Mandatory=$true)]
37+
[string[]]$RequestedMultiTargets,
38+
39+
[Alias("c")]
40+
[Parameter(Mandatory=$true)]
41+
[string]$Component,
42+
43+
[Alias("winui")]
44+
[Parameter(Mandatory=$true)]
45+
[int]$WinUIMajorVersion
46+
)
47+
48+
if ($RequestedMultiTargets -eq 'all') {
49+
$RequestedMultiTargets = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')
50+
}
51+
52+
# List of WinUI-0 (non-WinUI) compatible multitargets
53+
$WinUI0MultiTargets = @('netstandard')
54+
55+
# List of WinUI-2 compatible multitargets
56+
$WinUI2MultiTargets = @('uwp', 'wasm', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')
57+
58+
# List of WinUI-3 compatible multitargets
59+
$WinUI3MultiTargets = @('wasdk', 'wasm', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')
60+
61+
# If WinUI 0 is requested, the component must not support WinUI 2 or WinUI 3 to be built.
62+
# If WinUI 2 or 3 is requested, the component must have a target that supports WinUI 2 or 3 to be built.
63+
$isWinUI0Supported = $false
64+
$isWinUI2Supported = $false
65+
$isWinUI3Supported = $false
66+
67+
if ($null -ne $SupportedMultiTargets -and $SupportedMultiTargets.Count -gt 0) {
68+
# If supported MultiTargets are provided, use them directly
69+
$supportedMultiTargets = $SupportedMultiTargets
70+
} else {
71+
# If not provided, retrieve the supported MultiTargets for the component
72+
if ($null -eq $Component) {
73+
Write-Error "Component name must be specified to retrieve supported MultiTargets."
74+
exit 1
75+
}
76+
$supportedMultiTargets = & $PSScriptRoot\MultiTarget\Get-MultiTargets.ps1 -component $Component
77+
}
78+
79+
80+
# Flag to check if any of the requested targets are supported by the component
81+
$isRequestedTargetSupported = $false
82+
83+
foreach ($requestedTarget in $RequestedMultiTargets) {
84+
if ($false -eq $isRequestedTargetSupported) {
85+
$isRequestedTargetSupported = $requestedTarget -in $supportedMultiTargets
86+
}
87+
}
88+
89+
foreach ($supportedMultiTarget in $supportedMultiTargets) {
90+
# Only build components that support WinUI 2
91+
if ($false -eq $isWinUI2Supported) {
92+
$isWinUI2Supported = $supportedMultiTarget -in $WinUI2MultiTargets;
93+
}
94+
95+
# Only build components that support WinUI 3
96+
if ($false -eq $isWinUI3Supported) {
97+
$isWinUI3Supported = $supportedMultiTarget -in $WinUI3MultiTargets;
98+
}
99+
100+
# Build components that support neither WinUI 2 nor WinUI 3 (e.g. netstandard only)
101+
if ($false -eq $isWinUI0Supported) {
102+
$isWinUI0Supported = $supportedMultiTarget -in $WinUI0MultiTargets -and -not ($isWinUI2Supported -or $isWinUI3Supported);
103+
}
104+
}
105+
106+
# If none of the requested targets are supported by the component, we can skip build to save time and avoid errors.
107+
if (-not $isRequestedTargetSupported) {
108+
$IsSupported = $false
109+
$Reason = "None of the requested MultiTargets '$MultiTargets' are enabled for this component."
110+
}
111+
112+
if (-not $isWinUI0Supported -and $WinUIMajorVersion -eq 0) {
113+
$IsSupported = $false
114+
$Reason = "WinUI is disabled and one of the supported MultiTargets '$supportedMultiTargets' supports WinUI."
115+
}
116+
117+
if ((-not $isWinUI2Supported -and $WinUIMajorVersion -eq 2) -or (-not $isWinUI3Supported -and $WinUIMajorVersion -eq 3)) {
118+
$IsSupported = $false
119+
$Reason = "WinUI $WinUIMajorVersion is enabled and not supported by any of the MultiTargets '$supportedMultiTargets'"
120+
}
121+
122+
if ($null -eq $IsSupported) {
123+
# Default to true if no conditions were met
124+
$IsSupported = $true
125+
$Reason = $null
126+
}
127+
128+
return [PSCustomObject]@{
129+
IsSupported = $IsSupported
130+
Reason = $Reason
131+
}

0 commit comments

Comments
 (0)