Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"extensions": [
"ms-dotnettools.csharp",
"unoplatform.vscode",
"ms-vsliveshare.vsliveshare"
"ms-vsliveshare.vsliveshare",
"ms-vscode.powershell"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
Expand Down
37 changes: 15 additions & 22 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": "All samples",
"name": "All samples app",
"type": "coreclr",
"request": "launch",
"program": "dotnet",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we want to add this command as a separate job on the CI?

Copy link
Member Author

@Arlodotexe Arlodotexe May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't include in this PR because it isn't as easy as running a command in the CI.

To do this proper, we'd want to

  1. Investigate if we can validate the JSON as a VSCode config using some command line tool (make sure invalid json isn't generated or committed)
  2. Write a script to copy the command and parameters programmatically by reading the JSON file, then execute it to make sure it does fail.
  3. Repeat step 1 and 2 with the generated "discovered" sample launch configs.

Expand All @@ -19,28 +16,24 @@
"/p:UnoRemoteControlPort=443",
"--project=${workspaceFolder}/platforms/CommunityToolkit.Labs.Wasm/CommunityToolkit.Labs.Wasm.csproj",
"-p:TargetFrameworks=netstandard2.0",
"-p:TargetFramework=net5.0",
"-p:TargetFramework=net5.0"
],
"presentation": {
"group": "1",
"order": 1
},
"cwd": "${workspaceFolder}/platforms/CommunityToolkit.Labs.Wasm",
"preLaunchTask": "generateAllSolution"
},
{
"name": "CanvasLayout",
"type": "coreclr",
"type": "PowerShell",
"request": "launch",
"program": "dotnet",
"args": [
"run",
"build",
"/r",
"/bl",
"/p:UnoSourceGeneratorUseGenerationHost=true",
"/p:UnoSourceGeneratorUseGenerationController=false",
"/p:UnoRemoteControlPort=443",
"--project=${workspaceFolder}/labs/CanvasLayout/samples/CanvasLayout.Wasm/CanvasLayout.Wasm.csproj",
"-p:TargetFrameworks=netstandard2.0",
"-p:TargetFramework=net5.0",
],
"cwd": "${workspaceFolder}/labs/CanvasLayout/samples/CanvasLayout.Wasm",
"name": "Discover samples",
"script": "${workspaceFolder}/DiscoverSamples.ps1",
"presentation": {
"group": "2",
"order": 2
}
}
]
}
}
13 changes: 13 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "generateAllSolution",
"type": "shell",
"command": "pwsh ./GenerateAllSolution.ps1",
"group": "build"
}
]
}
106 changes: 106 additions & 0 deletions DiscoverSamples.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
Param (
[Parameter(HelpMessage = "Disables suppressing changes to the ./.vscode/launch.json file in git, allowing changes to be committed.")]
[switch]$allowGitChanges = $false
)

$templatedSampleProjectReferencesDefinitionMarker = "[TemplatedSampleProjectReferences]"
$sampleRefsPropsTemplatePath = 'common/Labs.SampleRefs.props.template';
$generatedSampleRefsPropsPath = 'common/Labs.SampleRefs.props';

