Skip to content

Commit

Permalink
Align single-component sln generation script with capabilities of gal…
Browse files Browse the repository at this point in the history
…lery sln generation script
  • Loading branch information
Arlodotexe committed Dec 5, 2024
1 parent 43e41c2 commit fd230f0
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 19 deletions.
122 changes: 103 additions & 19 deletions ProjectHeads/GenerateSingleSampleHeads.ps1
Original file line number Diff line number Diff line change
@@ -1,30 +1,48 @@
<#
.SYNOPSIS
Uses the dotnet template tool to copy and rename project heads to run sample code for different platforms.
.DESCRIPTION
This is used to centralize configuration and reduce duplication of copying these heads for every project.
This script also generates a solution for the project and will open Visual Studio.
.PARAMETER componentPath
Folder for the project to copy the project heads to.
.PARAMETER heads
Which heads to include to copy, defaults to all. (Currently ignored.)
.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 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...
.EXAMPLE
C:\PS> .\GenerateSingleSampleHeads -componentPath components\testproj
Builds project heads for component in testproj directory.
.NOTES
Author: Windows Community Toolkit Labs Team
Date: Feb 9, 2023
#>
Param (
[ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')]
[Alias("mt")]
[string[]]$MultiTargets = @('uwp', 'wasm', 'wasdk'),

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

[Alias("winui")]
[int]$WinUIMajorVersion = 2,

[Parameter(HelpMessage = "The path to the containing folder for a component where sample heads should be generated.")]
[string]$componentPath,

[Parameter(HelpMessage = "The heads that should be generated. If excluded, all heads will be generated. (Currently Ignored)")]
[string[]]$heads = @("uwp", "wasm", "winappsdk", "tests.uwp", "tests.winappsdk"),

[Parameter(HelpMessage = "Add extra diagnostic output to slngen generator.")]
[switch]$UseDiagnostics = $false
)
Expand All @@ -39,11 +57,55 @@ if ($null -ne $Env:Path -and $Env:Path.ToLower().Contains("msbuild") -eq $false)
Exit
}

# If componentPath is not provided or is an empty string, use the $PSScriptRoot
if ($null -eq $componentPath -or $componentPath -eq '')
{
$componentPath = $pwd
}

# Multitarget handling
# -----------------

if ($MultiTargets.Contains('all')) {
$MultiTargets = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')
}

if ($null -eq $ExcludeMultiTargets)
{
$ExcludeMultiTargets = @()
}

# Both uwp and wasdk share a targetframework. Both cannot be enabled at once.
# If both are supplied, remove one based on WinUIMajorVersion.
if ($MultiTargets.Contains('uwp') -and $MultiTargets.Contains('wasdk'))
{
if ($WinUIMajorVersion -eq 2)
{
$ExcludeMultiTargets = $ExcludeMultiTargets + 'wasdk'
}
else
{
$ExcludeMultiTargets = $ExcludeMultiTargets + 'uwp'
}
}

$MultiTargets = $MultiTargets | Where-Object { $_ -notin $ExcludeMultiTargets }
$ExcludeMultiTargets = $ExcludeMultiTargets | Where-Object { $_ -notin $MultiTargets }

# Generate required props for preferences
& $PSScriptRoot/../MultiTarget/UseTargetFrameworks.ps1 -MultiTargets $MultiTargets
& $PSScriptRoot/../MultiTarget/UseUnoWinUI.ps1 $WinUIMajorVersion

# Head generation
# -----------------

$headsFolderName = "heads"
$componentName = (Get-Item $componentPath -ErrorAction Stop).Name

$outputHeadsDir = "$componentPath/$headsFolderName";

# Remove existing heads directory to refresh
Remove-Item -Recurse -Force "$componentPath/$headsFolderName/" -ErrorAction SilentlyContinue;
Remove-Item -Recurse -Force $outputHeadsDir -ErrorAction SilentlyContinue;

# Intall our heads as a temporary template
dotnet new --install "$PSScriptRoot/SingleComponent" --force
Expand All @@ -58,9 +120,14 @@ dotnet new ct-tooling-heads -n $componentName -o $headsFolderName
# Remove template, as just for script
dotnet new --uninstall "$PSScriptRoot/SingleComponent"


# Generate Solution
#------------------
# ------------------

# Projects to include
$projects = [System.Collections.ArrayList]::new()

# Include all projects in component folder
[void]$projects.Add(".\*\*.*proj")

# Install slgnen
dotnet tool restore
Expand All @@ -76,18 +143,35 @@ if (Test-Path -Path $generatedSolutionFilePath)
Write-Host "Removed previous solution file"
}

# Projects to include
$projects = [System.Collections.ArrayList]::new()

# Include all projects in component folder
[void]$projects.Add(".\**.*proj")
# Deployable sample gallery heads
# All heads are included by default since they reside in the same folder as the component.
# Remove any heads that are not required for the solution.
# 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 $MultiTargets) {
# capitalize first letter, avoid case sensitivity issues on linux
$csprojFileNamePartForMultiTarget = $multitarget.substring(0,1).ToUpper() + $multitarget.Substring(1).ToLower()

$path = "$outputHeadsDir\**\*$csprojFileNamePartForMultiTarget.csproj";

if (Test-Path $path) {
# iterate the wildcards caught by $path
foreach ($foundItem in Get-ChildItem $path)
{
$projects = $projects + $foundItem.FullName
}
}
else {
Write-Warning "No project head could be found at $path for MultiTarget $multitarget. Skipping."
}
}

# Include common dependencies required for solution to build
[void]$projects.Add("..\..\tooling\CommunityToolkit.App.Shared\**\*.*proj")
[void]$projects.Add("..\..\tooling\CommunityToolkit.Tests.Shared\**\*.*proj")
[void]$projects.Add("..\..\tooling\CommunityToolkit.Tooling.SampleGen\*.csproj")
[void]$projects.Add("..\..\tooling\CommunityToolkit.Tooling.TestGen\*.csproj")
[void]$projects.Add("..\..\tooling\CommunityToolkit.Tooling.XamlNamedPropertyRelay\*.csproj")
$projects = $projects + "..\..\tooling\CommunityToolkit.App.Shared\**\*.*proj"
$projects = $projects + "..\..\tooling\CommunityToolkit.Tests.Shared\**\*.*proj"
$projects = $projects + "..\..\tooling\CommunityToolkit.Tooling.SampleGen\*.csproj"
$projects = $projects + "..\..\tooling\CommunityToolkit.Tooling.TestGen\*.csproj"
$projects = $projects + "..\..\tooling\CommunityToolkit.Tooling.XamlNamedPropertyRelay\*.csproj"

if ($UseDiagnostics.IsPresent)
{
Expand Down

0 comments on commit fd230f0

Please sign in to comment.