Skip to content

Commit eacd5c1

Browse files
authored
Merge branch 'main' into niels9001/gallery-tweaks
2 parents 466faa9 + b920000 commit eacd5c1

22 files changed

+415
-120
lines changed

.github/workflows/config/nuget.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<packageSources>
33
<clear />
44
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
5-
<add key="MainLatest" value="https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-MainLatest/nuget/v3/index.json" protocolVersion="3" />
65
</packageSources>
76
<disabledPackageSources>
87
<clear />

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
}

Build-Toolkit-Docs.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function ProcessMarkdownFile($markdownFile) {
3737

3838
# Insert Header
3939
$contents = $contents.Substring(0, $endIndex + 5) + "`n# $header`n" + $contents.Substring($endIndex + 5)
40-
40+
4141
# Find Sample Placeholders, replace with code content
4242
foreach ($sample in ($contents | Select-String -Pattern '>\s*\[!SAMPLE\s*(?<sampleid>.*)\s*\]\s*' -AllMatches).Matches) {
4343
$sampleid = $sample.Groups[1].Value
@@ -47,8 +47,8 @@ function ProcessMarkdownFile($markdownFile) {
4747
foreach ($csFile in Get-ChildItem -Recurse -Path ($markdownFile.DirectoryName + '\**\*.xaml.cs').Replace('\', '/') |
4848
Where-Object { $_.FullName -notlike "*\bin\*" -and $_FullName -notlike "*\obj\*" }) {
4949
$csSample = Get-Content $csFile -Raw
50-
51-
if ($csSample -match '\[ToolkitSample\s?\(\s*id:\s*(?:"|nameof\()\s?' + $sampleid + '\s?(?:"|\))') {
50+
51+
if ($csSample -match '\[ToolkitSample\s?\(\s*(?:id\:)?\s*(?:"|nameof\()\s?' + $sampleid + '\s?(?:"|\))') {
5252
# Get Relative Path
5353
$docPath = $(Join-Path "components" $($csfile.FullName.Replace($componentsRoot.Path, ''))).Replace('\', '/').Trim('/')
5454

CommunityToolkit.App.Shared/Renderers/ToolkitDocumentationRenderer.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
1+
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
22
<Page x:Class="CommunityToolkit.App.Shared.Renderers.ToolkitDocumentationRenderer"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@@ -230,7 +230,7 @@
230230
</StackPanel>
231231
<interactivity:Interaction.Behaviors>
232232
<interactivity:EventTriggerBehavior EventName="Click">
233-
<behaviors:NavigateToUriAction NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToComponentUri(Metadata.ComponentName), Mode=OneWay}" />
233+
<behaviors:NavigateToUriAction NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToComponentUri(Metadata.ComponentName, Metadata.IsExperimental), Mode=OneWay}" />
234234
</interactivity:EventTriggerBehavior>
235235
</interactivity:Interaction.Behaviors>
236236
</Button>
@@ -258,16 +258,16 @@
258258
Text="NuGet package" />
259259
<TextBlock IsTextSelectionEnabled="True">
260260
<Hyperlink FontFamily="Consolas"
261-
NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToPackageUri('Uwp', Metadata.CsProjName), Mode=OneWay}"
261+
NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToPackageUri('Uwp', Metadata.CsProjName, Metadata.IsExperimental), Mode=OneWay}"
262262
TextDecorations="None">
263-
<Run Text="{x:Bind renderer:ToolkitDocumentationRenderer.ToPackageName('Uwp', Metadata.CsProjName), Mode=OneWay}" />
263+
<Run Text="{x:Bind renderer:ToolkitDocumentationRenderer.ToPackageName('Uwp', Metadata.CsProjName, Metadata.IsExperimental), Mode=OneWay}" />
264264
</Hyperlink>
265265
</TextBlock>
266266
<TextBlock IsTextSelectionEnabled="True">
267267
<Hyperlink FontFamily="Consolas"
268-
NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToPackageUri('WinUI', Metadata.CsProjName), Mode=OneWay}"
268+
NavigateUri="{x:Bind renderer:ToolkitDocumentationRenderer.ToPackageUri('WinUI', Metadata.CsProjName, Metadata.IsExperimental), Mode=OneWay}"
269269
TextDecorations="None">
270-
<Run Text="{x:Bind renderer:ToolkitDocumentationRenderer.ToPackageName('WinUI', Metadata.CsProjName), Mode=OneWay}" />
270+
<Run Text="{x:Bind renderer:ToolkitDocumentationRenderer.ToPackageName('WinUI', Metadata.CsProjName, Metadata.IsExperimental), Mode=OneWay}" />
271271
</Hyperlink>
272272
</TextBlock>
273273
</StackPanel>

CommunityToolkit.App.Shared/Renderers/ToolkitDocumentationRenderer.xaml.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,35 @@ private async void MarkdownTextBlock_LinkClicked(object sender, LinkClickedEvent
216216

217217
public static Uri? ToGitHubUri(string path, int id) => IsProjectPathValid() ? new Uri($"{ProjectUrl}/{path}/{id}") : null;
218218

219-
public static Uri? ToComponentUri(string name) => IsProjectPathValid() ? new Uri($"{ProjectUrl}/tree/main/components/{name}") : null;
219+
public static Uri? ToComponentUri(string name, bool? isExperimental = null)
220+
{
221+
if (IsProjectPathValid() is not true)
222+
{
223+
return null;
224+
}
220225

221-
public static Uri? ToPackageUri(string platform, string projectFileName) => new Uri($"https://www.nuget.org/packages/{RemoveFileExtension(projectFileName).Replace("WinUI", platform)}");
226+
string? url = (isExperimental is null || isExperimental is false)
227+
? ProjectUrl
228+
: ProjectUrl?.Replace("Windows", "Labs-Windows");
222229

223-
public static string ToPackageName(string platform, string projectFileName) => RemoveFileExtension(projectFileName).Replace("WinUI", platform);
230+
return new Uri($"{url}/tree/main/components/{name}");
231+
}
232+
233+
public static Uri? ToPackageUri(string platform, string projectFileName, bool? isExperimental = null)
234+
{
235+
if (isExperimental is null || isExperimental is false)
236+
{
237+
return new Uri($"https://www.nuget.org/packages/{ToPackageName(platform, projectFileName, isExperimental)}");
238+
}
239+
else
240+
{
241+
// Labs feed for experimental packages (currently)
242+
// See inconsistency for Labs package names/project names https://github.com/CommunityToolkit/Windows/issues/587#issuecomment-2738529086
243+
return new Uri($"https://dev.azure.com/dotnet/CommunityToolkit/_artifacts/feed/CommunityToolkit-Labs/NuGet/{ToPackageName(platform, projectFileName, isExperimental)}");
244+
}
245+
}
246+
247+
public static string ToPackageName(string platform, string projectFileName, bool? isExperimental) => RemoveFileExtension(projectFileName).Replace("CommunityToolkit.WinUI", isExperimental == true ? "CommunityToolkit.Labs.WinUI" : "CommunityToolkit.WinUI").Replace("WinUI", platform);
224248

225249
// TODO: Think this is most of the special cases with Controls and the Extensions/Triggers using the base namespace
226250
// See: https://github.com/CommunityToolkit/Tooling-Windows-Submodule/issues/105#issuecomment-1698306420

GenerateAllSolution.ps1

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
.PARAMETER UseDiagnostics
2727
Add extra diagnostic output to running slngen, such as a binlog, etc...
2828
29+
.PARAMETER Launch
30+
Specifies whether to launch the solution after generation. Default is $true.
31+
2932
.EXAMPLE
3033
C:\PS> .\GenerateAllSolution -MultiTargets wasdk
3134
Build a solution that doesn't contain UWP projects.
@@ -50,7 +53,9 @@ Param (
5053

5154
[string[]]$ExcludeComponents,
5255

53-
[switch]$UseDiagnostics = $false
56+
[switch]$UseDiagnostics = $false,
57+
58+
[bool]$Launch = $true
5459
)
5560

5661
if ($MultiTargets.Contains('all')) {
@@ -111,28 +116,14 @@ $projects = [System.Collections.ArrayList]::new()
111116
# Common/Dependencies for shared infrastructure
112117
[void]$projects.Add(".\tooling\CommunityToolkit*\*.*proj")
113118

114-
# Deployable sample gallery heads
115-
# TODO: this handles separate project heads, but won't directly handle the unified Skia head from Uno.
116-
# Once we have that, just do a transform on the csproj filename inside this loop to decide the same csproj for those separate MultiTargets.
117-
foreach ($multitarget in $MultiTargets) {
118-
# capitalize first letter, avoid case sensitivity issues on linux
119-
$csprojFileNamePartForMultiTarget = $multitarget.substring(0,1).ToUpper() + $multitarget.Substring(1).ToLower()
120-
121-
$path = ".\tooling\ProjectHeads\AllComponents\**\*.$csprojFileNamePartForMultiTarget.csproj";
122-
123-
if (Test-Path $path) {
124-
[void]$projects.Add($path)
125-
}
126-
else {
127-
Write-Warning "No project head could be found at $path for MultiTarget $multitarget. Skipping."
128-
}
129-
}
130-
131119
# Individual projects
132120
if ($Components -eq @('all')) {
133121
$Components = @('**')
134122
}
135123

124+
125+
$allUsedMultiTargetPrefs = @()
126+
136127
foreach ($componentName in $Components) {
137128
if ($ExcludeComponents -contains $componentName) {
138129
continue;
@@ -141,20 +132,42 @@ foreach ($componentName in $Components) {
141132
foreach ($componentPath in Get-Item "$PSScriptRoot/../components/$componentName/") {
142133
$multiTargetPrefs = & $PSScriptRoot\MultiTarget\Get-MultiTargets.ps1 -component $($componentPath.BaseName)
143134

144-
$shouldReferenceInSolution = $multiTargetPrefs.Where({ $MultiTargets.Contains($_) }).Count -gt 0
145-
135+
$usedMultiTargetPrefs = $multiTargetPrefs.Where({ $MultiTargets.Contains($_) });
136+
$shouldReferenceInSolution = $usedMultiTargetPrefs.Count -gt 0
137+
146138
if ($shouldReferenceInSolution) {
147139
Write-Output "Add component $componentPath to solution";
148-
140+
$allUsedMultiTargetPrefs += $usedMultiTargetPrefs
141+
149142
[void]$projects.Add(".\components\$($componentPath.BaseName)\src\*.csproj")
150143
[void]$projects.Add(".\components\$($componentPath.BaseName)\samples\*.Samples.csproj")
151-
[void]$projects.Add(".\components\$($componentPath.BaseName)\tests\*.Tests\*.shproj")
144+
[void]$projects.Add(".\components\$($componentPath.BaseName)\tests\*.shproj")
152145
} else {
153146
Write-Warning "Component $($componentPath.BaseName) doesn't MultiTarget any of $MultiTargets and won't be added to the solution.";
154147
}
155148
}
156149
}
157150

151+
# Deployable sample gallery heads
152+
# Only include heads for requested MultiTargets if components were included that use them.
153+
# ===
154+
# TODO: this handles separate project heads, but won't directly handle the unified Skia head from Uno.
155+
# Once we have that, just do a transform on the csproj filename inside this loop to decide the same csproj for those separate MultiTargets.
156+
# ===
157+
foreach ($multitarget in $allUsedMultiTargetPrefs) {
158+
# capitalize first letter, avoid case sensitivity issues on linux
159+
$csprojFileNamePartForMultiTarget = $multitarget.substring(0,1).ToUpper() + $multitarget.Substring(1).ToLower()
160+
161+
$path = ".\tooling\ProjectHeads\AllComponents\**\*.$csprojFileNamePartForMultiTarget.csproj";
162+
163+
if (Test-Path $path) {
164+
[void]$projects.Add($path)
165+
}
166+
else {
167+
Write-Warning "No project head could be found at $path for MultiTarget $multitarget. Skipping."
168+
}
169+
}
170+
158171
if ($UseDiagnostics.IsPresent)
159172
{
160173
$sdkoptions = "-d"
@@ -187,6 +200,7 @@ $arguments = @(
187200
'--platform'
188201
$platforms
189202
$projects
203+
"--launch $launch"
190204
)
191205

192206
&$cmd @arguments

Get-Changed-Components.ps1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<#
2+
.PARAMETER FromSha
3+
The SHA of the commit to start the diff from. This is typically the SHA of the main branch.
4+
The default value is 'origin/main'.
5+
6+
.PARAMETER ToSha
7+
The SHA of the commit to end the diff at. This is typically the SHA of the current commit.
8+
If not provided, the script will use the current commit SHA.
9+
10+
.EXAMPLE
11+
Get-Changed-Components.ps1 -FromSha 'origin/main' -ToSha $(git rev-parse HEAD)
12+
13+
Get-Changed-Components.ps1 -t $(git rev-parse HEAD)
14+
15+
Gets the components that have been changed in a specific patch range, defined by -FromSha and -ToSha parameters.
16+
17+
.NOTES
18+
Author: Arlo Godfrey
19+
Date: 2/19/2024
20+
#>
21+
Param (
22+
[Alias("f")]
23+
[string]$FromSha = 'origin/main',
24+
25+
[Alias("t")]
26+
[string]$ToSha
27+
)
28+
29+
if (-not $ToSha) {
30+
$ToSha = $(git rev-parse HEAD)
31+
}
32+
33+
# Ensure that orphaned commits are available for diffing (e.g. when force-pushed).
34+
git fetch origin $FromSha
35+
git fetch origin main
36+
37+
$changedComponentFiles = Invoke-Expression "git diff --name-only $($FromSha)...$($ToSha) -- components/" -ErrorAction Stop
38+
$otherChanges = Invoke-Expression "git diff --name-only $($FromSha)...$($ToSha) | Select-String -NotMatch '^components/'" -ErrorAction Stop
39+
40+
# If one or more components is changed, return them in a list.
41+
$retChangedComponents = -not [string]::IsNullOrWhiteSpace($changedComponentFiles);
42+
43+
# Return 'all' components when either:
44+
# - One or more files *outside* of a component folder is changed
45+
# - All files *inside* of component folders are unchanged
46+
# Both of these:
47+
# - Can happen when any non-component file is changed
48+
# - May indicate (but not guarantee) a build configuration change.
49+
# - Are a fallback to ensure that the script doesn't return an empty list of components.
50+
$retAllComponents = [string]::IsNullOrWhiteSpace($changedComponentFiles) -or -not [string]::IsNullOrWhiteSpace($otherChanges);
51+
52+
if ($retAllComponents) {
53+
return 'all';
54+
}
55+
56+
if ($retChangedComponents) {
57+
$names = $changedComponentFiles | ForEach-Object { ($_ -replace '^components/', '') -replace '/.*$', '' }
58+
$uniqueNames = $names | Sort-Object -Unique
59+
$changedComponentsList = $uniqueNames -join ','
60+
return $changedComponentsList
61+
}
62+
63+
Write-Error "Unhandled code path."
64+
Write-Error "Please report this error to the author of this script."

MultiTarget/EnabledMultiTargets.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<!--Indicates which MultiTargets are enabled via UseTargetFrameworks script. -->
33
<!-- Do not commit changes made to default values by tooling. -->
44
<PropertyGroup>
5-
<EnabledMultiTargets>wasm;uwp;netstandard;</EnabledMultiTargets>
5+
<EnabledMultiTargets>wasm;wasdk;</EnabledMultiTargets>
66
</PropertyGroup>
77
</Project>

0 commit comments

Comments
 (0)