From a5b2f7aaadeeb99099530af082d4f437a2f24735 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 26 Jul 2024 12:54:15 -0500 Subject: [PATCH 1/8] Aligned head and MultiTarget generation --- GenerateAllSolution.ps1 | 39 ++++---- MultiTarget/UseTargetFrameworks.ps1 | 91 +++++++++---------- .../CommunityToolkit.Tests.Wasdk.csproj} | 0 .../Package.appxmanifest | 0 .../Properties/launchSettings.json | 0 .../app.manifest | 0 .../CommunityToolkit.App.Wasdk.csproj} | 0 .../{WinAppSdk => Wasdk}/Package.appxmanifest | 0 .../Properties/launchSettings.json | 0 .../{WinAppSdk => Wasdk}/app.manifest | 0 10 files changed, 68 insertions(+), 62 deletions(-) rename ProjectHeads/AllComponents/{Tests.WinAppSdk/CommunityToolkit.Tests.WinAppSdk.csproj => Tests.Wasdk/CommunityToolkit.Tests.Wasdk.csproj} (100%) rename ProjectHeads/AllComponents/{Tests.WinAppSdk => Tests.Wasdk}/Package.appxmanifest (100%) rename ProjectHeads/AllComponents/{Tests.WinAppSdk => Tests.Wasdk}/Properties/launchSettings.json (100%) rename ProjectHeads/AllComponents/{Tests.WinAppSdk => Tests.Wasdk}/app.manifest (100%) rename ProjectHeads/AllComponents/{WinAppSdk/CommunityToolkit.App.WinAppSdk.csproj => Wasdk/CommunityToolkit.App.Wasdk.csproj} (100%) rename ProjectHeads/AllComponents/{WinAppSdk => Wasdk}/Package.appxmanifest (100%) rename ProjectHeads/AllComponents/{WinAppSdk => Wasdk}/Properties/launchSettings.json (100%) rename ProjectHeads/AllComponents/{WinAppSdk => Wasdk}/app.manifest (100%) diff --git a/GenerateAllSolution.ps1 b/GenerateAllSolution.ps1 index 888888f9..f2a7f7f5 100644 --- a/GenerateAllSolution.ps1 +++ b/GenerateAllSolution.ps1 @@ -7,27 +7,31 @@ Otherwise it is recommended to focus on an individual component's solution instead. .PARAMETER IncludeHeads - List of TFM based projects to include. This can be 'all', 'uwp', or 'winappsdk'. + List of TFM based projects to include. This can be 'all', 'uwp', or 'wasdk'. - Defaults to 'all' for local-use. + Defaults to 'all'. .PARAMETER UseDiagnostics Add extra diagnostic output to running slngen, such as a binlog, etc... .EXAMPLE - C:\PS> .\GenerateAllSolution -IncludeHeads winappsdk + C:\PS> .\GenerateAllSolution -IncludeHeads wasdk Build a solution that doesn't contain UWP projects. .NOTES Author: Windows Community Toolkit Labs Team Date: April 27, 2022 #> Param ( - [Parameter(HelpMessage = "The heads to include for building platform samples and tests.", ParameterSetName = "IncludeHeads")] - [ValidateSet('all', 'uwp', 'winappsdk')] - [string]$IncludeHeads = 'all', + [Parameter(HelpMessage = "The heads to include for building the sample gallery and tests.", ParameterSetName = "IncludeHeads")] + [ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')] + [string[]]$IncludeHeads = @('all'), [Parameter(HelpMessage = "Add extra diagnostic output to slngen generator.")] [switch]$UseDiagnostics = $false ) +if ($IncludeHeads.Contains('all')) { + $IncludeHeads = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android') +} + # Generate required props for "All" solution. & ./tooling/MultiTarget/GenerateAllProjectReferences.ps1 @@ -55,18 +59,21 @@ $projects = [System.Collections.ArrayList]::new() # Common/Dependencies for shared infrastructure [void]$projects.Add(".\tooling\CommunityToolkit*\*.*proj") -# App Head and Test Head -if ($IncludeHeads -ne 'winappsdk') -{ - [void]$projects.Add(".\tooling\ProjectHeads\AllComponents\**\*.Uwp.csproj") -} +# TODO: this handles separate project heads, but won't directly handle the unified Skia head from Uno. +# Once we have that, just do a transform on the csproj filename inside this loop to decide the same csproj for those separate MultiTargets. +foreach ($multitarget in $IncludeHeads) { + # capitalize first letter, avoid case sensitivity issues on linux + $csprojFileNamePartForMultiTarget = $multitarget.substring(0,1).ToUpper() + $multitarget.Substring(1).ToLower() -if ($IncludeHeads -ne 'uwp') -{ - [void]$projects.Add(".\tooling\ProjectHeads\AllComponents\**\*.WinAppSdk.csproj") -} + $path = ".\tooling\ProjectHeads\AllComponents\**\*.$csprojFileNamePartForMultiTarget.csproj"; -[void]$projects.Add(".\tooling\ProjectHeads\AllComponents\**\*.Wasm.csproj") + if (Test-Path $path) { + [void]$projects.Add($path) + } + else { + Write-Warning "No project head could be found at $path for MultiTarget $multitarget. Skipping." + } +} # Individual projects [void]$projects.Add(".\components\**\src\*.csproj") diff --git a/MultiTarget/UseTargetFrameworks.ps1 b/MultiTarget/UseTargetFrameworks.ps1 index b79ff2b8..d2ab7877 100644 --- a/MultiTarget/UseTargetFrameworks.ps1 +++ b/MultiTarget/UseTargetFrameworks.ps1 @@ -3,29 +3,32 @@ Changes the target frameworks to build for each package created within the repository. .DESCRIPTION By default, only the UWP, Windows App SDK, and WASM heads are built to simplify dependencies - needed to build projects within the repository. The CI will enable all targets to build a package + needed to build projects within the repository. The CI will enable all include to build a package that works on all supported platforms. Note: Projects which rely on target platforms that are excluded will be unable to build. -.PARAMETER targets - List of targets to set as TFM platforms to build for. Possible values match those provided to the MSBuild property, as well as 'all', 'all-uwp', 'all-wasdk', or blank. - When run as blank, the defaults (uwp, winappsdk, wasm) will be used. - 'all', 'all-uwp', and 'all-wasdk' shouldn't be used with other targets or each other. -.PARAMETER allowGitChanges - Enabling this flag will allow changes to the props file to be checked into source control. - By default the file is ignored so local changes to building don't accidently get checked in. +.PARAMETER include + List of include to set as TFM platforms to build for. Possible values match those provided to the MSBuild property. + By default, uwp, wasdk, and wasm will included. +.PARAMETER exclude + List to exclude from build. Possible values match those provided to the MSBuild property. + By default, none will excluded. .EXAMPLE - C:\PS> .\UseTargetFrameworks winappsdk - Build targets for just the WindowsAppSDK. + C:\PS> .\UseTargetFrameworks wasdk + Build include for just the WindowsAppSDK. .NOTES Author: Windows Community Toolkit Labs Team Date: April 8, 2022 #> Param ( [Parameter(HelpMessage = "The target frameworks to enable.")] - [ValidateSet('all', 'all-uwp', 'all-wasdk', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] - [string[]]$targets = @('uwp', 'winappsdk', 'wasm') # default settings -) + [ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] + [string[]]$include = @('uwp', 'wasdk', 'wasm'), # default settings + + [Parameter(HelpMessage = "The target frameworks to disable.")] + [ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] + [string[]]$exclude = @() # default settings +)3 $UwpTfm = "UwpTargetFramework"; $WinAppSdkTfm = "WinAppSdkTargetFramework"; @@ -39,71 +42,67 @@ $NetstandardTfm = "DotnetStandardCommonTargetFramework"; $fileContents = Get-Content -Path $PSScriptRoot/AvailableTargetFrameworks.props -$allTargetFrameworks = @( - $WasmTfm, - $UwpTfm, - $WinAppSdkTfm, - $WpfTfm, - $GtkTfm, - $macOSTfm, - $iOSTfm, - $DroidTfm, - $NetstandardTfm -); - -$desiredTfmValues = @(); - -if ($targets.Contains("all")) { - $desiredTfmValues = $allTargetFrameworks; +# 'all' represents many '$include' values +if ($include.Contains("all")) { + $include = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard') } -if ($targets.Contains("all-uwp")) { - $desiredTfmValues = $allTargetFrameworks.Replace($UwpTfm, ""); +# Exclude as needed +foreach ($excluded in $exclude) { + $include = $include.Where({ $_ -ne $excluded }); } -if ($targets.Contains("all-wasdk")) { - $desiredTfmValues = $allTargetFrameworks.Replace($WinAppSdkTfm, ""); -} +Write-Output "Setting enabled TargetFrameworks: $include" + +$desiredTfmValues = @(); -if ($targets.Contains("wasm")) { +if ($include.Contains("wasm")) { $desiredTfmValues += $WasmTfm; } -if ($targets.Contains("uwp")) { +if ($include.Contains("uwp")) { $desiredTfmValues += $UwpTfm; } -if ($targets.Contains("wasdk")) { +if ($include.Contains("wasdk")) { $desiredTfmValues += $WinAppSdkTfm; } -if ($targets.Contains("wpf")) { +if ($include.Contains("wpf")) { $desiredTfmValues += $WpfTfm; } -if ($targets.Contains("linuxgtk")) { +if ($include.Contains("linuxgtk")) { $desiredTfmValues += $GtkTfm; } -if ($targets.Contains("macos")) { +if ($include.Contains("macos")) { $desiredTfmValues += $macOSTfm; } -if ($targets.Contains("ios")) { +if ($include.Contains("ios")) { $desiredTfmValues += $iOSTfm; } -if ($targets.Contains("android")) { +if ($include.Contains("android")) { $desiredTfmValues += $DroidTfm; } -if ($targets.Contains("netstandard")) { +if ($include.Contains("netstandard")) { $desiredTfmValues += $NetstandardTfm; } -Write-Output "Setting enabled TargetFrameworks: $targets" - -$targetFrameworksToRemove = $allTargetFrameworks.Where({ -not $desiredTfmValues.Contains($_) }) +$targetFrameworksToRemove = @( + $WasmTfm, + $UwpTfm, + $WinAppSdkTfm, + $WpfTfm, + $GtkTfm, + $macOSTfm, + $iOSTfm, + $DroidTfm, + $NetstandardTfm +).Where({ -not $desiredTfmValues.Contains($_) }) $targetFrameworksToRemoveRegexPartial = $targetFrameworksToRemove -join "|"; diff --git a/ProjectHeads/AllComponents/Tests.WinAppSdk/CommunityToolkit.Tests.WinAppSdk.csproj b/ProjectHeads/AllComponents/Tests.Wasdk/CommunityToolkit.Tests.Wasdk.csproj similarity index 100% rename from ProjectHeads/AllComponents/Tests.WinAppSdk/CommunityToolkit.Tests.WinAppSdk.csproj rename to ProjectHeads/AllComponents/Tests.Wasdk/CommunityToolkit.Tests.Wasdk.csproj diff --git a/ProjectHeads/AllComponents/Tests.WinAppSdk/Package.appxmanifest b/ProjectHeads/AllComponents/Tests.Wasdk/Package.appxmanifest similarity index 100% rename from ProjectHeads/AllComponents/Tests.WinAppSdk/Package.appxmanifest rename to ProjectHeads/AllComponents/Tests.Wasdk/Package.appxmanifest diff --git a/ProjectHeads/AllComponents/Tests.WinAppSdk/Properties/launchSettings.json b/ProjectHeads/AllComponents/Tests.Wasdk/Properties/launchSettings.json similarity index 100% rename from ProjectHeads/AllComponents/Tests.WinAppSdk/Properties/launchSettings.json rename to ProjectHeads/AllComponents/Tests.Wasdk/Properties/launchSettings.json diff --git a/ProjectHeads/AllComponents/Tests.WinAppSdk/app.manifest b/ProjectHeads/AllComponents/Tests.Wasdk/app.manifest similarity index 100% rename from ProjectHeads/AllComponents/Tests.WinAppSdk/app.manifest rename to ProjectHeads/AllComponents/Tests.Wasdk/app.manifest diff --git a/ProjectHeads/AllComponents/WinAppSdk/CommunityToolkit.App.WinAppSdk.csproj b/ProjectHeads/AllComponents/Wasdk/CommunityToolkit.App.Wasdk.csproj similarity index 100% rename from ProjectHeads/AllComponents/WinAppSdk/CommunityToolkit.App.WinAppSdk.csproj rename to ProjectHeads/AllComponents/Wasdk/CommunityToolkit.App.Wasdk.csproj diff --git a/ProjectHeads/AllComponents/WinAppSdk/Package.appxmanifest b/ProjectHeads/AllComponents/Wasdk/Package.appxmanifest similarity index 100% rename from ProjectHeads/AllComponents/WinAppSdk/Package.appxmanifest rename to ProjectHeads/AllComponents/Wasdk/Package.appxmanifest diff --git a/ProjectHeads/AllComponents/WinAppSdk/Properties/launchSettings.json b/ProjectHeads/AllComponents/Wasdk/Properties/launchSettings.json similarity index 100% rename from ProjectHeads/AllComponents/WinAppSdk/Properties/launchSettings.json rename to ProjectHeads/AllComponents/Wasdk/Properties/launchSettings.json diff --git a/ProjectHeads/AllComponents/WinAppSdk/app.manifest b/ProjectHeads/AllComponents/Wasdk/app.manifest similarity index 100% rename from ProjectHeads/AllComponents/WinAppSdk/app.manifest rename to ProjectHeads/AllComponents/Wasdk/app.manifest From a7d5d4670de69d69eac681815a8e21fc8ca364f2 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 26 Jul 2024 13:26:06 -0500 Subject: [PATCH 2/8] Fix head names in gallery build script --- Build-Toolkit-Gallery.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Build-Toolkit-Gallery.ps1 b/Build-Toolkit-Gallery.ps1 index 72070fa0..1a79f134 100644 --- a/Build-Toolkit-Gallery.ps1 +++ b/Build-Toolkit-Gallery.ps1 @@ -12,7 +12,7 @@ Specifies the MultiTarget TFM(s) to exclude for building the components. The default value excludes targets that require additional tooling or workloads to build: 'wpf', 'linuxgtk', 'macos', 'ios', and 'android'. Run uno-check to install the required workloads. .PARAMETER Heads - The heads to include in the build. Default is 'Uwp', 'WinAppSdk', 'Wasm'. + The heads to include in the build. Default is 'Uwp', 'Wasdk', 'Wasm'. .PARAMETER ExcludeHeads The heads to exclude from the build. Default is none. @@ -52,10 +52,10 @@ Param ( [ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] [string[]]$ExcludeMultiTargets = @('wpf', 'linuxgtk', 'macos', 'ios', 'android'), - [ValidateSet('all', 'Uwp', 'WinAppSdk', 'Wasm', 'Tests.Uwp', 'Tests.WinAppSdk')] - [string[]]$Heads = @('Uwp', 'WinAppSdk', 'Wasm'), + [ValidateSet('all', 'Uwp', 'Wasdk', 'Wasm', 'Tests.Uwp', 'Tests.Wasdk')] + [string[]]$Heads = @('Uwp', 'Wasdk', 'Wasm'), - [ValidateSet('Uwp', 'WinAppSdk', 'Wasm', 'Tests.Uwp', 'Tests.WinAppSdk')] + [ValidateSet('Uwp', 'Wasdk', 'Wasm', 'Tests.Uwp', 'Tests.Wasdk')] [string[]]$ExcludeHeads, [Alias("bl")] @@ -113,7 +113,7 @@ if ($Components -notcontains 'Converters') { & $PSScriptRoot\MultiTarget\GenerateAllProjectReferences.ps1 -MultiTarget $MultiTargets -Components $Components if ($Heads -eq 'all') { - $Heads = @('Uwp', 'WinAppSdk', 'Wasm', 'Tests.Uwp', 'Tests.WinAppSdk') + $Heads = @('Uwp', 'Wasdk', 'Wasm', 'Tests.Uwp', 'Tests.Wasdk') } function Invoke-MSBuildWithBinlog { From f3c24c1afe44fc83403f7b04ac147840b87b4816 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 26 Jul 2024 15:39:45 -0500 Subject: [PATCH 3/8] Fix multitarget name for droid --- MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 b/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 index a87f2603..0f9c47b7 100644 --- a/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 +++ b/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 @@ -67,7 +67,7 @@ $templateContents = $templateContents -replace [regex]::escape("[CanTargetWpf]") $templateContents = $templateContents -replace [regex]::escape("[CanTargetLinuxGtk]"), "'$(ShouldMultiTarget "linuxgtk")'"; $templateContents = $templateContents -replace [regex]::escape("[CanTargetMacOS]"), "'$(ShouldMultiTarget "macos")'"; $templateContents = $templateContents -replace [regex]::escape("[CanTargetiOS]"), "'$(ShouldMultiTarget "ios")'"; -$templateContents = $templateContents -replace [regex]::escape("[CanTargetDroid]"), "'$(ShouldMultiTarget "droid")'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetDroid]"), "'$(ShouldMultiTarget "android")'"; $templateContents = $templateContents -replace [regex]::escape("[CanTargetNetstandard]"), "'$(ShouldMultiTarget "netstandard")'"; # Save to disk From 34e683a898b647acef044a56d9a9b9b2e037881d Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 26 Jul 2024 17:14:04 -0500 Subject: [PATCH 4/8] Handle specific MultiTargets and Components for solution and project reference generation --- Build-Toolkit-Components.ps1 | 11 ++- Build-Toolkit-Gallery.ps1 | 9 ++- GenerateAllSolution.ps1 | 81 ++++++++++++++++--- MultiTarget/GenerateAllProjectReferences.ps1 | 10 +-- ...eMultiTargetAwareProjectReferenceProps.ps1 | 44 ++++++---- MultiTarget/UseTargetFrameworks.ps1 | 41 +++++----- 6 files changed, 136 insertions(+), 60 deletions(-) diff --git a/Build-Toolkit-Components.ps1 b/Build-Toolkit-Components.ps1 index 068f96d7..87e61598 100644 --- a/Build-Toolkit-Components.ps1 +++ b/Build-Toolkit-Components.ps1 @@ -58,11 +58,13 @@ #> Param ( [ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] - [string[]]$MultiTargets = @('all'), + [Alias("mt")] + [string[]]$MultiTargets = @('uwp', 'wasdk', 'wasm'), # default settings [ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] - [string[]]$ExcludeMultiTargets = @('wpf', 'linuxgtk', 'macos', 'ios', 'android'), + [string[]]$ExcludeMultiTargets = @() # default settings + [Alias("c")] [string[]]$Components = @("all"), [string[]]$ExcludeComponents, @@ -76,10 +78,13 @@ Param ( [Alias("bl")] [switch]$EnableBinLogs, + [Alias("blo")] [string]$BinlogOutput, - + + [Alias("p")] [hashtable]$AdditionalProperties, + [Alias("winui")] [int]$WinUIMajorVersion = 2, [string]$ComponentDir = "src", diff --git a/Build-Toolkit-Gallery.ps1 b/Build-Toolkit-Gallery.ps1 index 1a79f134..b08abe47 100644 --- a/Build-Toolkit-Gallery.ps1 +++ b/Build-Toolkit-Gallery.ps1 @@ -47,10 +47,11 @@ #> Param ( [ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] - [string[]]$MultiTargets = @('all'), + [Alias("mt")] + [string[]]$MultiTargets = @('uwp', 'wasdk', 'wasm'), # default settings [ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] - [string[]]$ExcludeMultiTargets = @('wpf', 'linuxgtk', 'macos', 'ios', 'android'), + [string[]]$ExcludeMultiTargets = @() # default settings [ValidateSet('all', 'Uwp', 'Wasdk', 'Wasm', 'Tests.Uwp', 'Tests.Wasdk')] [string[]]$Heads = @('Uwp', 'Wasdk', 'Wasm'), @@ -61,12 +62,16 @@ Param ( [Alias("bl")] [switch]$EnableBinLogs, + [Alias("blo")] [string]$BinlogOutput, + [Alias("p")] [hashtable]$AdditionalProperties, + [Alias("winui")] [int]$WinUIMajorVersion = 2, + [Alias("c")] [string[]]$Components = @("all"), [string[]]$ExcludeComponents, diff --git a/GenerateAllSolution.ps1 b/GenerateAllSolution.ps1 index f2a7f7f5..4235e148 100644 --- a/GenerateAllSolution.ps1 +++ b/GenerateAllSolution.ps1 @@ -1,39 +1,71 @@ <# .SYNOPSIS Generates the solution file comprising of platform heads for samples, individual component projects, and tests. + .DESCRIPTION Used mostly for CI building of everything and testing end-to-end scenarios involving the full sample app experience. Otherwise it is recommended to focus on an individual component's solution instead. -.PARAMETER IncludeHeads - List of TFM based projects to include. This can be 'all', 'uwp', or 'wasdk'. - Defaults to 'all'. +.PARAMETER MultiTargets + Specifies the MultiTarget TFM(s) to include for building the components. The default value is 'all'. + +.PARAMETER ExcludeMultiTargets + 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. + +.PARAMETER Components + The names of the components to generate project and solution references for. Defaults to all components. + +.PARAMETER ExcludeComponents + The names of the components to exclude when generating solution and project references. Defaults to none. + .PARAMETER UseDiagnostics Add extra diagnostic output to running slngen, such as a binlog, etc... + .EXAMPLE - C:\PS> .\GenerateAllSolution -IncludeHeads wasdk + C:\PS> .\GenerateAllSolution -MultiTargets wasdk Build a solution that doesn't contain UWP projects. + .NOTES Author: Windows Community Toolkit Labs Team Date: April 27, 2022 #> Param ( - [Parameter(HelpMessage = "The heads to include for building the sample gallery and tests.", ParameterSetName = "IncludeHeads")] + [Parameter(HelpMessage = "The heads to include for building the sample gallery and tests.", ParameterSetName = "MultiTargets")] [ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')] - [string[]]$IncludeHeads = @('all'), + [Alias("mt")] + [string[]]$MultiTargets = @('all'), + + [Parameter(HelpMessage = "The target frameworks to disable.")] + [ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] + [string[]]$ExcludeMultiTargets = @() # default settings + + [Parameter(HelpMessage = "The names of the components to generate project and solution references for. Defaults to all components.")] + [Alias("c")] + [string[]]$Components = @('all'), + + [Parameter(HelpMessage = "The names of the components to exclude when generating solution and project references.")] + [string[]]$ExcludeComponents, [Parameter(HelpMessage = "Add extra diagnostic output to slngen generator.")] [switch]$UseDiagnostics = $false ) -if ($IncludeHeads.Contains('all')) { - $IncludeHeads = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android') +if ($MultiTargets.Contains('all')) { + $MultiTargets = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android') +} + +if ($null -eq $ExcludeMultiTargets) +{ + $ExcludeMultiTargets = @() } +$MultiTargets = $MultiTargets | Where-Object { $_ -notin $ExcludeMultiTargets } + # Generate required props for "All" solution. -& ./tooling/MultiTarget/GenerateAllProjectReferences.ps1 +& ./tooling/MultiTarget/GenerateAllProjectReferences.ps1 -MultiTargets $MultiTargets -Components $Components -ExcludeComponents $ExcludeComponents +& ./tooling/MultiTarget/UseTargetFrameworks.ps1 -MultiTargets $MultiTargets # Set up constant values $generatedSolutionFilePath = 'CommunityToolkit.AllComponents.sln' @@ -59,9 +91,10 @@ $projects = [System.Collections.ArrayList]::new() # Common/Dependencies for shared infrastructure [void]$projects.Add(".\tooling\CommunityToolkit*\*.*proj") +# Deployable sample gallery heads # TODO: this handles separate project heads, but won't directly handle the unified Skia head from Uno. # Once we have that, just do a transform on the csproj filename inside this loop to decide the same csproj for those separate MultiTargets. -foreach ($multitarget in $IncludeHeads) { +foreach ($multitarget in $MultiTargets) { # capitalize first letter, avoid case sensitivity issues on linux $csprojFileNamePartForMultiTarget = $multitarget.substring(0,1).ToUpper() + $multitarget.Substring(1).ToLower() @@ -76,9 +109,31 @@ foreach ($multitarget in $IncludeHeads) { } # Individual projects -[void]$projects.Add(".\components\**\src\*.csproj") -[void]$projects.Add(".\components\**\samples\*.Samples.csproj") -[void]$projects.Add(".\components\**\tests\*.Tests\*.shproj") +if ($Components -eq @('all')) { + $Components = @('**') +} + +foreach ($componentName in $Components) { + if ($ExcludeComponents -contains $componentName) { + continue; + } + + foreach ($componentPath in Get-Item "$PSScriptRoot/../components/$componentName/") { + $multiTargetPrefs = & $PSScriptRoot\MultiTarget\Get-MultiTargets.ps1 -component $($componentPath.BaseName) + + $shouldReferenceInSolution = $multiTargetPrefs.Where({ $MultiTargets.Contains($_) }).Count -gt 0 + + if ($shouldReferenceInSolution) { + Write-Output "Add component $componentPath to solution"; + + [void]$projects.Add(".\components\$($componentPath.BaseName)\src\*.csproj") + [void]$projects.Add(".\components\$($componentPath.BaseName)\samples\*.Samples.csproj") + [void]$projects.Add(".\components\$($componentPath.BaseName)\tests\*.Tests\*.shproj") + } else { + Write-Warning "Component $($componentPath.BaseName) doesn't MultiTarget any of $MultiTargets and won't be added to the solution."; + } + } +} if ($UseDiagnostics.IsPresent) { diff --git a/MultiTarget/GenerateAllProjectReferences.ps1 b/MultiTarget/GenerateAllProjectReferences.ps1 index 821c8f1c..1cca529e 100644 --- a/MultiTarget/GenerateAllProjectReferences.ps1 +++ b/MultiTarget/GenerateAllProjectReferences.ps1 @@ -3,7 +3,9 @@ Param ( [string]$projectPropsOutputDir = "$PSScriptRoot/Generated", [Parameter(HelpMessage = "Only projects that support these targets will have references generated for use by deployable heads.")] - [string[]]$MultiTarget = @("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android", "netstandard"), + [Alias("mt")] + [ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] + [string[]]$MultiTargets = @("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android", "netstandard"), [Parameter(HelpMessage = "The names of the components to generate references for. Defaults to all components.")] [string[]]$Components = @("all"), @@ -30,8 +32,6 @@ foreach ($componentName in $Components) { # Find all components source csproj (when wildcard), or find specific component csproj by name. foreach ($componentPath in Get-Item "$PSScriptRoot/../../components/$componentName/") { - Write-Output "Generating project references for component $componentName at $componentPath"; - # Find source and sample csproj files $componentSourceCsproj = Get-ChildItem $componentPath/src/*.csproj -ErrorAction SilentlyContinue; $componentSampleCsproj = Get-ChildItem $componentPath/samples/*.csproj -ErrorAction SilentlyContinue; @@ -39,11 +39,11 @@ foreach ($componentName in $Components) { # Generate s for sample project # Use source project MultiTarget as first fallback. if ($null -ne $componentSampleCsproj -and (Test-Path $componentSampleCsproj)) { - & $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $componentSampleCsproj -outputPath "$projectPropsOutputDir/$($componentSampleCsproj.BaseName).props" -MultiTarget $MultiTarget + & $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $componentSampleCsproj -outputPath "$projectPropsOutputDir/$($componentSampleCsproj.BaseName).props" -MultiTargets $MultiTargets } # Generate s for src project - & $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $componentSourceCsproj -outputPath "$projectPropsOutputDir/$($componentSourceCsproj.BaseName).props" -MultiTarget $MultiTarget + & $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $componentSourceCsproj -outputPath "$projectPropsOutputDir/$($componentSourceCsproj.BaseName).props" -MultiTargets $MultiTargets } } diff --git a/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 b/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 index 0f9c47b7..6890d89e 100644 --- a/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 +++ b/MultiTarget/GenerateMultiTargetAwareProjectReferenceProps.ps1 @@ -16,7 +16,8 @@ Param ( [Parameter(HelpMessage = "Only projects that support these targets will have references generated for use by deployable heads.")] [ValidateSet("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android", "netstandard")] - [string[]] $MultiTarget = @("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android", "netstandard") + [Alias("mt")] + [string[]] $MultiTargets = @("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android", "netstandard") ) $templateContents = Get-Content -Path $templatePath; @@ -40,35 +41,44 @@ $templateContents = $templateContents -replace [regex]::escape($projectRootPlace $componentPath = Get-Item "$projectPath/../../" # Load multitarget preferences for component -$multiTargets = & $PSScriptRoot\Get-MultiTargets.ps1 -component $($componentPath.BaseName) +$multiTargetPrefs = & $PSScriptRoot\Get-MultiTargets.ps1 -component $($componentPath.BaseName) -if ($null -eq $multiTargets) { +if ($null -eq $multiTargetPrefs) { Write-Error "Couldn't get MultiTarget property for $componentPath"; exit(-1); } -# Ensure multiTargets is not empty -if ($multiTargets.Length -eq 0) { +# Ensure multiTargetPrefs is not empty +if ($multiTargetPrefs.Length -eq 0) { Write-Error "MultiTarget property is empty for $projectPath"; exit(-1); } -$templateContents = $templateContents -replace [regex]::escape("[IntendedTargets]"), $multiTargets; +$templateContents = $templateContents -replace [regex]::escape("[IntendedTargets]"), $multiTargetPrefs; function ShouldMultiTarget([string] $target) { - return ($multiTargets.Contains($target) -and $MultiTarget.Contains($target)).ToString().ToLower() + return ($multiTargetPrefs.Contains($target) -and $MultiTargets.Contains($target)) } -Write-Host "Generating project references for $([System.IO.Path]::GetFileNameWithoutExtension($csprojFileName)): $($multiTargets -Join ', ')" -$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasm]"), "'$(ShouldMultiTarget "wasm")'"; -$templateContents = $templateContents -replace [regex]::escape("[CanTargetUwp]"), "'$(ShouldMultiTarget "uwp")'"; -$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasdk]"), "'$(ShouldMultiTarget "wasdk")'"; -$templateContents = $templateContents -replace [regex]::escape("[CanTargetWpf]"), "'$(ShouldMultiTarget "wpf")'"; -$templateContents = $templateContents -replace [regex]::escape("[CanTargetLinuxGtk]"), "'$(ShouldMultiTarget "linuxgtk")'"; -$templateContents = $templateContents -replace [regex]::escape("[CanTargetMacOS]"), "'$(ShouldMultiTarget "macos")'"; -$templateContents = $templateContents -replace [regex]::escape("[CanTargetiOS]"), "'$(ShouldMultiTarget "ios")'"; -$templateContents = $templateContents -replace [regex]::escape("[CanTargetDroid]"), "'$(ShouldMultiTarget "android")'"; -$templateContents = $templateContents -replace [regex]::escape("[CanTargetNetstandard]"), "'$(ShouldMultiTarget "netstandard")'"; +function ShouldMultiTargetMsBuildValue([string] $target) { + return $(ShouldMultiTarget $target).ToString().ToLower() +} + +$targeted = @("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android", "netstandard").Where({ ShouldMultiTarget $_ }) + +if ($targeted.Count -gt 0) { + Write-Host "Generating project references for $([System.IO.Path]::GetFileNameWithoutExtension($csprojFileName)): $($targeted -Join ', ')" +} + +$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasm]"), "'$(ShouldMultiTargetMsBuildValue "wasm")'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetUwp]"), "'$(ShouldMultiTargetMsBuildValue "uwp")'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasdk]"), "'$(ShouldMultiTargetMsBuildValue "wasdk")'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetWpf]"), "'$(ShouldMultiTargetMsBuildValue "wpf")'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetLinuxGtk]"), "'$(ShouldMultiTargetMsBuildValue "linuxgtk")'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetMacOS]"), "'$(ShouldMultiTargetMsBuildValue "macos")'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetiOS]"), "'$(ShouldMultiTargetMsBuildValue "ios")'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetDroid]"), "'$(ShouldMultiTargetMsBuildValue "android")'"; +$templateContents = $templateContents -replace [regex]::escape("[CanTargetNetstandard]"), "'$(ShouldMultiTargetMsBuildValue "netstandard")'"; # Save to disk Set-Content -Path $outputPath -Value $templateContents; diff --git a/MultiTarget/UseTargetFrameworks.ps1 b/MultiTarget/UseTargetFrameworks.ps1 index d2ab7877..71adef08 100644 --- a/MultiTarget/UseTargetFrameworks.ps1 +++ b/MultiTarget/UseTargetFrameworks.ps1 @@ -7,10 +7,10 @@ that works on all supported platforms. Note: Projects which rely on target platforms that are excluded will be unable to build. -.PARAMETER include +.PARAMETER MultiTargets List of include to set as TFM platforms to build for. Possible values match those provided to the MSBuild property. By default, uwp, wasdk, and wasm will included. -.PARAMETER exclude +.PARAMETER ExcludeMultiTargets List to exclude from build. Possible values match those provided to the MSBuild property. By default, none will excluded. .EXAMPLE @@ -23,12 +23,13 @@ Param ( [Parameter(HelpMessage = "The target frameworks to enable.")] [ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] - [string[]]$include = @('uwp', 'wasdk', 'wasm'), # default settings + [Alias("mt")] + [string[]]$MultiTargets = @('uwp', 'wasdk', 'wasm'), # default settings [Parameter(HelpMessage = "The target frameworks to disable.")] [ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] - [string[]]$exclude = @() # default settings -)3 + [string[]]$ExcludeMultiTargets = @() # default settings +) $UwpTfm = "UwpTargetFramework"; $WinAppSdkTfm = "WinAppSdkTargetFramework"; @@ -42,53 +43,53 @@ $NetstandardTfm = "DotnetStandardCommonTargetFramework"; $fileContents = Get-Content -Path $PSScriptRoot/AvailableTargetFrameworks.props -# 'all' represents many '$include' values -if ($include.Contains("all")) { - $include = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard') +# 'all' represents many '$MultiTargets' values +if ($MultiTargets.Contains("all")) { + $MultiTargets = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard') } # Exclude as needed -foreach ($excluded in $exclude) { - $include = $include.Where({ $_ -ne $excluded }); +foreach ($excluded in $ExcludeMultiTargets) { + $MultiTargets = $MultiTargets.Where({ $_ -ne $excluded }); } -Write-Output "Setting enabled TargetFrameworks: $include" +Write-Output "Setting enabled TargetFrameworks: $MultiTargets" $desiredTfmValues = @(); -if ($include.Contains("wasm")) { +if ($MultiTargets.Contains("wasm")) { $desiredTfmValues += $WasmTfm; } -if ($include.Contains("uwp")) { +if ($MultiTargets.Contains("uwp")) { $desiredTfmValues += $UwpTfm; } -if ($include.Contains("wasdk")) { +if ($MultiTargets.Contains("wasdk")) { $desiredTfmValues += $WinAppSdkTfm; } -if ($include.Contains("wpf")) { +if ($MultiTargets.Contains("wpf")) { $desiredTfmValues += $WpfTfm; } -if ($include.Contains("linuxgtk")) { +if ($MultiTargets.Contains("linuxgtk")) { $desiredTfmValues += $GtkTfm; } -if ($include.Contains("macos")) { +if ($MultiTargets.Contains("macos")) { $desiredTfmValues += $macOSTfm; } -if ($include.Contains("ios")) { +if ($MultiTargets.Contains("ios")) { $desiredTfmValues += $iOSTfm; } -if ($include.Contains("android")) { +if ($MultiTargets.Contains("android")) { $desiredTfmValues += $DroidTfm; } -if ($include.Contains("netstandard")) { +if ($MultiTargets.Contains("netstandard")) { $desiredTfmValues += $NetstandardTfm; } From 8a65ec08f7186b5a34d759776e1c1eece6f9fc7f Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 26 Jul 2024 17:58:31 -0500 Subject: [PATCH 5/8] Fixed default multitarget values, pass and apply WinUIMajorVersion --- GenerateAllSolution.ps1 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/GenerateAllSolution.ps1 b/GenerateAllSolution.ps1 index 4235e148..f4282943 100644 --- a/GenerateAllSolution.ps1 +++ b/GenerateAllSolution.ps1 @@ -20,6 +20,9 @@ .PARAMETER ExcludeComponents The names of the components to exclude when generating solution and project references. Defaults to none. +.PARAMETER WinUIMajorVersion + Specifies the WinUI major version to use when building an Uno head. Also decides the package id and dependency variant. The default value is '2'. + .PARAMETER UseDiagnostics Add extra diagnostic output to running slngen, such as a binlog, etc... @@ -32,23 +35,21 @@ Date: April 27, 2022 #> Param ( - [Parameter(HelpMessage = "The heads to include for building the sample gallery and tests.", ParameterSetName = "MultiTargets")] [ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')] [Alias("mt")] - [string[]]$MultiTargets = @('all'), + [string[]]$MultiTargets = @('uwp', 'wasm', 'wasdk'), - [Parameter(HelpMessage = "The target frameworks to disable.")] [ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] - [string[]]$ExcludeMultiTargets = @() # default settings + [string[]]$ExcludeMultiTargets = @(), # default settings - [Parameter(HelpMessage = "The names of the components to generate project and solution references for. Defaults to all components.")] [Alias("c")] [string[]]$Components = @('all'), - [Parameter(HelpMessage = "The names of the components to exclude when generating solution and project references.")] + [Alias("winui")] + [int]$WinUIMajorVersion = 2, + [string[]]$ExcludeComponents, - [Parameter(HelpMessage = "Add extra diagnostic output to slngen generator.")] [switch]$UseDiagnostics = $false ) @@ -66,6 +67,7 @@ $MultiTargets = $MultiTargets | Where-Object { $_ -notin $ExcludeMultiTargets } # Generate required props for "All" solution. & ./tooling/MultiTarget/GenerateAllProjectReferences.ps1 -MultiTargets $MultiTargets -Components $Components -ExcludeComponents $ExcludeComponents & ./tooling/MultiTarget/UseTargetFrameworks.ps1 -MultiTargets $MultiTargets +& ./tooling/MultiTarget/UseUnoWinUI.ps1 $WinUIMajorVersion # Set up constant values $generatedSolutionFilePath = 'CommunityToolkit.AllComponents.sln' From a9c9407c384d90a6593123c9662e592be883555b Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Mon, 29 Jul 2024 13:07:35 -0500 Subject: [PATCH 6/8] Fixed syntax error --- Build-Toolkit-Components.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Build-Toolkit-Components.ps1 b/Build-Toolkit-Components.ps1 index 87e61598..d797d5df 100644 --- a/Build-Toolkit-Components.ps1 +++ b/Build-Toolkit-Components.ps1 @@ -62,7 +62,7 @@ Param ( [string[]]$MultiTargets = @('uwp', 'wasdk', 'wasm'), # default settings [ValidateSet('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android', 'netstandard')] - [string[]]$ExcludeMultiTargets = @() # default settings + [string[]]$ExcludeMultiTargets = @(), # default settings [Alias("c")] [string[]]$Components = @("all"), From fda081e11081ec7b0c034cdacbb817d906128b24 Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Tue, 30 Jul 2024 18:19:47 -0500 Subject: [PATCH 7/8] Fixed bad find/replace --- MultiTarget/UseTargetFrameworks.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MultiTarget/UseTargetFrameworks.ps1 b/MultiTarget/UseTargetFrameworks.ps1 index 71adef08..544c2b5a 100644 --- a/MultiTarget/UseTargetFrameworks.ps1 +++ b/MultiTarget/UseTargetFrameworks.ps1 @@ -3,19 +3,19 @@ Changes the target frameworks to build for each package created within the repository. .DESCRIPTION By default, only the UWP, Windows App SDK, and WASM heads are built to simplify dependencies - needed to build projects within the repository. The CI will enable all include to build a package + needed to build projects within the repository. The CI will enable all targets to build a package that works on all supported platforms. Note: Projects which rely on target platforms that are excluded will be unable to build. .PARAMETER MultiTargets - List of include to set as TFM platforms to build for. Possible values match those provided to the MSBuild property. + List of targets to set as TFM platforms to build for. Possible values match those provided to the MSBuild property. By default, uwp, wasdk, and wasm will included. .PARAMETER ExcludeMultiTargets List to exclude from build. Possible values match those provided to the MSBuild property. By default, none will excluded. .EXAMPLE C:\PS> .\UseTargetFrameworks wasdk - Build include for just the WindowsAppSDK. + Build TFMs for only the Windows App SDK. .NOTES Author: Windows Community Toolkit Labs Team Date: April 8, 2022 From acc45f7b174e94fa46245b20ac4784ea72be4f1a Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Fri, 2 Aug 2024 16:15:03 -0500 Subject: [PATCH 8/8] Disable consolelogger, add tracking issue --- GenerateAllSolution.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/GenerateAllSolution.ps1 b/GenerateAllSolution.ps1 index f4282943..1ef1efac 100644 --- a/GenerateAllSolution.ps1 +++ b/GenerateAllSolution.ps1 @@ -142,7 +142,9 @@ if ($UseDiagnostics.IsPresent) $sdkoptions = "-d" $diagnostics = @( '-bl:slngen.binlog' - '--consolelogger:ShowEventId;Summary;Verbosity=Detailed' + # Console logger + binlog causes exception and failure + # Track https://github.com/microsoft/slngen/issues/451 + #'--consolelogger:ShowEventId;Summary;Verbosity=Detailed' ) } else