-
Notifications
You must be signed in to change notification settings - Fork 79
Codespaces: Fix launching all-sample app, add auto sample discovery #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a5f1922
e6b43a2
b5a6c40
106727d
16a5263
add326b
7074f43
d4a4a63
04576c5
2fefab6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" | ||
| } | ||
| ] | ||
| } |
| 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"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"; | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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