aboutsummaryrefslogtreecommitdiff
path: root/src/ext/Bal/WixToolset.Dnc.HostGenerator/DncHostGenerator.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ext/Bal/WixToolset.Dnc.HostGenerator/DncHostGenerator.cs')
-rw-r--r--src/ext/Bal/WixToolset.Dnc.HostGenerator/DncHostGenerator.cs127
1 files changed, 0 insertions, 127 deletions
diff --git a/src/ext/Bal/WixToolset.Dnc.HostGenerator/DncHostGenerator.cs b/src/ext/Bal/WixToolset.Dnc.HostGenerator/DncHostGenerator.cs
deleted file mode 100644
index 088b2b49..00000000
--- a/src/ext/Bal/WixToolset.Dnc.HostGenerator/DncHostGenerator.cs
+++ /dev/null
@@ -1,127 +0,0 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.Dnc.HostGenerator
4{
5 using System;
6 using System.Diagnostics.CodeAnalysis;
7 using System.Text;
8 using Microsoft.CodeAnalysis;
9 using Microsoft.CodeAnalysis.Text;
10
11 [Generator]
12 public sealed class DncHostGenerator : ISourceGenerator
13 {
14 public static readonly string Version = String.Format($"{ThisAssembly.Git.SemVer.Major}.{ThisAssembly.Git.SemVer.Minor}.{ThisAssembly.Git.SemVer.Patch}{ThisAssembly.Git.SemVer.DashLabel}+{ThisAssembly.Git.Sha}");
15 public static readonly string TargetAttributeFullName = "WixToolset.Mba.Core.BootstrapperApplicationFactoryAttribute";
16
17 [SuppressMessage("MicrosoftCodeAnalysisReleaseTracking", "RS2008:Enable analyzer release tracking", Justification = "Tracking not needed")]
18 public static readonly DiagnosticDescriptor MissingFactoryAttributeDescriptor = new DiagnosticDescriptor(
19 "WIXBAL001",
20 $"Missing assembly level attribute {TargetAttributeFullName}.",
21 $"Add [assembly: {TargetAttributeFullName}(typeof(<your IBootstrapperApplicationFactory>)].",
22 "WixToolset.Bal.wixext",
23 DiagnosticSeverity.Error,
24 true
25 );
26
27 public void Initialize(GeneratorInitializationContext context)
28 {
29 }
30
31 public void Execute(GeneratorExecutionContext context)
32 {
33 var symbolDisplayFormat = new SymbolDisplayFormat(typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces);
34
35 string baFactoryClassName = null;
36 foreach (var assemblyAttribute in context.Compilation.Assembly.GetAttributes())
37 {
38 var fullAssemblyTypeName = assemblyAttribute.AttributeClass.ToDisplayString(symbolDisplayFormat);
39
40 if (fullAssemblyTypeName == TargetAttributeFullName &&
41 assemblyAttribute.ConstructorArguments.Length == 1)
42 {
43 var arg = assemblyAttribute.ConstructorArguments[0];
44 if (arg.Value is INamedTypeSymbol argValue)
45 {
46 baFactoryClassName = argValue.ToDisplayString(symbolDisplayFormat);
47 break;
48 }
49 }
50 }
51
52 if (baFactoryClassName == null)
53 {
54 context.ReportDiagnostic(Diagnostic.Create(MissingFactoryAttributeDescriptor, null));
55 }
56 else
57 {
58 var source = String.Format(Template, Version, baFactoryClassName);
59 context.AddSource("WixToolset.Dnc.Host.g.cs", SourceText.From(source, Encoding.UTF8, SourceHashAlgorithm.Sha256));
60 }
61 }
62
63 public const string Template = @"
64//------------------------------------------------------------------------------
65// <auto-generated>
66// This code was generated by a tool.
67//
68// Changes to this file may cause incorrect behavior and will be lost if
69// the code is regenerated.
70// </auto-generated>
71//------------------------------------------------------------------------------
72
73namespace WixToolset.Dnc.Host
74{{
75 using System;
76 using System.CodeDom.Compiler;
77 using System.Diagnostics.CodeAnalysis;
78 using System.Linq;
79 using System.Reflection;
80 using System.Runtime.CompilerServices;
81 using System.Runtime.InteropServices;
82 using WixToolset.Mba.Core;
83
84 [GeneratedCode(""WixToolset.Dnc.HostGenerator.DncHostGenerator"", ""{0}"")]
85 [CompilerGenerated]
86 delegate IBootstrapperApplicationFactory StaticEntryDelegate();
87
88 /// <summary>
89 /// Entry point for the .NET Core host to create and return the BA to the engine.
90 /// </summary>
91 [GeneratedCode(""WixToolset.Dnc.HostGenerator.DncHostGenerator"", ""{0}"")]
92 [CompilerGenerated]
93 public sealed class BootstrapperApplicationFactory : IBootstrapperApplicationFactory
94 {{
95 /// <summary>
96 /// Creates the bootstrapper application factory and calls its IBootstrapperApplicationFactory.Create method.
97 /// </summary>
98 /// <param name=""pArgs"">Pointer to BOOTSTRAPPER_CREATE_ARGS struct.</param>
99 /// <param name=""pResults"">Pointer to BOOTSTRAPPER_CREATE_RESULTS struct.</param>
100 public void Create(IntPtr pArgs, IntPtr pResults)
101 {{
102 var baFactory = new {1}();
103 baFactory.Create(pArgs, pResults);
104 }}
105
106 // Entry point for the DNC host.
107 public static IBootstrapperApplicationFactory CreateBAFactory()
108 {{
109 return new BootstrapperApplicationFactory();
110 }}
111
112#if NET5_0_OR_GREATER
113 [ModuleInitializer]
114 [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(BootstrapperApplicationFactory))]
115#if NET5_0
116 [DynamicDependency(""GetFunctionPointer(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr)"", ""Internal.Runtime.InteropServices.ComponentActivator"", ""System.Private.CoreLib"")]
117#endif
118 /// <summary>
119 /// Empty method to attach above attributes to support linker trimming.
120 /// </summary>
121 public static void ModuleInitialize() {{ }}
122#endif
123 }}
124}}
125";
126 }
127}