From 176a030a5765472fb28677f11cba0c251fa425be Mon Sep 17 00:00:00 2001 From: Austin Vandersluis Date: Sun, 19 Nov 2023 06:56:40 -0800 Subject: [PATCH] Add support for configurable preprocessor directives --- src/CSharp/CSharpLanguage.cs | 6 +++--- src/ObjectStream/Data/CompilerData.cs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/CSharp/CSharpLanguage.cs b/src/CSharp/CSharpLanguage.cs index 3120a18..e32907b 100644 --- a/src/CSharp/CSharpLanguage.cs +++ b/src/CSharp/CSharpLanguage.cs @@ -43,9 +43,9 @@ public async Task Compile(int id, CompilerData data) Stopwatch stopwatch = Stopwatch.StartNew(); _logger.LogInformation(Events.Compile, $"Starting compilation of job {id} | Total Plugins: {data.SourceFiles.Length}"); string details = - $"Settings[Encoding: {data.Encoding}, CSVersion: {data.CSharpVersion()}, Target: {data.OutputKind()}, Platform: {data.Platform()}, StdLib: {data.StdLib}, Debug: {data.Debug}]"; + $"Settings[Encoding: {data.Encoding}, CSVersion: {data.CSharpVersion()}, Target: {data.OutputKind()}, Platform: {data.Platform()}, StdLib: {data.StdLib}, Debug: {data.Debug}, Preprocessor: {string.Join(", ", data.Preprocessor)}]"; - if (Program.ApplicationLogLevel.MinimumLevel < LogEventLevel.Debug) + if (Program.ApplicationLogLevel.MinimumLevel <= LogEventLevel.Debug) { if (data.ReferenceFiles.Length > 0) { @@ -150,7 +150,7 @@ private async Task SafeCompile(CompilerData data, CompilerMessa Dictionary trees = new(); Encoding encoding = Encoding.GetEncoding(data.Encoding); - CSharpParseOptions options = new(data.CSharpVersion()); + CSharpParseOptions options = new(data.CSharpVersion(), preprocessorSymbols: data.Preprocessor); foreach (var source in data.SourceFiles) { string fileName = Path.GetFileName(source.Name); diff --git a/src/ObjectStream/Data/CompilerData.cs b/src/ObjectStream/Data/CompilerData.cs index 5d65dc2..39d1479 100644 --- a/src/ObjectStream/Data/CompilerData.cs +++ b/src/ObjectStream/Data/CompilerData.cs @@ -26,6 +26,7 @@ public CompilerData() public CompilerLanguageVersion Version { get; set; } public string Encoding { get; set; } public bool Debug { get; set; } + public string[] Preprocessor { get; set; } [NonSerialized] public CompilerMessage Message;