Skip to content

Commit d934190

Browse files
committed
Moved single-component slngen script to root of tooling alongside all-component slngen script.
The original script was replaced with a wrapped call to the new script location to allow for gradual upstream updates.
1 parent 94888f1 commit d934190

File tree

2 files changed

+228
-144
lines changed

2 files changed

+228
-144
lines changed

GenerateSingleSolution.ps1

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
<#
2+
.SYNOPSIS
3+
Uses the dotnet template tool to copy and rename project heads to run sample code for different platforms.
4+
5+
.DESCRIPTION
6+
This is used to centralize configuration and reduce duplication of copying these heads for every project.
7+
This script also generates a solution for the project and will open Visual Studio.
8+
9+
.PARAMETER componentPath
10+
Folder for the project to copy the project heads to.
11+
12+
.PARAMETER MultiTargets
13+
Specifies the MultiTarget TFM(s) to include for building the components. The default value is 'uwp', 'wasm', 'wasdk'.
14+
15+
.PARAMETER ExcludeMultiTargets
16+
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.
17+
18+
.PARAMETER Component
19+
The name of the components to generate project and solution references for. Defaults to an empty string.
20+
21+
.PARAMETER WinUIMajorVersion
22+
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'.
23+
24+
.PARAMETER UseDiagnostics
25+
Add extra diagnostic output to running slngen, such as a binlog, etc...
26+
27+
.EXAMPLE
28+
C:\PS> .\GenerateSingleSampleHeads -componentPath components\testproj
29+
Builds project heads for component in testproj directory.
30+
31+
.NOTES
32+
Author: Windows Community Toolkit Labs Team
33+
Date: Feb 9, 2023
34+
#>
35+
Param (
36+
[ValidateSet('all', 'wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')]
37+
[Alias("mt")]
38+
[string[]]$MultiTargets = @('uwp', 'wasm', 'wasdk'),
39+
40+
[string[]]$ExcludeMultiTargets,
41+
42+
[Alias("winui")]
43+
[int]$WinUIMajorVersion = 3,
44+
45+
[Alias("c")]
46+
[string]$Component = "",
47+
48+
[Parameter(HelpMessage = "The path to the containing folder for a component where sample heads should be generated.")]
49+
[string]$componentPath,
50+
51+
[Parameter(HelpMessage = "Add extra diagnostic output to slngen generator.")]
52+
[switch]$UseDiagnostics = $false
53+
)
54+
55+
if ($null -ne $Env:Path -and $Env:Path.ToLower().Contains("msbuild") -eq $false) {
56+
Write-Host
57+
Write-Host -ForegroundColor Red "Please run from a command window that has MSBuild.exe on the PATH"
58+
Write-Host
59+
Write-Host "Press any key to continue"
60+
[void]$host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
61+
62+
Exit
63+
}
64+
65+
# If Component (name) is provided, use a known path to find componentPath
66+
if ($null -ne $Component -and $Component -ne '')
67+
{
68+
$componentPath = Get-Item "$PSScriptRoot/../components/$Component/"
69+
}
70+
71+
# If componentPath is not provided or is an empty string, use the current directory $pwd
72+
if ($null -eq $componentPath -or $componentPath -eq '')
73+
{
74+
$componentPath = $pwd
75+
}
76+
77+
# Component check
78+
# -----------------
79+
80+
# Check that the component path exists
81+
if (-not (Test-Path $componentPath -PathType Container))
82+
{
83+
Write-Error "Component path '$componentPath' does not exist."
84+
Exit
85+
}
86+
87+
# Check that the path contains a src folder
88+
if (-not (Test-Path "$componentPath/src" -PathType Container))
89+
{
90+
Write-Error "Provided path '$componentPath' does not contain a 'src' folder and may not be a component."
91+
Exit
92+
}
93+
94+
# Multitarget handling
95+
# -----------------
96+
97+
if ($MultiTargets.Contains('all')) {
98+
$MultiTargets = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')
99+
}
100+
101+
if ($null -eq $ExcludeMultiTargets)
102+
{
103+
$ExcludeMultiTargets = @()
104+
}
105+
106+
# Both uwp and wasdk share a targetframework. Both cannot be enabled at once.
107+
# If both are supplied, remove one based on WinUIMajorVersion.
108+
if ($MultiTargets.Contains('uwp') -and $MultiTargets.Contains('wasdk'))
109+
{
110+
if ($WinUIMajorVersion -eq 2)
111+
{
112+
$ExcludeMultiTargets = $ExcludeMultiTargets + 'wasdk'
113+
}
114+
else
115+
{
116+
$ExcludeMultiTargets = $ExcludeMultiTargets + 'uwp'
117+
}
118+
}
119+
120+
$MultiTargets = $MultiTargets | Where-Object { $_ -notin $ExcludeMultiTargets }
121+
122+
# Generate required props for preferences
123+
& $PSScriptRoot/MultiTarget/UseTargetFrameworks.ps1 -MultiTargets $MultiTargets
124+
& $PSScriptRoot/MultiTarget/UseUnoWinUI.ps1 $WinUIMajorVersion
125+
126+
# Head generation
127+
# -----------------
128+
129+
$headsFolderName = "heads"
130+
$componentName = (Get-Item $componentPath -ErrorAction Stop).Name
131+
132+
$outputHeadsDir = Get-Item "$componentPath\$headsFolderName";
133+
134+
# Remove existing heads directory to refresh
135+
Write-Output "Removing existing heads directory: $outputHeadsDir"
136+
Remove-Item -Recurse -Force $outputHeadsDir -ErrorAction SilentlyContinue;
137+
138+
# Intall our heads as a temporary template
139+
Write-Output "Installing SingleComponent template"
140+
dotnet new --install "$PSScriptRoot/ProjectHeads/SingleComponent" --force
141+
142+
# We need to copy files and run slngen from the target directory path
143+
Push-Location $componentPath
144+
145+
# Copy and rename projects
146+
# Set output folder to 'heads' instead of default
147+
Write-Output "Generating heads for $componentName in $outputHeadsDir"
148+
dotnet new ct-tooling-heads -n $componentName -o $headsFolderName
149+
150+
# Remove template, as just for script
151+
Write-Output "Uninstalling SingleComponent template"
152+
dotnet new --uninstall "$PSScriptRoot/ProjectHeads/SingleComponent"
153+
154+
# Generate Solution
155+
# ------------------
156+
157+
# Projects to include
158+
$projects = [System.Collections.ArrayList]::new()
159+
160+
# Include all projects in component folder
161+
[void]$projects.Add(".\*\*.*proj")
162+
163+
# Install slgnen
164+
dotnet tool restore
165+
166+
$generatedSolutionFilePath = "$componentPath/$componentName.sln"
167+
$platforms = '"Any CPU;x64;x86;ARM64"'
168+
$slngenConfig = "--folders true --collapsefolders true --ignoreMainProject"
169+
170+
# Remove previous file if it exists
171+
if (Test-Path -Path $generatedSolutionFilePath)
172+
{
173+
Remove-Item $generatedSolutionFilePath
174+
Write-Host "Removed previous solution file"
175+
}
176+
177+
# Deployable sample gallery heads
178+
Write-Output "Generating solution for $componentName in $generatedSolutionFilePath"
179+
180+
# All heads are included by default since they reside in the same folder as the component.
181+
# Remove any heads that are not required for the solution.
182+
# TODO: this handles separate project heads, but won't directly handle the unified Skia head from Uno.
183+
# Once we have that, just do a transform on the csproj filename inside this loop to decide the same csproj for those separate MultiTargets.
184+
foreach ($multitarget in $MultiTargets) {
185+
# capitalize first letter, avoid case sensitivity issues on linux
186+
$csprojFileNamePartForMultiTarget = $multitarget.substring(0,1).ToUpper() + $multitarget.Substring(1).ToLower()
187+
188+
$path = "$outputHeadsDir\**\*$csprojFileNamePartForMultiTarget.csproj";
189+
190+
if (Test-Path $path) {
191+
# iterate the wildcards caught by $path
192+
foreach ($foundItem in Get-ChildItem $path)
193+
{
194+
$projects = $projects + $foundItem.FullName
195+
}
196+
}
197+
else {
198+
Write-Warning "No project head could be found at $path for MultiTarget $multitarget. Skipping."
199+
}
200+
}
201+
202+
# Include common dependencies required for solution to build
203+
$projects = $projects + "$PSScriptRoot\CommunityToolkit.App.Shared\**\*.*proj"
204+
$projects = $projects + "$PSScriptRoot\CommunityToolkit.Tests.Shared\**\*.*proj"
205+
$projects = $projects + "$PSScriptRoot\CommunityToolkit.Tooling.SampleGen\*.csproj"
206+
$projects = $projects + "$PSScriptRoot\CommunityToolkit.Tooling.TestGen\*.csproj"
207+
$projects = $projects + "$PSScriptRoot\CommunityToolkit.Tooling.XamlNamedPropertyRelay\*.csproj"
208+
209+
if ($UseDiagnostics.IsPresent)
210+
{
211+
$sdkoptions = " -d"
212+
$diagnostics = '-bl:slngen.binlog --consolelogger:"ShowEventId;Summary;Verbosity=Detailed" --filelogger:"LogFile=slngen.log;Append;Verbosity=Diagnostic;Encoding=UTF-8" '
213+
}
214+
else
215+
{
216+
$sdkoptions = ""
217+
$diagnostics = ""
218+
}
219+
220+
$cmd = "dotnet$sdkoptions tool run slngen -o $generatedSolutionFilePath $slngenConfig $diagnostics--platform $platforms $($projects -Join ' ')"
221+
222+
Write-Output "Running Command: $cmd"
223+
224+
Invoke-Expression $cmd
225+
226+
# go back to main working directory
227+
Pop-Location