function CreateVsCodeLaunchConfigJson {
param (
[string]$projectName
)

return "{
`"name`": `"$projectName`",
`"type`": `"coreclr`",
`"request`": `"launch`",
`"program`": `"dotnet`",
`"args`": [
`"run`",
`"build`",
`"/r`",
`"/p:UnoSourceGeneratorUseGenerationHost=true`",
`"/p:UnoSourceGeneratorUseGenerationController=false`",
`"/p:UnoRemoteControlPort=443`",
`"--project=`$`{workspaceFolder`}/labs/$projectName/samples/$projectName.Wasm/$projectName.Wasm.csproj`",
`"-p:TargetFrameworks=netstandard2.0`",
`"-p:TargetFramework=net5.0`",
],
`"presentation`": {
`"group`": `"2`",
},
`"cwd`": `"`$`{workspaceFolder`}/labs/$projectName/samples/$projectName.Wasm`",
}";
}

# Execute ProjectReference generation for all heads
$sampleRefsPropsTemplate = Get-Content -Path $sampleRefsPropsTemplatePath;
Write-Output "Loaded sample ProjectReference template from $sampleRefsPropsTemplatePath";

# Add sample projects
foreach ($sampleProjectPath in Get-ChildItem -Recurse -Path 'labs/*/samples/*.Sample/*.Sample.csproj') {
$relativePath = Resolve-Path -Relative -Path $sampleProjectPath;
$relativePath = $relativePath.TrimStart('.\');
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath);

Write-Host "Adding $projectName to project references";

$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";

$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
" + $projectReferenceDefinition);
}

# Add library projects
foreach ($sampleProjectPath in Get-ChildItem -Recurse -Path 'labs/*/src/*.csproj') {
$relativePath = Resolve-Path -Relative -Path $sampleProjectPath;
$relativePath = $relativePath.TrimStart('.\');
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath);

Write-Host "Adding $projectName to project references";

$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";

$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
" + $projectReferenceDefinition);
}

$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), "";

# Save
Set-Content -Path $generatedSampleRefsPropsPath -Value $sampleRefsPropsTemplate;
Write-Output "Sample project references generated at $generatedSampleRefsPropsPath";

$launchConfigJson = Get-Content -Path "./.vscode/launch.json";
$launchConfig = $launchConfigJson | ConvertFrom-Json;

# Remove all non-generated configurations
$originalConfigurations = $launchConfig.configurations;
$launchConfig.configurations = @();
$launchConfig.configurations += $originalConfigurations[0];
$launchConfig.configurations += $originalConfigurations[1];

foreach ($wasmProjectPath in Get-ChildItem -Recurse -Path 'labs/*/samples/*.Wasm/*.Wasm.csproj') {
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($wasmProjectPath) -Replace ".Wasm", "";
Write-Host "Generating VSCode launch config for $projectName";

$configJson = CreateVsCodeLaunchConfigJson $projectName;
$config = $configJson | ConvertFrom-Json;

$launchConfig.configurations += $config;
}

if ($allowGitChanges.IsPresent) {
Write-Warning "Changes to the default launch.json in Labs can now be committed. Run this command again without the -allowGitChanges flag to disable committing further changes.";
git update-index --no-assume-unchanged ./.vscode/launch.json
}
else {
Write-Output "Changes to the default launch.json in Labs are now suppressed. To switch branches, run git reset --hard with a clean working tree. Include the -allowGitChanges flag to enable committing changes.";
git update-index --assume-unchanged ./.vscode/launch.json
}

# Save
Set-Content -Path "./.vscode/launch.json" -Value ($launchConfig | ConvertTo-Json -Depth 9);
Write-Output "Saved VSCode launch configs to ./.vscode/launch.json";
43 changes: 2 additions & 41 deletions GenerateAllSolution.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ $templatedProjectDefinitionsMarker = "[TemplatedProjectDefinitions]";
$templatedSharedTestProjectSelfDefinitionsMarker = "[TemplatedSharedTestProjectDefinitions]";
$templatedSharedTestUwpProjectSelfDefinitionsMarker = "[TemplatedSharedTestUwpProjectDefinitions]";
$templatedSharedTestWinAppSdkProjectSelfDefinitionsMarker = "[TemplatedSharedTestWinAppSdkProjectDefinitions]";
$templatedSampleProjectReferencesDefinitionMarker = "[TemplatedSampleProjectReferences]"

$sampleProjectTypeGuid = "9A19103F-16F7-4668-BE54-9A1E7A4F7556";
$sharedProjectTypeGuid = "D954291E-2A0B-460D-934E-DC6B0785DB48";
Expand All @@ -28,9 +27,6 @@ $libProjectTypeGuid = $sampleProjectTypeGuid;
$solutionTemplatePath = 'common/Toolkit.Labs.All.sln.template';
$generatedSolutionFilePath = 'Toolkit.Labs.All.sln'

$sampleRefsPropsTemplatePath = 'common/Labs.SampleRefs.props.template';
$generatedSampleRefsPropsPath = 'common/Labs.SampleRefs.props';

function CreateProjectConfiguration {
param (
[string]$projectGuid
Expand Down Expand Up @@ -248,40 +244,5 @@ $solutionTemplate = $solutionTemplate -replace "(?m)^\s*`r`n", "";
Set-Content -Path $generatedSolutionFilePath -Value $solutionTemplate;
Write-Output "Solution generated at $generatedSolutionFilePath";

# Execute ProjectReference generation for all heads
$sampleRefsPropsTemplate = Get-Content -Path $sampleRefsPropsTemplatePath;
Write-Output "Loaded sample ProjectReference template from $sampleRefsPropsTemplatePath";

# Add sample projects
foreach ($sampleProjectPath in Get-ChildItem -Recurse -Path 'labs/*/samples/*.Sample/*.Sample.csproj') {
$relativePath = Resolve-Path -Relative -Path $sampleProjectPath;
$relativePath = $relativePath.TrimStart('.\');
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath);

Write-Host "Adding $projectName to project references";

$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";

$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
" + $projectReferenceDefinition);
}

# Add library projects
foreach ($sampleProjectPath in Get-ChildItem -Recurse -Path 'labs/*/src/*.csproj') {
$relativePath = Resolve-Path -Relative -Path $sampleProjectPath;
$relativePath = $relativePath.TrimStart('.\');
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($relativePath);

Write-Host "Adding $projectName to project references";

$projectReferenceDefinition = "<ProjectReference Include=`"`$(RepositoryDirectory)$relativePath`" />";

$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), ($templatedSampleProjectReferencesDefinitionMarker + "
" + $projectReferenceDefinition);
}

$sampleRefsPropsTemplate = $sampleRefsPropsTemplate -replace [regex]::escape($templatedSampleProjectReferencesDefinitionMarker), "";

# Save
Set-Content -Path $generatedSampleRefsPropsPath -Value $sampleRefsPropsTemplate;
Write-Output "Sample project references generated at $generatedSampleRefsPropsPath";
# Run sample discovery
& ./DiscoverSamples.ps1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work if the script is executed from a different directory? (Don't think that'll be a common occurrence, but curious as I know I had to use a different method in the past to grab the current directory of where the script was located that is being executed.)

Copy link
Member Author

@Arlodotexe Arlodotexe May 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this would work if ran from a different directory, same way relatives paths break in UseUnoWinUI.ps1 and UseTargetFrameworks.ps1 when run from the wrong directory.

Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private ImmutableArray<ToolkitFrontMatter> GatherDocumentFrontMatter(SourceProdu
}

// Get the filepath we need to be able to load the markdown file in sample app.
var filepath = file.Path.Split(new string[] { @"\labs\" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
var filepath = file.Path.Split(new string[] { @"\labs\", "/labs/" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();

// Look for sample id tags
var matches = MarkdownRegexSampleTag.Matches(content);
Expand Down