Skip to content

Commit

Permalink
Added Basic conditionally to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Oct 21, 2023
1 parent 616115e commit 356651c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Draco.Compiler.Cli/Draco.Compiler.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Basic.Reference.Assemblies.Net70" Version="1.4.1" Condition="$(DefineConstants.Contains('DEBUG'))" />
</ItemGroup>
</Project>
16 changes: 10 additions & 6 deletions src/Draco.Compiler.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ private static void CompileCommand(FileInfo[] input, FileInfo output, DirectoryI
var (path, name) = ExtractOutputPathAndName(output);
var compilation = Compilation.Create(
syntaxTrees: syntaxTrees,
metadataReferences: references
.Select(r => MetadataReference.FromPeStream(r.OpenRead()))
.ToImmutableArray(),
metadataReferences: GetMetadataReferences(references),
rootModulePath: rootModule?.FullName,
outputPath: path,
assemblyName: name);
Expand All @@ -131,9 +129,7 @@ private static void RunCommand(FileInfo[] input, DirectoryInfo? rootModule, File
var syntaxTrees = GetSyntaxTrees(input);
var compilation = Compilation.Create(
syntaxTrees: syntaxTrees,
metadataReferences: references
.Select(r => MetadataReference.FromPeStream(r.OpenRead()))
.ToImmutableArray(),
metadataReferences: GetMetadataReferences(references),
rootModulePath: rootModule?.FullName);
var execResult = ScriptingEngine.Execute(compilation);
if (!EmitDiagnostics(execResult, msbuildDiags))
Expand Down Expand Up @@ -193,6 +189,14 @@ private static ImmutableArray<SyntaxTree> GetSyntaxTrees(params FileInfo[] input
return result.ToImmutable();
}

private static ImmutableArray<MetadataReference> GetMetadataReferences(FileInfo[] references) => references
.Select(r => MetadataReference.FromPeStream(r.OpenRead()))
#if DEBUG
.Concat(Basic.Reference.Assemblies.Net70.ReferenceInfos.All
.Select(r => MetadataReference.FromPeStream(new MemoryStream(r.ImageBytes))))
#endif
.ToImmutableArray();

private static bool EmitDiagnostics(EmitResult result, bool msbuildDiags)
{
if (result.Success) return false;
Expand Down

0 comments on commit 356651c

Please sign in to comment.