ProjectHeads/GenerateSingleSampleHeads.ps1

Lines changed: 1 addition & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -46,147 +46,4 @@ Param (
4646
[switch]$UseDiagnostics = $false
4747
)
4848

49-
if ($null -ne $Env:Path -and $Env:Path.ToLower().Contains("msbuild") -eq $false) {
50-
Write-Host
51-
Write-Host -ForegroundColor Red "Please run from a command window that has MSBuild.exe on the PATH"
52-
Write-Host
53-
Write-Host "Press any key to continue"
54-
[void]$host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
55-
56-
Exit
57-
}
58-
59-
# If componentPath is not provided or is an empty string, use the $PSScriptRoot
60-
if ($null -eq $componentPath -or $componentPath -eq '')
61-
{
62-
$componentPath = $pwd
63-
}
64-
65-
# Multitarget handling
66-
# -----------------
67-
68-
if ($MultiTargets.Contains('all')) {
69-
$MultiTargets = @('wasm', 'uwp', 'wasdk', 'wpf', 'linuxgtk', 'macos', 'ios', 'android')
70-
}
71-
72-
if ($null -eq $ExcludeMultiTargets)
73-
{
74-
$ExcludeMultiTargets = @()
75-
}
76-
77-
# Both uwp and wasdk share a targetframework. Both cannot be enabled at once.
78-
# If both are supplied, remove one based on WinUIMajorVersion.
79-
if ($MultiTargets.Contains('uwp') -and $MultiTargets.Contains('wasdk'))
80-
{
81-
if ($WinUIMajorVersion -eq 2)
82-
{
83-
$ExcludeMultiTargets = $ExcludeMultiTargets + 'wasdk'
84-
}
85-
else
86-
{
87-
$ExcludeMultiTargets = $ExcludeMultiTargets + 'uwp'
88-
}
89-
}
90-
91-
$MultiTargets = $MultiTargets | Where-Object { $_ -notin $ExcludeMultiTargets }
92-
93-
# Generate required props for preferences
94-
& $PSScriptRoot/../MultiTarget/UseTargetFrameworks.ps1 -MultiTargets $MultiTargets
95-
& $PSScriptRoot/../MultiTarget/UseUnoWinUI.ps1 $WinUIMajorVersion
96-
97-
# Head generation
98-
# -----------------
99-
100-
$headsFolderName = "heads"
101-
$componentName = (Get-Item $componentPath -ErrorAction Stop).Name
102-
103-
$outputHeadsDir = "$componentPath/$headsFolderName";
104-
105-
# Remove existing heads directory to refresh
106-
Remove-Item -Recurse -Force $outputHeadsDir -ErrorAction SilentlyContinue;
107-
108-
# Intall our heads as a temporary template
109-
dotnet new --install "$PSScriptRoot/SingleComponent" --force
110-
111-
# We need to copy files and run slngen from the target directory path
112-
Push-Location $componentPath
113-
114-
# Copy and rename projects
115-
# Set output folder to 'heads' instead of default
116-
dotnet new ct-tooling-heads -n $componentName -o $headsFolderName
117-
118-
# Remove template, as just for script
119-
dotnet new --uninstall "$PSScriptRoot/SingleComponent"
120-
121-
# Generate Solution
122-
# ------------------
123-
124-
# Projects to include
125-
$projects = [System.Collections.ArrayList]::new()
126-
127-
# Include all projects in component folder
128-
[void]$projects.Add(".\*\*.*proj")
129-
130-
# Install slgnen
131-
dotnet tool restore
132-
133-
$generatedSolutionFilePath = "$componentPath/$componentName.sln"
134-
$platforms = '"Any CPU;x64;x86;ARM64"'
135-
$slngenConfig = "--folders true --collapsefolders true --ignoreMainProject"
136-
137-
# Remove previous file if it exists
138-
if (Test-Path -Path $generatedSolutionFilePath)
139-
{
140-
Remove-Item $generatedSolutionFilePath
141-
Write-Host "Removed previous solution file"
142-
}
143-
144-
# Deployable sample gallery heads
145-
# All heads are included by default since they reside in the same folder as the component.
146-
# Remove any heads that are not required for the solution.
147-
# TODO: this handles separate project heads, but won't directly handle the unified Skia head from Uno.
148-
# Once we have that, just do a transform on the csproj filename inside this loop to decide the same csproj for those separate MultiTargets.
149-
foreach ($multitarget in $MultiTargets) {
150-
# capitalize first letter, avoid case sensitivity issues on linux
151-
$csprojFileNamePartForMultiTarget = $multitarget.substring(0,1).ToUpper() + $multitarget.Substring(1).ToLower()
152-
153-
$path = "$outputHeadsDir\**\*$csprojFileNamePartForMultiTarget.csproj";
154-
155-
if (Test-Path $path) {
156-
# iterate the wildcards caught by $path
157-
foreach ($foundItem in Get-ChildItem $path)
158-
{
159-
$projects = $projects + $foundItem.FullName
160-
}
161-
}
162-
else {
163-
Write-Warning "No project head could be found at $path for MultiTarget $multitarget. Skipping."
164-
}
165-
}
166-
167-
# Include common dependencies required for solution to build
168-
$projects = $projects + "..\..\tooling\CommunityToolkit.App.Shared\**\*.*proj"
169-
$projects = $projects + "..\..\tooling\CommunityToolkit.Tests.Shared\**\*.*proj"
170-
$projects = $projects + "..\..\tooling\CommunityToolkit.Tooling.SampleGen\*.csproj"
171-
$projects = $projects + "..\..\tooling\CommunityToolkit.Tooling.TestGen\*.csproj"
172-
$projects = $projects + "..\..\tooling\CommunityToolkit.Tooling.XamlNamedPropertyRelay\*.csproj"
173-
174-
if ($UseDiagnostics.IsPresent)
175-
{
176-
$sdkoptions = " -d"
177-
$diagnostics = '-bl:slngen.binlog --consolelogger:"ShowEventId;Summary;Verbosity=Detailed" --filelogger:"LogFile=slngen.log;Append;Verbosity=Diagnostic;Encoding=UTF-8" '
178-
}
179-
else
180-
{
181-
$sdkoptions = ""
182-
$diagnostics = ""
183-
}
184-
185-
$cmd = "dotnet$sdkoptions tool run slngen -o $generatedSolutionFilePath $slngenConfig $diagnostics--platform $platforms $($projects -Join ' ')"
186-
187-
Write-Output "Running Command: $cmd"
188-
189-
Invoke-Expression $cmd
190-
191-
# go back to main working directory
192-
Pop-Location
49+
& $PSScriptRoot/../GenerateSingleSolution.ps1 -MultiTargets $MultiTargets -ExcludeMultiTargets $ExcludeMultiTargets -WinUIMajorVersion $WinUIMajorVersion -UseDiagnostics $UseDiagnostics -componentPath $componentPath

0 commit comments

Comments
 (0)