Skip to content

Commit

Permalink
Merge branch 'main' into llama/transitionhelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlodotexe committed Mar 11, 2023
2 parents 072052c + 3bde759 commit f2dc018
Show file tree
Hide file tree
Showing 113 changed files with 3,143 additions and 558 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,6 @@ csharp_style_prefer_extended_property_pattern = true:suggestion

# Require file header
dotnet_diagnostic.IDE0073.severity = warning

# Uno platform exposes IDisposable on Storyboard publicly when it should be internal. Ignore this.
dotnet_code_quality.CA1001.excluded_type_names_with_derived_types = T:Windows.UI.Xaml.Media.Animation.Storyboard
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
"/p:UnoSourceGeneratorUseGenerationHost=true",
"/p:UnoSourceGeneratorUseGenerationController=false",
"/p:UnoRemoteControlPort=443",
"--project=${workspaceFolder}/common/ProjectHeads/AllComponents/CommunityToolkit.Labs.Wasm/CommunityToolkit.Labs.Wasm.csproj"
"--project=${workspaceFolder}/common/ProjectHeads/AllComponents/Wasm/CommunityToolkit.App.Wasm.csproj"
],
"presentation": {
"group": "1",
"order": 1
},
"cwd": "${workspaceFolder}/common/ProjectHeads/AllComponents/CommunityToolkit.Labs.Wasm",
"cwd": "${workspaceFolder}/common/ProjectHeads/AllComponents/Wasm",
"preLaunchTask": "generateAllSolution"
},
{
"type": "PowerShell",
"request": "launch",
"name": "Discover samples",
"script": "${workspaceFolder}/common/MultiTarget/GenerateAllProjectReferences.ps1; ${workspaceFolder}/common/GenerateVSCodeLaunchConfig.ps1; ",
"script": "foreach ($component in Get-ChildItem -Directory -Depth 0 -Path './components/*') { ${workspaceFolder}/common/ProjectHeads/GenerateSingleSampleHeads.ps1 -ComponentPath $component } ; ${workspaceFolder}/common/GenerateVSCodeLaunchConfig.ps1; ",
"presentation": {
"group": "2",
"order": 2
Expand Down
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project>
<PropertyGroup>
<PackageIdPrefix>CommunityToolkit.Labs</PackageIdPrefix>
<RepositoryDirectory>$(MSBuildThisFileDirectory)</RepositoryDirectory>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>
Expand Down
6 changes: 5 additions & 1 deletion common/CommunityToolkit.App.Shared/App.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- 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. -->
<!-- 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. -->
<Application x:Class="CommunityToolkit.App.Shared.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
Expand All @@ -23,6 +23,10 @@

<SolidColorBrush x:Key="BackgroundColorBrush"
Color="{ThemeResource SolidBackgroundFillColorBase}" />
<SolidColorBrush x:Key="WindowCaptionBackground"
Color="Transparent" />
<SolidColorBrush x:Key="WindowCaptionBackgroundDisabled"
Color="Transparent" />

<!-- PathData for the GitHub icon -->
<x:String x:Key="GithubIcon">M21.7999992370605,0L19.220495223999,0.26007080078125 16.81787109375,1.00595712661743 14.6436157226563,2.18616962432861 12.7492189407349,3.74921894073486 11.1861696243286,5.64361572265625 10.0059566497803,7.81787109375 9.26007080078125,10.2204961776733 9,12.8000001907349 9.65248012542725,16.8459720611572 11.4694375991821,20.3591785430908 14.2401514053345,23.1291217803955 17.7539005279541,24.9453010559082 18.4305686950684,24.8080005645752 18.6273498535156,24.3296756744385 18.6207065582275,23.4247951507568 18.609375,21.9468746185303 16.4340572357178,22.0373229980469 15.1187467575073,21.4822216033936 14.4708204269409,20.7821025848389 14.2976503372192,20.4375 13.8297338485718,19.5214366912842 13.3685493469238,18.947265625 12.8765497207642,18.5656261444092 12.3995819091797,18.1091804504395 12.4844465255737,17.87890625 12.7874250411987,17.7974605560303 12.9647998809814,17.7875003814697 13.8134965896606,18.0311241149902 14.4276065826416,18.4802703857422 14.8007507324219,18.9127178192139 14.926549911499,19.1062507629395 15.8880548477173,20.1437015533447 16.9443283081055,20.494140625 17.9229640960693,20.416259765625 18.6515502929688,20.1687507629395 18.9645938873291,19.1242198944092 19.4640502929688,18.4593753814697 17.3543262481689,18.0241260528564 15.4833002090454,17.014066696167 14.1450357437134,15.1450166702271 13.6336002349854,12.1328001022339 13.9853601455688,10.2268438339233 14.9500007629395,8.69764995574951 14.7027282714844,7.54188776016235 14.7441072463989,6.53565359115601 15.0765495300293,5.30859994888306 15.2825078964233,5.28076791763306 15.9191312789917,5.34375619888306 17.0145378112793,5.71729135513306 18.596851348877,6.62109994888306 21.799976348877,6.19062519073486 25.004674911499,6.62265014648438 26.5845413208008,5.71818733215332 27.6791000366211,5.34472513198853 28.315746307373,5.28210020065308 28.5218753814697,5.31015014648438 28.8556652069092,6.53784370422363 28.8976573944092,7.5438346862793 28.6499996185303,8.69764995574951 29.6154251098633,10.2268533706665 29.9656257629395,12.1328001022339 29.453296661377,15.1497011184692 28.1123065948486,17.0164012908936 26.2366523742676,18.020601272583 24.120325088501,18.4500007629395 24.7275562286377,19.3355484008789 24.9890747070313,20.8187503814697 24.9804744720459,23.0584030151367 24.9718742370605,24.3312511444092 25.1693305969238,24.8128852844238 25.8531246185303,24.9453010559082 29.3641395568848,23.1273632049561 32.1326217651367,20.3568344116211 33.948070526123,16.8442134857178 34.5999984741211,12.8000001907349 34.3399276733398,10.2204961776733 33.5940399169922,7.81787109375 32.4138298034668,5.64361572265625 30.8507804870605,3.74921894073486 28.9563827514648,2.18616962432861 26.7821273803711,1.00595712661743 24.3795032501221,0.26007080078125 21.7999992370605,0z</x:String>
Expand Down
1 change: 0 additions & 1 deletion common/GenerateAllSolution.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Param (

# Generate required props for "All" solution.
& ./common/MultiTarget/GenerateAllProjectReferences.ps1
& ./common/GenerateVSCodeLaunchConfig.ps1

# Set up constant values
$generatedSolutionFilePath = 'Toolkit.Labs.All.sln'
Expand Down
10 changes: 6 additions & 4 deletions common/GenerateVSCodeLaunchConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ function CreateVsCodeLaunchConfigJson {
`"/p:UnoSourceGeneratorUseGenerationHost=true`",
`"/p:UnoSourceGeneratorUseGenerationController=false`",
`"/p:UnoRemoteControlPort=443`",
`"--project=`$`{workspaceFolder`}/components/$projectName/samples/$projectName.Wasm/$projectName.Wasm.csproj`"
`"--project=`$`{workspaceFolder`}/components/$projectName/heads/Wasm/$projectName.Wasm.csproj`"
],
`"presentation`": {
`"group`": `"2`"
},
`"cwd`": `"`$`{workspaceFolder`}/components/$projectName/samples/$projectName.Wasm`"
`"cwd`": `"`$`{workspaceFolder`}/components/$projectName/heads/Wasm`"
}";
}

Expand All @@ -38,8 +38,10 @@ $launchConfig.configurations = @();
$launchConfig.configurations += $originalConfigurations[0];
$launchConfig.configurations += $originalConfigurations[1];

foreach ($wasmProjectPath in Get-ChildItem -Recurse -Path "$PSScriptRoot/../*/*/samples/*.Wasm/*.Wasm.csproj") {
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($wasmProjectPath) -Replace ".Wasm", "";
& $PSScriptRoot/MultiTarget/GenerateAllProjectReferences.ps1 -MultiTarget 'wasm'

foreach ($projectPath in Get-ChildItem -Directory -Depth 0 -Path "$PSScriptRoot/../components/*") {
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($projectPath);
Write-Host "Generating VSCode launch config for $projectName";

$configJson = CreateVsCodeLaunchConfigJson $projectName;
Expand Down
4 changes: 2 additions & 2 deletions common/GlobalUsings_WinUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

global using System.Runtime.InteropServices.WindowsRuntime;

global using CommunityToolkit.Labs.WinUI;

global using Windows.Foundation;
global using Windows.Foundation.Collections;

Expand All @@ -26,6 +24,7 @@
global using Windows.UI.Xaml.Input;
global using Windows.UI.Xaml.Markup;
global using Windows.UI.Xaml.Media;
global using Windows.UI.Xaml.Media.Animation;
global using Windows.UI.Xaml.Navigation;

#else
Expand All @@ -40,6 +39,7 @@
global using Microsoft.UI.Xaml.Input;
global using Microsoft.UI.Xaml.Markup;
global using Microsoft.UI.Xaml.Media;
global using Microsoft.UI.Xaml.Media.Animation;
global using Microsoft.UI.Xaml.Navigation;
#endif

Expand Down
26 changes: 6 additions & 20 deletions common/MultiTarget/GenerateAllProjectReferences.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Param (
[Parameter(HelpMessage = "The directory where props files for discovered projects should be saved.")]
[string]$projectPropsOutputDir = "$PSScriptRoot/Generated"
[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")
)

$preWorkingDir = $pwd;
Expand All @@ -12,35 +15,18 @@ New-Item -ItemType Directory -Force -Path $projectPropsOutputDir -ErrorAction Si

# Discover projects in provided paths
foreach ($projectPath in Get-ChildItem -Directory -Depth 0 -Path "$PSScriptRoot/../../components/*") {
# Normalize project path
$projectName = $projectPath.Name;

# Folder layout is expected to match the Community Toolkit.
# Uses the <MultiTarget> values from the source library project as the fallback for the sample project.
# This behavior also implemented in MultiTarget.props for TargetFramework evaluation.
$srcPath = Resolve-Path "$($projectPath.FullName)\src";
$srcProjectPath = Get-ChildItem -File "$srcPath\*.csproj";

$samplePath = Resolve-Path "$($projectPath.FullName)\samples";
$sampleProjectPath = Get-ChildItem -File "$samplePath\*.csproj";

if ($srcProjectPath.Length -eq 0) {
Write-Error "Could not locate source csproj for $projectName";
exit(-1);
}

if ($sampleProjectPath.Length -eq 0) {
Write-Error "Could not locate sample csproj for $projectName";
exit(-1);
}

# Generate <ProjectReference>s for sample project
# Use source project MultiTarget as first fallback.
& $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $sampleProjectPath -outputPath "$projectPropsOutputDir/$($sampleProjectPath.BaseName).props" -multiTargetFallbackPropsPath @("$srcPath/MultiTarget.props", "$samplePath/MultiTarget.props", "$PSScriptRoot/Defaults.props");
& $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $sampleProjectPath -outputPath "$projectPropsOutputDir/$($sampleProjectPath.BaseName).props" -MultiTarget $MultiTarget

# Generate <ProjectReference>s for src project
& $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $srcProjectPath -outputPath "$projectPropsOutputDir/$($srcProjectPath.BaseName).props" -multiTargetFallbackPropsPath @("$srcPath/MultiTarget.props", "$PSScriptRoot/Defaults.props");
& $PSScriptRoot\GenerateMultiTargetAwareProjectReferenceProps.ps1 -projectPath $srcProjectPath -outputPath "$projectPropsOutputDir/$($srcProjectPath.BaseName).props" -MultiTarget $MultiTarget
}


Set-Location $preWorkingDir;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Param (
[Parameter(HelpMessage = "A path to a .props file where generated content should be saved to.", Mandatory = $true)]
[string]$outputPath,

[Parameter(HelpMessage = "The path to the template used to generate the props file.")]
[Parameter(HelpMessage = "The path to the template used to generate the props file.")]
[string]$templatePath = "$PSScriptRoot/MultiTargetAwareProjectReference.props.template",

[Parameter(HelpMessage = "The path to the props file that contains the default MultiTarget values.")]
Expand All @@ -15,7 +15,11 @@ Param (
[string]$projectFileNamePlaceholder = "[ProjectFileName]",

[Parameter(HelpMessage = "The placeholder text to replace when inserting the project path into the template.")]
[string]$projectRootPlaceholder = "[ProjectRoot]"
[string]$projectRootPlaceholder = "[ProjectRoot]",

[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")]
[string[]] $MultiTarget = @("uwp", "wasdk", "wpf", "wasm", "linuxgtk", "macos", "ios", "android")
)

$preWorkingDir = $pwd;
Expand All @@ -29,56 +33,31 @@ Set-Location $preWorkingDir;
# Insert csproj file name.
$csprojFileName = [System.IO.Path]::GetFileName($relativeProjectPath);
$templateContents = $templateContents -replace [regex]::escape($projectFileNamePlaceholder), $csprojFileName;
$projectName = (Get-Item (Split-Path -Parent $projectPath)).Name;

# Insert project directory
$projectDirectoryRelativeToRoot = [System.IO.Path]::GetDirectoryName($relativeProjectPath).TrimStart('.').TrimStart('\');
$templateContents = $templateContents -replace [regex]::escape($projectRootPlaceholder), "$projectDirectoryRelativeToRoot";

function LoadMultiTargetsFrom([string] $path) {
$fileContents = "";

# If file does not exist
if ($false -eq (Test-Path -Path $path -PathType Leaf)) {
# Load first available default
foreach ($fallbackPath in $multiTargetFallbackPropsPath) {
if (Test-Path $fallbackPath) {
$fileContents = Get-Content $fallbackPath -ErrorAction Stop;
break;
}
}
}
else {
# Load requested file
$fileContents = Get-Content $path -ErrorAction Stop;
}

# Parse file contents
$regex = Select-String -Pattern '<MultiTarget>(.+?)<\/MultiTarget>' -InputObject $fileContents;

if ($null -eq $regex -or $null -eq $regex.Matches -or $null -eq $regex.Matches.Groups -or $regex.Matches.Groups.Length -lt 2) {
Write-Error "Couldn't get MultiTarget property from $path";
exit(-1);
}

return $regex.Matches.Groups[1].Value;
}

# Load multitarget preferences for project
$multiTargets = LoadMultiTargetsFrom("$([System.IO.Path]::GetDirectoryName($projectPath))\MultiTarget.props");

$multiTargets = & $PSScriptRoot\GetMultiTargets.ps1 -ComponentName $projectName -ErrorAction Stop;
$templateContents = $templateContents -replace [regex]::escape("[IntendedTargets]"), $multiTargets;

$multiTargets = $multiTargets.Split(';');
Write-Host "Generating project references for $([System.IO.Path]::GetFileNameWithoutExtension($csprojFileName)): $($multiTargets -Join ', ')"

$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasm]"), "'$($multiTargets.Contains("wasm").ToString().ToLower())'";
$templateContents = $templateContents -replace [regex]::escape("[CanTargetUwp]"), "'$($multiTargets.Contains("uwp").ToString().ToLower())'";
$templateContents = $templateContents -replace [regex]::escape("[CanTargetWasdk]"), "'$($multiTargets.Contains("wasdk").ToString().ToLower())'";
$templateContents = $templateContents -replace [regex]::escape("[CanTargetWpf]"), "'$($multiTargets.Contains("wpf").ToString().ToLower())'";
$templateContents = $templateContents -replace [regex]::escape("[CanTargetLinuxGtk]"), "'$($multiTargets.Contains("linuxgtk").ToString().ToLower())'";
$templateContents = $templateContents -replace [regex]::escape("[CanTargetMacOS]"), "'$($multiTargets.Contains("macos").ToString().ToLower())'";
$templateContents = $templateContents -replace [regex]::escape("[CanTargetiOS]"), "'$($multiTargets.Contains("ios").ToString().ToLower())'";
$templateContents = $templateContents -replace [regex]::escape("[CanTargetDroid]"), "'$($multiTargets.Contains("android").ToString().ToLower())'";
function ShouldMultiTarget([string] $target) {
return ($multiTargets.Contains($target) -and $MultiTarget.Contains($target)).ToString().ToLower()
}

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 "droid")'";

# Save to disk
Set-Content -Path $outputPath -Value $templateContents;
58 changes: 58 additions & 0 deletions common/MultiTarget/GetMultiTargets.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<#
.SYNOPSIS
Returns the defined MultiTarget value for the provided project name.
.DESCRIPTION
Locates a component by the provided name from the root ./components folder, and pulls the <MultiTarget> value that should be used.
The MultiTarget value can be defined by a component in multiple places, but in a MultiTarget.props next to a *.csproj.
The load order is as follows:
- ./components/SomeComponent/src/MultiTarget.props
- ./components/SomeComponent/samples/MultiTarget.props
- $PSScriptRoot/Defaults.props
.PARAMETER ComponentName
The name of the component.
.EXAMPLE
C:\PS> .\GetMultiTargets "CanvasView"
Return the multitargets for the component named "CanvasView".
.NOTES
Author: Windows Community Toolkit Labs Team
Date: February 27, 2023
#>
Param (
[Parameter(HelpMessage = "The name of the component.", Mandatory = $true)]
[string]$ComponentName
)

$componentPath = "$PSScriptRoot/../../components/$ComponentName";

Test-Path $componentPath -ErrorAction Stop | Out-Null

# Folder layout is expected to match the Community Toolkit.
# Uses the <MultiTarget> values from the source library project as the fallback for the sample project.
# This behavior also implemented in MultiTarget.props for TargetFramework evaluation.
$parent = Split-Path -Parent $projectPath
$srcPath = Resolve-Path "$parent\..\src";
$samplePath = Resolve-Path "$parent\..\samples";

$multiTargetFallbackPropsPaths = @("$srcPath/MultiTarget.props", "$samplePath/MultiTarget.props", "$PSScriptRoot/Defaults.props")

$fileContents = "";
# Load first available default
foreach ($fallbackPath in $multiTargetFallbackPropsPaths) {
if (Test-Path $fallbackPath) {
$fileContents = Get-Content $fallbackPath -ErrorAction Stop;
break;
}
}

# Parse file contents
$regex = Select-String -Pattern '<MultiTarget>(.+?)<\/MultiTarget>' -InputObject $fileContents;

if ($null -eq $regex -or $null -eq $regex.Matches -or $null -eq $regex.Matches.Groups -or $regex.Matches.Groups.Length -lt 2) {
Write-Error "Couldn't get MultiTarget property from $path";
exit(-1);
}

$value = $regex.Matches.Groups[1].Value;

return $value;
5 changes: 3 additions & 2 deletions common/ProjectHeads/GenerateSingleSampleHeads.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Param (
[switch]$UseDiagnostics = $false
)

if ($Env:Path.Contains("MSBuild") -eq $false) {
if ($null -ne $Env:Path -and $Env:Path.ToLower().Contains("msbuild") -eq $false) {
Write-Host
Write-Host -ForegroundColor Red "Please run from a command window that has MSBuild.exe on the PATH"
Write-Host
Expand Down Expand Up @@ -85,7 +85,8 @@ $projects = [System.Collections.ArrayList]::new()
[void]$projects.Add(".\**.*proj")

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

0 comments on commit f2dc018

Please sign in to comment.