Skip to content

Commit

Permalink
embedding dummy SourceExpander code
Browse files Browse the repository at this point in the history
  • Loading branch information
kzrnm committed Nov 29, 2020
1 parent 19bb79e commit e461a1e
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 3 deletions.
45 changes: 45 additions & 0 deletions Source/DummySourceExpanderEmbedder/DummySourceExpanderEmbedder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Reflection;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Text;
using SourceExpander.Roslyn;

namespace SourceExpander
{
[Generator]
public class DummySourceExpanderEmbedder : ISourceGenerator
{
public void Initialize(GeneratorInitializationContext context) { }
public void Execute(GeneratorExecutionContext context)
{
var assembly = Assembly.GetExecutingAssembly();
using var stream = assembly.GetManifestResourceStream("DummySourceExpanderEmbedder.Expander.cs");

var opts = ((CSharpParseOptions)context.ParseOptions).WithLanguageVersion(LanguageVersion.CSharp4);
var compilation = CSharpCompilation.Create(
assemblyName: "DummySourceExpander",
syntaxTrees: new[] {
CSharpSyntaxTree.ParseText(
SourceText.From(stream, Encoding.UTF8))
},
references: context.Compilation.References,
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));

if (!compilation.GetDiagnostics(context.CancellationToken).IsEmpty)
throw new InvalidProgramException();

var resolver = new EmbeddingResolver(
compilation,
opts,
new DiagnosticReporter(context),
context.CancellationToken);

foreach (var (path, source) in resolver.EnumerateEmbeddingSources())
{
context.AddSource(path, source);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>9</LangVersion>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Expander.cs" />
<EmbeddedResource Include="Expander.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SourceExpander.Embedder\SourceExpander.Embedder.csproj" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions Source/DummySourceExpanderEmbedder/Expander.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Diagnostics;

namespace SourceExpander
{
public static class Expander
{
[Conditional("EXPANDER")]
public static void Expand(string inputFilePath = null, string outputFilePath = null) { }
public static string ExpandString(string inputFilePath = null) { return ""; }
}
}
3 changes: 0 additions & 3 deletions Source/SourceExpander/Properties/AssemblyInfo.cs

This file was deleted.

4 changes: 4 additions & 0 deletions Source/SourceExpander/SourceExpander.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\DummySourceExpanderEmbedder\DummySourceExpanderEmbedder.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>Analyzer</OutputItemType>
</ProjectReference>
<ProjectReference Include="..\SourceExpander.Core\SourceExpander.Core.csproj" />
</ItemGroup>

Expand Down
6 changes: 6 additions & 0 deletions SourceExpander.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SourceExpander.Generator.Te
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{4D491FE6-63FF-4D17-A6ED-F6ACB0B23214}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DummySourceExpanderEmbedder", "Source\DummySourceExpanderEmbedder\DummySourceExpanderEmbedder.csproj", "{C379919A-0342-4945-8835-A1CE5C72E236}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -59,6 +61,10 @@ Global
{4BDD1D33-DB4B-4B06-A42D-58212D5F9A81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4BDD1D33-DB4B-4B06-A42D-58212D5F9A81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4BDD1D33-DB4B-4B06-A42D-58212D5F9A81}.Release|Any CPU.Build.0 = Release|Any CPU
{C379919A-0342-4945-8835-A1CE5C72E236}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C379919A-0342-4945-8835-A1CE5C72E236}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C379919A-0342-4945-8835-A1CE5C72E236}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C379919A-0342-4945-8835-A1CE5C72E236}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit e461a1e

Please sign in to comment.