Skip to content

Commit 34e683a

Browse files
committed
Handle specific MultiTargets and Components for solution and project reference generation
1 parent f3c24c1 commit 34e683a

6 files changed

+136
-60
lines changed

Build-Toolkit-Components.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@
5858
#>
5959
Param (
6060
[ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')]
61-
[string[]]$MultiTargets = @('all'),
61+
[Alias("mt")]
62+
[string[]]$MultiTargets = @('uwp', 'wasdk', 'wasm'), # default settings
6263

6364
[ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')]
64-
[string[]]$ExcludeMultiTargets = @('wpf', 'linuxgtk', 'macos', 'ios', 'android'),
65+
[string[]]$ExcludeMultiTargets = @() # default settings
6566

67+
[Alias("c")]
6668
[string[]]$Components = @("all"),
6769

6870
[string[]]$ExcludeComponents,
@@ -76,10 +78,13 @@ Param (
7678
[Alias("bl")]
7779
[switch]$EnableBinLogs,
7880

81+
[Alias("blo")]
7982
[string]$BinlogOutput,
80-
83+
84+
[Alias("p")]
8185
[hashtable]$AdditionalProperties,
8286

87+
[Alias("winui")]
8388
[int]$WinUIMajorVersion = 2,
8489

8590
[string]$ComponentDir = "src",

Build-Toolkit-Gallery.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747
#>
4848
Param (
4949
[ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')]
50-
[string[]]$MultiTargets = @('all'),
50+
[Alias("mt")]
51+
[string[]]$MultiTargets = @('uwp', 'wasdk', 'wasm'), # default settings
5152

5253
[ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')]
53-
[string[]]$ExcludeMultiTargets = @('wpf', 'linuxgtk', 'macos', 'ios', 'android'),
54+
[string[]]$ExcludeMultiTargets = @() # default settings
5455

5556
[ValidateSet('all', 'Uwp', 'Wasdk', 'Wasm', 'Tests.Uwp', 'Tests.Wasdk')]
5657
[string[]]$Heads = @('Uwp', 'Wasdk', 'Wasm'),
@@ -61,12 +62,16 @@ Param (
6162
[Alias("bl")]
6263
[switch]$EnableBinLogs,
6364

65+
[Alias("blo")]
6466
[string]$BinlogOutput,
6567

68+
[Alias("p")]
6669
[hashtable]$AdditionalProperties,
6770

71+
[Alias("winui")]
6872
[int]$WinUIMajorVersion = 2,
6973

74+
[Alias("c")]
7075
[string[]]$Components = @("all"),
7176

7277
[string[]]$ExcludeComponents,

GenerateAllSolution.ps1

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,71 @@
11
<#
22
.SYNOPSIS
33
Generates the solution file comprising of platform heads for samples, individual component projects, and tests.
4+
45
.DESCRIPTION
56
Used mostly for CI building of everything and testing end-to-end scenarios involving the full
67
sample app experience.
78
89
Otherwise it is recommended to focus on an individual component's solution instead.
9-
.PARAMETER IncludeHeads
10-
List of TFM based projects to include. This can be 'all', 'uwp', or 'wasdk'.
1110
12-
Defaults to 'all'.
11+
.PARAMETER MultiTargets
12+
Specifies the MultiTarget TFM(s) to include for building the components. The default value is 'all'.
13+
14+
.PARAMETER ExcludeMultiTargets
15+
Specifies the MultiTarget TFM(s) to exclude for building the components. The default value excludes targets that require additional tooling or workloads to build. Run uno-check to install the required workloads.
16+
17+
.PARAMETER Components
18+
The names of the components to generate project and solution references for. Defaults to all components.
19+
20+
.PARAMETER ExcludeComponents
21+
The names of the components to exclude when generating solution and project references. Defaults to none.
22+
1323
.PARAMETER UseDiagnostics
1424
Add extra diagnostic output to running slngen, such as a binlog, etc...
25+
1526
.EXAMPLE
16-
C:\PS> .\GenerateAllSolution -IncludeHeads wasdk
27+
C:\PS> .\GenerateAllSolution -MultiTargets wasdk
1728
Build a solution that doesn't contain UWP projects.
29+
1830
.NOTES
1931
Author: Windows Community Toolkit Labs Team
2032
Date: April 27, 2022
2133
#>
2234
Param (
23-
[Parameter(HelpMessage = "The heads to include for building the sample gallery and tests.", ParameterSetName = "IncludeHeads")]
35+
[Parameter(HelpMessage = "The heads to include for building the sample gallery and tests.", ParameterSetName = "MultiTargets")]
2436
[ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')]
25-
[string[]]$IncludeHeads = @('all'),
37+
[Alias("mt")]
38+
[string[]]$MultiTargets = @('all'),
39+
40+
[Parameter(HelpMessage = "The target frameworks to disable.")]
41+
[ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')]
42+
[string[]]$ExcludeMultiTargets = @() # default settings
43+
44+
[Parameter(HelpMessage = "The names of the components to generate project and solution references for. Defaults to all components.")]
45+
[Alias("c")]
46+
[string[]]$Components = @('all'),
47+
48+
[Parameter(HelpMessage = "The names of the components to exclude when generating solution and project references.")]
49+
[string[]]$ExcludeComponents,
2650

2751
[Parameter(HelpMessage = "Add extra diagnostic output to slngen generator.")]
2852
[switch]$UseDiagnostics = $false
2953
)
3054

31-
if ($IncludeHeads.Contains('all')) {
32-
$IncludeHeads = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')
55+
if ($MultiTargets.Contains('all')) {
56+
$MultiTargets = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')
57+
}
58+
59+
if ($null -eq $ExcludeMultiTargets)
60+
{
61+
$ExcludeMultiTargets = @()
3362
}
3463

64+
$MultiTargets = $MultiTargets | Where-Object { $_ -notin $ExcludeMultiTargets }
65+
3566
# Generate required props for "All" solution.
36-
& ./tooling/MultiTarget/GenerateAllProjectReferences.ps1
67+
& ./tooling/MultiTarget/GenerateAllProjectReferences.ps1 -MultiTargets $MultiTargets -Components $Components -ExcludeComponents $ExcludeComponents
68+
& ./tooling/MultiTarget/UseTargetFrameworks.ps1 -MultiTargets $MultiTargets
3769

3870
# Set up constant values
3971
$generatedSolutionFilePath = 'CommunityToolkit.AllComponents.sln'
@@ -59,9 +91,10 @@ $projects = [System.Collections.ArrayList]::new()
5991
# Common/Dependencies for shared infrastructure
6092
[void]$projects.Add(".\tooling\CommunityToolkit*\*.*proj")
6193

94+
# Deployable sample gallery heads
6295
# TODO: this handles separate project heads, but won't directly handle the unified Skia head from Uno.
6396
# Once we have that, just do a transform on the csproj filename inside this loop to decide the same csproj for those separate MultiTargets.
64-
foreach ($multitarget in $IncludeHeads) {
97+
foreach ($multitarget in $MultiTargets) {
6598
# capitalize first letter, avoid case sensitivity issues on linux
6699
$csprojFileNamePartForMultiTarget = $multitarget.substring(0,1).ToUpper() + $multitarget.Substring(1).ToLower()
67100

@@ -76,9 +109,31 @@ foreach ($multitarget in $IncludeHeads) {
76109
}
77110

78111
# Individual projects
79-
[void]$projects.Add(".\components\**\src\*.csproj")
80-
[void]$projects.Add(".\components\**\samples\*.Samples.csproj")
81-
[void]$projects.Add(".\components\**\tests\*.Tests\*.shproj")
112+
if ($Components -eq @('all')) {
113+
$Components = @('**')
114+
}
115+
116+
foreach ($componentName in $Components) {
117+
if ($ExcludeComponents -contains $componentName) {
118+
continue;
119+
}
120+
121+
foreach ($componentPath in Get-Item "$PSScriptRoot/../components/$componentName/") {
122+
$multiTargetPrefs = & $PSScriptRoot\MultiTarget\Get-MultiTargets.ps1 -component $($componentPath.BaseName)
123+
124+
$shouldReferenceInSolution = $multiTargetPrefs.Where({ $MultiTargets.Contains($_) }).Count -gt 0
125+
126+
if ($shouldReferenceInSolution) {
127+
Write-Output "Add component $componentPath to solution";
128+
129+
[void]$projects.Add(".\components\$($componentPath.BaseName)\src\*.csproj")
130+
[void]$projects.Add(".\components\$($componentPath.BaseName)\samples\*.Samples.csproj")
131+
[void]$projects.Add(".\components\$($componentPath.BaseName)\tests\*.Tests\*.shproj")
132+
} else {
133+
Write-Warning "Component $($componentPath.BaseName) doesn't MultiTarget any of $MultiTargets and won't be added to the solution.";
134+
}
135+
}
136+
}
82137

83138
if ($UseDiagnostics.IsPresent)
84139
{

MultiTarget/GenerateAllProjectReferences.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Param (
33
[string]$projectPropsOutputDir = "$PSScriptRoot/Generated",
44

55
[Parameter(HelpMessage = "Only projects that support these targets will have references generated for use by deployable heads.")]
6-
[string[]]$MultiTarget = @("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android", "netstandard"),
6+
[Alias("mt")]
7+
[ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')]
8+
[string[]]$MultiTargets = @("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android", "netstandard"),
79

810
[Parameter(HelpMessage = "The names of the components to generate references for. Defaults to all components.")]
911
[string[]]$Components = @("all"),
@@ -30,20 +32,18 @@ foreach ($componentName in $Components) {
3032

3133
# Find all components source csproj (when wildcard), or find specific component csproj by name.
3234
foreach ($componentPath in Get-Item "$PSScriptRoot/../../components/$componentName/") {
33-
Write-Output "Generating project references for component $componentName at $componentPath";
34-
3535
# Find source and sample csproj files
3636
$componentSourceCsproj = Get-ChildItem $componentPath/src/*.csproj -ErrorAction SilentlyContinue;
3737
$componentSampleCsproj = Get-ChildItem $componentPath/samples/*.csproj -ErrorAction SilentlyContinue;
3838

3939
# Generate <ProjectReference>s for sample project
4040
# Use source project MultiTarget as first fallback.
4141
if ($null -ne $componentSampleCsproj -and (Test-Path $componentSampleCsproj)) {
42-
& $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $componentSampleCsproj -outputPath "$projectPropsOutputDir/$($componentSampleCsproj.BaseName).props" -MultiTarget $MultiTarget
42+
& $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $componentSampleCsproj -outputPath "$projectPropsOutputDir/$($componentSampleCsproj.BaseName).props" -MultiTargets $MultiTargets
4343
}
4444

4545
# Generate <ProjectReference>s for src project
46-
& $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $componentSourceCsproj -outputPath "$projectPropsOutputDir/$($componentSourceCsproj.BaseName).props" -MultiTarget $MultiTarget
46+
& $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $componentSourceCsproj -outputPath "$projectPropsOutputDir/$($componentSourceCsproj.BaseName).props" -MultiTargets $MultiTargets
4747
}
4848
}
4949

MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Param (
1616

1717
[Parameter(HelpMessage = "Only projects that support these targets will have references generated for use by deployable heads.")]
1818
[ValidateSet("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android", "netstandard")]
19-
[string[]] $MultiTarget = @("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android", "netstandard")
19+
[Alias("mt")]
20+
[string[]] $MultiTargets = @("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android", "netstandard")
2021
)
2122

2223
$templateContents = Get-Content -Path $templatePath;
@@ -40,35 +41,44 @@ $templateContents = $templateContents -replace [regex]::escape($projectRootPlace
4041
$componentPath = Get-Item "$projectPath/../../"
4142

4243
# Load multitarget preferences for component
43-
$multiTargets = & $PSScriptRoot\Get-MultiTargets.ps1 -component $($componentPath.BaseName)
44+
$multiTargetPrefs = & $PSScriptRoot\Get-MultiTargets.ps1 -component $($componentPath.BaseName)
4445

45-
if ($null -eq $multiTargets) {
46+
if ($null -eq $multiTargetPrefs) {
4647
Write-Error "Couldn't get MultiTarget property for $componentPath";
4748
exit(-1);
4849
}
4950

50-
# Ensure multiTargets is not empty
51-
if ($multiTargets.Length -eq 0) {
51+
# Ensure multiTargetPrefs is not empty
52+
if ($multiTargetPrefs.Length -eq 0) {
5253
Write-Error "MultiTarget property is empty for $projectPath";
5354
exit(-1);
5455
}
5556

56-
$templateContents = $templateContents -replace [regex]::escape("[IntendedTargets]"), $multiTargets;
57+
$templateContents = $templateContents -replace [regex]::escape("[IntendedTargets]"), $multiTargetPrefs;
5758

5859
function ShouldMultiTarget([string] $target) {
59-
return ($multiTargets.Contains($target) -and $MultiTarget.Contains($target)).ToString().ToLower()
60+
return ($multiTargetPrefs.Contains($target) -and $MultiTargets.Contains($target))
6061
}
6162

62-
Write-Host "Generating project references for $([System.IO.Path]::GetFileNameWithoutExtension($csprojFileName)): $($multiTargets -Join ', ')"
63-
$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasm]"), "'$(ShouldMultiTarget "wasm")'";
64-
$templateContents = $templateContents -replace [regex]::escape("[CanTargetUwp]"), "'$(ShouldMultiTarget "uwp")'";
65-
$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasdk]"), "'$(ShouldMultiTarget "wasdk")'";
66-
$templateContents = $templateContents -replace [regex]::escape("[CanTargetWpf]"), "'$(ShouldMultiTarget "wpf")'";
67-
$templateContents = $templateContents -replace [regex]::escape("[CanTargetLinuxGtk]"), "'$(ShouldMultiTarget "linuxgtk")'";
68-
$templateContents = $templateContents -replace [regex]::escape("[CanTargetMacOS]"), "'$(ShouldMultiTarget "macos")'";
69-
$templateContents = $templateContents -replace [regex]::escape("[CanTargetiOS]"), "'$(ShouldMultiTarget "ios")'";
70-
$templateContents = $templateContents -replace [regex]::escape("[CanTargetDroid]"), "'$(ShouldMultiTarget "android")'";
71-
$templateContents = $templateContents -replace [regex]::escape("[CanTargetNetstandard]"), "'$(ShouldMultiTarget "netstandard")'";
63+
function ShouldMultiTargetMsBuildValue([string] $target) {
64+
return $(ShouldMultiTarget $target).ToString().ToLower()
65+
}
66+
67+
$targeted = @("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android", "netstandard").Where({ ShouldMultiTarget $_ })
68+
69+
if ($targeted.Count -gt 0) {
70+
Write-Host "Generating project references for $([System.IO.Path]::GetFileNameWithoutExtension($csprojFileName)): $($targeted -Join ', ')"
71+
}
72+
73+
$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasm]"), "'$(ShouldMultiTargetMsBuildValue "wasm")'";
74+
$templateContents = $templateContents -replace [regex]::escape("[CanTargetUwp]"), "'$(ShouldMultiTargetMsBuildValue "uwp")'";
75+
$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasdk]"), "'$(ShouldMultiTargetMsBuildValue "wasdk")'";
76+
$templateContents = $templateContents -replace [regex]::escape("[CanTargetWpf]"), "'$(ShouldMultiTargetMsBuildValue "wpf")'";
77+
$templateContents = $templateContents -replace [regex]::escape("[CanTargetLinuxGtk]"), "'$(ShouldMultiTargetMsBuildValue "linuxgtk")'";
78+
$templateContents = $templateContents -replace [regex]::escape("[CanTargetMacOS]"), "'$(ShouldMultiTargetMsBuildValue "macos")'";
79+
$templateContents = $templateContents -replace [regex]::escape("[CanTargetiOS]"), "'$(ShouldMultiTargetMsBuildValue "ios")'";
80+
$templateContents = $templateContents -replace [regex]::escape("[CanTargetDroid]"), "'$(ShouldMultiTargetMsBuildValue "android")'";
81+
$templateContents = $templateContents -replace [regex]::escape("[CanTargetNetstandard]"), "'$(ShouldMultiTargetMsBuildValue "netstandard")'";
7282

7383
# Save to disk
7484
Set-Content -Path $outputPath -Value $templateContents;

MultiTarget/UseTargetFrameworks.ps1

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
that works on all supported platforms.
88
99
Note: Projects which rely on target platforms that are excluded will be unable to build.
10-
.PARAMETER include
10+
.PARAMETER MultiTargets
1111
List of include to set as TFM platforms to build for. Possible values match those provided to the <MultiTarget> MSBuild property.
1212
By default, uwp, wasdk, and wasm will included.
13-
.PARAMETER exclude
13+
.PARAMETER ExcludeMultiTargets
1414
List to exclude from build. Possible values match those provided to the <MultiTarget> MSBuild property.
1515
By default, none will excluded.
1616
.EXAMPLE
@@ -23,12 +23,13 @@
2323
Param (
2424
[Parameter(HelpMessage = "The target frameworks to enable.")]
2525
[ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')]
26-
[string[]]$include = @('uwp', 'wasdk', 'wasm'), # default settings
26+
[Alias("mt")]
27+
[string[]]$MultiTargets = @('uwp', 'wasdk', 'wasm'), # default settings
2728

2829
[Parameter(HelpMessage = "The target frameworks to disable.")]
2930
[ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')]
30-
[string[]]$exclude = @() # default settings
31-
)3
31+
[string[]]$ExcludeMultiTargets = @() # default settings
32+
)
3233

3334
$UwpTfm = "UwpTargetFramework";
3435
$WinAppSdkTfm = "WinAppSdkTargetFramework";
@@ -42,53 +43,53 @@ $NetstandardTfm = "DotnetStandardCommonTargetFramework";
4243

4344
$fileContents = Get-Content -Path $PSScriptRoot/AvailableTargetFrameworks.props
4445

45-
# 'all' represents many '$include' values
46-
if ($include.Contains("all")) {
47-
$include = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')
46+
# 'all' represents many '$MultiTargets' values
47+
if ($MultiTargets.Contains("all")) {
48+
$MultiTargets = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')
4849
}
4950

5051
# Exclude as needed
51-
foreach ($excluded in $exclude) {
52-
$include = $include.Where({ $_ -ne $excluded });
52+
foreach ($excluded in $ExcludeMultiTargets) {
53+
$MultiTargets = $MultiTargets.Where({ $_ -ne $excluded });
5354
}
5455

55-
Write-Output "Setting enabled TargetFrameworks: $include"
56+
Write-Output "Setting enabled TargetFrameworks: $MultiTargets"
5657

5758
$desiredTfmValues = @();
5859

59-
if ($include.Contains("wasm")) {
60+
if ($MultiTargets.Contains("wasm")) {
6061
$desiredTfmValues += $WasmTfm;
6162
}
6263

63-
if ($include.Contains("uwp")) {
64+
if ($MultiTargets.Contains("uwp")) {
6465
$desiredTfmValues += $UwpTfm;
6566
}
6667

67-
if ($include.Contains("wasdk")) {
68+
if ($MultiTargets.Contains("wasdk")) {
6869
$desiredTfmValues += $WinAppSdkTfm;
6970
}
7071

71-
if ($include.Contains("wpf")) {
72+
if ($MultiTargets.Contains("wpf")) {
7273
$desiredTfmValues += $WpfTfm;
7374
}
7475

75-
if ($include.Contains("linuxgtk")) {
76+
if ($MultiTargets.Contains("linuxgtk")) {
7677
$desiredTfmValues += $GtkTfm;
7778
}
7879

79-
if ($include.Contains("macos")) {
80+
if ($MultiTargets.Contains("macos")) {
8081
$desiredTfmValues += $macOSTfm;
8182
}
8283

83-
if ($include.Contains("ios")) {
84+
if ($MultiTargets.Contains("ios")) {
8485
$desiredTfmValues += $iOSTfm;
8586
}
8687

87-
if ($include.Contains("android")) {
88+
if ($MultiTargets.Contains("android")) {
8889
$desiredTfmValues += $DroidTfm;
8990
}
9091

91-
if ($include.Contains("netstandard")) {
92+
if ($MultiTargets.Contains("netstandard")) {
9293
$desiredTfmValues += $NetstandardTfm;
9394
}
9495

0 commit comments

Comments
 (0)