Skip to content

Commit

Permalink
Upgrade Authoring source generator to use new Roslyn API. (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoritzinsky authored Sep 24, 2020
1 parent 3831edd commit 2fe4e76
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions Authoring/WinRT.SourceGenerator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ public class SourceGenerator : ISourceGenerator
{
private string _tempFolder;

private string GetAssemblyName(SourceGeneratorContext context)
private string GetAssemblyName(GeneratorExecutionContext context)
{
context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.AssemblyName", out var assemblyName);
return assemblyName;
}

private string GetAssemblyVersion(SourceGeneratorContext context)
private string GetAssemblyVersion(GeneratorExecutionContext context)
{
context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.AssemblyVersion", out var assemblyVersion);
return assemblyVersion;
}

public static string GetGeneratedFilesDir(SourceGeneratorContext context)
public static string GetGeneratedFilesDir(GeneratorExecutionContext context)
{
// TODO: determine correct location to write to.
context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.GeneratedFilesDir", out var generatedFilesDir);
Directory.CreateDirectory(generatedFilesDir);
return generatedFilesDir;
}

private static bool IsCsWinRTComponent(SourceGeneratorContext context)
private static bool IsCsWinRTComponent(GeneratorExecutionContext context)
{
if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.CsWinRTComponent", out var isCsWinRTComponentStr))
{
Expand All @@ -45,7 +45,7 @@ private static bool IsCsWinRTComponent(SourceGeneratorContext context)
return false;
}

private static string GetCsWinRTExe(SourceGeneratorContext context)
private static string GetCsWinRTExe(GeneratorExecutionContext context)
{
context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.CsWinRTExe", out var cswinrtExe);
return cswinrtExe;
Expand Down Expand Up @@ -73,7 +73,7 @@ private string GetTempFolder(bool clearSourceFilesFromFolder = false)
return _tempFolder;
}

private void GenerateSources(SourceGeneratorContext context)
private void GenerateSources(GeneratorExecutionContext context)
{
string cswinrtExe = GetCsWinRTExe(context);
string assemblyName = GetAssemblyName(context);
Expand Down Expand Up @@ -110,7 +110,7 @@ private void GenerateSources(SourceGeneratorContext context)
Directory.Delete(outputDir, true);
}

private string GetWinmdOutputFile(SourceGeneratorContext context)
private string GetWinmdOutputFile(GeneratorExecutionContext context)
{
return Path.Combine(GetGeneratedFilesDir(context), GetAssemblyName(context) + ".winmd");
}
Expand All @@ -133,7 +133,7 @@ private void GenerateWinMD(MetadataBuilder metadataBuilder, string outputFile)
peBlob.WriteContentTo(fs);
}

public void Execute(SourceGeneratorContext context)
public void Execute(GeneratorExecutionContext context)
{
if (!IsCsWinRTComponent(context))
{
Expand Down Expand Up @@ -179,7 +179,7 @@ public void Execute(SourceGeneratorContext context)
Logger.Close();
}

public void Initialize(InitializationContext context)
public void Initialize(GeneratorInitializationContext context)
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion Authoring/WinRT.SourceGenerator/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Generator
{
class Logger
{
public static void Initialize(SourceGeneratorContext context)
public static void Initialize(GeneratorExecutionContext context)
{
context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.CsWinRTEnableLogging", out var enableLoggingStr);
if (enableLoggingStr != null && bool.TryParse(enableLoggingStr, out var enableLogging) && enableLogging)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.7.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0-4.20472.6" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.0" PrivateAssets="all" />
</ItemGroup>

Expand Down

0 comments on commit 2fe4e76

Please sign in to comment.