Skip to content

Commit

Permalink
Scope down - remove xdc for now
Browse files Browse the repository at this point in the history
  • Loading branch information
asklar committed May 11, 2022
1 parent 9ac1318 commit 6843eaa
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 89 deletions.
10 changes: 5 additions & 5 deletions src/Authoring/WinRT.SourceGenerator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ public void Generate()
writer.FinalizeGeneration();

GenerateWinMD(metadataBuilder);
if (!context.ShouldSkipGeneratingSources())
{
GenerateSources();
if (!context.ShouldGenerateWinMDOnly())
{
GenerateSources();
}
}
catch (Exception e)
Expand All @@ -206,8 +206,8 @@ public class SourceGenerator : ISourceGenerator
{
public void Execute(GeneratorExecutionContext context)
{
var isTest = string.CompareOrdinal(Process.GetCurrentProcess().ProcessName, "testhost") == 0;
if (!isTest && !context.IsCsWinRTComponent())
var isTest = string.CompareOrdinal(Process.GetCurrentProcess().ProcessName, "testhost") == 0;
if (!isTest && !context.IsCsWinRTComponent() && !context.ShouldGenerateWinMDOnly())
{
System.Diagnostics.Debug.WriteLine($"Skipping component {context.GetAssemblyName()}");
return;
Expand Down
50 changes: 25 additions & 25 deletions src/Authoring/WinRT.SourceGenerator/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO;
using System.Linq;

namespace Generator
Expand Down Expand Up @@ -32,23 +32,23 @@ public static Guid EncodeGuid(byte[] data)
}
return new Guid(data.Take(16).ToArray());
}
}

class AttributeDataComparer : IEqualityComparer<AttributeData>
{
public bool Equals(AttributeData x, AttributeData y)
{
return string.CompareOrdinal(x.ToString(), y.ToString()) == 0;
}

public int GetHashCode(AttributeData obj)
{
return obj.ToString().GetHashCode();
}
}

static class GeneratorExecutionContextHelper
{
class AttributeDataComparer : IEqualityComparer<AttributeData>
{
public bool Equals(AttributeData x, AttributeData y)
{
return string.CompareOrdinal(x.ToString(), y.ToString()) == 0;
}

public int GetHashCode(AttributeData obj)
{
return obj.ToString().GetHashCode();
}
}

static class GeneratorExecutionContextHelper
{
public static string GetAssemblyName(this GeneratorExecutionContext context)
{
context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.AssemblyName", out var assemblyName);
Expand Down Expand Up @@ -78,14 +78,14 @@ public static bool IsCsWinRTComponent(this GeneratorExecutionContext context)
return false;
}

public static bool ShouldSkipGeneratingSources(this GeneratorExecutionContext context)
{
if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.CSWinMD", out var isCsWinMDStr))
public static bool ShouldGenerateWinMDOnly(this GeneratorExecutionContext context)
{
if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.CsWinRTGenerateWinMDOnly", out var CsWinRTGenerateWinMDOnlyStr))
{
return bool.TryParse(isCsWinMDStr, out var isCsWinMD) && isCsWinMD;
return bool.TryParse(CsWinRTGenerateWinMDOnlyStr, out var CsWinRTGenerateWinMDOnly) && CsWinRTGenerateWinMDOnly;
}

return false;
return false;
}

public static string GetCsWinRTExe(this GeneratorExecutionContext context)
Expand All @@ -110,11 +110,11 @@ public static string GetCsWinRTDependentMetadata(this GeneratorExecutionContext
{
context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.CsWinRTAuthoringInputs", out var winmds);
return winmds;
}

}

public static string GetWinmdOutputFile(this GeneratorExecutionContext context)
{
return Path.Combine(context.GetGeneratedFilesDir(), context.GetAssemblyName() + ".winmd");
}
}
}
}
57 changes: 0 additions & 57 deletions src/Authoring/WinRT.SourceGenerator/WinRTTypeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2585,22 +2585,13 @@ void AddCustomAttributes(TypeDeclaration typeDeclaration, string interfaceName =
}
}

public static string XmlDocCustomAttributeTypeName { get; set; } = "CppComponent.DocStringAttribute";

public void FinalizeGeneration()
{
Logger.Log("finalizing");
var classTypeDeclarations = typeDefinitionMapping.Values
.Where(declaration => declaration.Node is INamedTypeSymbol symbol && symbol.TypeKind == TypeKind.Class)
.ToList();


var xmlDocCustomAttributeType = Model.Compilation.GetTypeByMetadataName(XmlDocCustomAttributeTypeName);
if (xmlDocCustomAttributeType != null)
{
GenerateXmlDocCustomAttributes();
}

foreach (var classTypeDeclaration in classTypeDeclarations)
{
INamedTypeSymbol classSymbol = classTypeDeclaration.Node as INamedTypeSymbol;
Expand Down Expand Up @@ -2745,54 +2736,6 @@ public void FinalizeGeneration()
}
}

private void GenerateXmlDocCustomAttributes()
{
throw new NotSupportedException();
var xdcTypes = typeDefinitionMapping.Values.Where(d => d.Node is INamedTypeSymbol);
foreach (var type in xdcTypes)
{
AddXmlDocumentation(type);

foreach (var methodDefs in type.MethodReferences)
{
var xdc = methodDefs.Key.GetDocumentationCommentXml();
if (!string.IsNullOrEmpty(xdc))
{
foreach (var eh in methodDefs.Value)
{
AddCustomAttributes(XmlDocCustomAttributeTypeName,
new[] { Model.Compilation.GetSpecialType(SpecialType.System_String) },
new[] { xdc },
eh);
}
}
}
foreach (var fieldDef in type.FieldDefinitions)
{
var xdc = fieldDef.Key.GetDocumentationCommentXml();
if (!string.IsNullOrEmpty(xdc))
{
AddCustomAttributes(XmlDocCustomAttributeTypeName,
new[] { Model.Compilation.GetSpecialType(SpecialType.System_String) },
new[] { xdc },
fieldDef.Value);
}
}
}
}

private void AddXmlDocumentation(TypeDeclaration classTypeDeclaration)
{
var xdc = classTypeDeclaration.Node.GetDocumentationCommentXml();
if (!string.IsNullOrEmpty(xdc))
{
AddCustomAttributes(XmlDocCustomAttributeTypeName,
new[] { Model.Compilation.GetSpecialType(SpecialType.System_String) },
new[] { xdc },
classTypeDeclaration.Handle);
}
}

public bool IsPublic(ISymbol type)
{
return type.DeclaredAccessibility == Accessibility.Public ||
Expand Down
3 changes: 1 addition & 2 deletions src/Authoring/cswinmd/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ public static void Main(string[] i, string o, string? sdkVersion)
config.Values["build_property.AssemblyName"] = assemblyName;
config.Values["build_property.AssemblyVersion"] = "0.0.0.1";
config.Values["build_property.CsWinRTGeneratedFilesDir"] = outFolder;
config.Values["build_property.CsWinRTComponent"] = "true";
config.Values["build_property.CsWinRTEnableLogging"] = "true";
config.Values["build_property.CSWinMD"] = "true";
config.Values["build_property.CsWinRTGenerateWinMDOnly"] = "true";

var driver = CSharpGeneratorDriver.Create(
generators: ImmutableArray.Create(g),
Expand Down

0 comments on commit 6843eaa

Please sign in to comment.