Skip to content

Commit

Permalink
Allow CSharpSyntaxGenerator to be used as a source generator
Browse files Browse the repository at this point in the history
This takes a fairly hacky approach to updating the code by converting
the CSharpSyntaxGenerator project to build twice: once as a
netcoreapp3.1 console app like it always did, and now also as a
netstandard2.0 library that is a source generator. The source generator
one only supports building the .cs outputs that are consumed as regular
APIs, and ignores the test or grammar outputs for now.

There is also no handling for cancellation yet which is not good for
performance.
  • Loading branch information
jasonmalinowski committed Nov 3, 2020
1 parent 5eae400 commit 875e104
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 65,725 deletions.
8 changes: 4 additions & 4 deletions Compilers.sln
Expand Up @@ -301,10 +301,10 @@ Global
{288089C5-8721-458E-BE3E-78990DAB5E2E}.Debug|Any CPU.Build.0 = Debug|x64
{288089C5-8721-458E-BE3E-78990DAB5E2E}.Release|Any CPU.ActiveCfg = Release|x64
{288089C5-8721-458E-BE3E-78990DAB5E2E}.Release|Any CPU.Build.0 = Release|x64
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Debug|Any CPU.ActiveCfg = Debug|x64
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Debug|Any CPU.Build.0 = Debug|x64
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Release|Any CPU.ActiveCfg = Release|x64
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Release|Any CPU.Build.0 = Release|x64
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Release|Any CPU.Build.0 = Release|Any CPU
{D0A79850-B32A-45E5-9FD5-D43CB345867A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D0A79850-B32A-45E5-9FD5-D43CB345867A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0A79850-B32A-45E5-9FD5-D43CB345867A}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
8 changes: 4 additions & 4 deletions Roslyn.sln
Expand Up @@ -662,10 +662,10 @@ Global
{288089C5-8721-458E-BE3E-78990DAB5E2E}.Debug|Any CPU.Build.0 = Debug|x64
{288089C5-8721-458E-BE3E-78990DAB5E2E}.Release|Any CPU.ActiveCfg = Release|x64
{288089C5-8721-458E-BE3E-78990DAB5E2E}.Release|Any CPU.Build.0 = Release|x64
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Debug|Any CPU.ActiveCfg = Debug|x64
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Debug|Any CPU.Build.0 = Debug|x64
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Release|Any CPU.ActiveCfg = Release|x64
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Release|Any CPU.Build.0 = Release|x64
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{288089C5-8721-458E-BE3E-78990DAB5E2D}.Release|Any CPU.Build.0 = Release|Any CPU
{6AA96934-D6B7-4CC8-990D-DB6B9DD56E34}.Debug|Any CPU.ActiveCfg = Debug|x64
{6AA96934-D6B7-4CC8-990D-DB6B9DD56E34}.Debug|Any CPU.Build.0 = Debug|x64
{6AA96934-D6B7-4CC8-990D-DB6B9DD56E34}.Release|Any CPU.ActiveCfg = Release|x64
Expand Down
8 changes: 6 additions & 2 deletions eng/generate-compiler-code.ps1
Expand Up @@ -11,7 +11,7 @@ $ErrorActionPreference="Stop"
function Run-Tool($projectFilePath, $toolArgs) {
$toolName = Split-Path -leaf $projectFilePath
Write-Host "Running $toolName $toolArgs"
Exec-Console $dotnet "run -p $projectFilePath $toolArgs"
Exec-Console $dotnet "run -p $projectFilePath --framework netcoreapp3.1 $toolArgs"
}

function Run-LanguageCore($language, $languageSuffix, $languageDir, $syntaxProject, $errorFactsProject, $generatedDir, $generatedTestDir) {
Expand All @@ -25,7 +25,11 @@ function Run-LanguageCore($language, $languageSuffix, $languageDir, $syntaxProje

Create-Directory $generatedDir
Create-Directory $generatedTestDir
Run-Tool $syntaxProject "`"$syntaxFilePath`" `"$generatedDir`""

# The C# syntax is now generated by a source generator
if ($language -ne "CSharp") {
Run-Tool $syntaxProject "`"$syntaxFilePath`" `"$generatedDir`""
}
Run-Tool $syntaxProject "`"$syntaxFilePath`" `"$generatedDir`" /grammar"
Run-Tool $syntaxProject "`"$syntaxFilePath`" `"$syntaxTestFilePath`" /test"
Run-Tool $boundTreeGenProject "$language `"$boundFilePath`" `"$boundGeneratedFilePath`""
Expand Down
2 changes: 1 addition & 1 deletion eng/targets/Imports.targets
Expand Up @@ -171,7 +171,7 @@
Disable analyzers via an MSBuild property settable on the command line.
-->
<ItemGroup>
<Analyzer Remove="@(Analyzer)" />
<Analyzer Remove="@(Analyzer)" Condition="'%(FileName)' != 'CSharpSyntaxGenerator'" />
</ItemGroup>
</Target>

Expand Down

0 comments on commit 875e104

Please sign in to comment.