From f1808d9231ca00d549c2ba301020c0e82c876c0c Mon Sep 17 00:00:00 2001 From: Maplewheels Date: Sun, 29 Mar 2026 00:30:18 -0400 Subject: [PATCH] Added verbose cs compilation. --- .../LuaCs/_Plugins/AssemblyLoader.cs | 21 ++++++++++++++----- .../LuaCs/_Plugins/IAssemblyLoaderService.cs | 18 ++++++++-------- .../_Services/PluginManagementService.cs | 2 +- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Plugins/AssemblyLoader.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Plugins/AssemblyLoader.cs index bd82efe1f..485690f8e 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Plugins/AssemblyLoader.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Plugins/AssemblyLoader.cs @@ -9,6 +9,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Loader; +using System.Text; using System.Threading; using Barotrauma.Extensions; using Barotrauma.LuaCs; @@ -255,8 +256,7 @@ public sealed class AssemblyLoader : AssemblyLoadContext, IAssemblyLoaderService } } - public FluentResults.Result CompileScriptAssembly( - [NotNull] string assemblyName, + public Result CompileScriptAssembly([NotNull] string assemblyName, bool compileWithInternalAccess, ImmutableArray syntaxTrees, ImmutableArray metadataReferences, @@ -290,7 +290,8 @@ public sealed class AssemblyLoader : AssemblyLoadContext, IAssemblyLoaderService outputKind: OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release, concurrentBuild: true, - reportSuppressedDiagnostics: true, + reportSuppressedDiagnostics: false, + warningLevel: 0, allowUnsafe: true); if (!compileWithInternalAccess) @@ -306,12 +307,22 @@ public sealed class AssemblyLoader : AssemblyLoadContext, IAssemblyLoaderService using var asmMemoryStream = new MemoryStream(); var result = CSharpCompilation - .Create(compilationAssemblyName, syntaxTrees, metadataReferences, compilationOptions) + .Create(compilationAssemblyName, syntaxTrees, + metadataReferences, compilationOptions) .Emit(asmMemoryStream); if (!result.Success) { + StringBuilder sb = new StringBuilder(); + foreach (var resultDiagnostic in result.Diagnostics) + { + if (resultDiagnostic.Severity != DiagnosticSeverity.Error) + { + continue; + } + sb.AppendLine($">>> {resultDiagnostic.GetMessage()} | Location: {resultDiagnostic.Location.SourceTree?.GetLineSpan(resultDiagnostic.Location.SourceSpan)} "); + } var res = new FluentResults.Result().WithError( - new Error($"Compilation failed for assembly {assemblyName}!") + new Error($"Package Error: {OwnerPackage.Name}: Compilation failed for assembly {assemblyName}! {sb.ToString()}\n") .WithMetadata(MetadataType.ExceptionObject, this) .WithMetadata(MetadataType.RootObject, syntaxTrees)); var failuresDiag = diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Plugins/IAssemblyLoaderService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Plugins/IAssemblyLoaderService.cs index 00cc5042b..f02f5c89b 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Plugins/IAssemblyLoaderService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Plugins/IAssemblyLoaderService.cs @@ -6,6 +6,7 @@ using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.CompilerServices; using Barotrauma.LuaCs; +using FluentResults; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -74,20 +75,19 @@ public interface IAssemblyLoaderService : IService /// AssemblyManager class. /// /// [NotNull]Name reference of the assembly. - /// [IMPORTANT] This is used to reference this assembly as the true name will be forced if - /// publicized assemblies are not used (InternalsVisibleTo Attrib). - /// Must be supplied for in-memory assemblies. - /// Must be unique to all other assemblies explicitly loaded using this context. + /// [IMPORTANT] This is used to reference this assembly as the true name will be forced if + /// publicized assemblies are not used (InternalsVisibleTo Attrib). + /// Must be supplied for in-memory assemblies. + /// Must be unique to all other assemblies explicitly loaded using this context. /// Forces the assembly name to and grants access to internal. - /// [IMPORTANT]Cannot be null or empty if is false. /// [NotNull]Syntax trees to compile into the assembly. /// All MetadataReferences to be used for compilation. - /// [IMPORTANT] This method builds metadata from loaded assemblies, only supply your own if you have in-memory - /// images not managed by the AssemblyManager class. + /// [IMPORTANT] This method builds metadata from loaded assemblies, only supply your own if you have in-memory + /// images not managed by the AssemblyManager class. /// [NotNull]CSharp compilation options. This method automatically adds the 'IgnoreAccessChecks' property for compilation. + /// [IMPORTANT]Cannot be null or empty if is false. /// Success state of the operation. - public FluentResults.Result CompileScriptAssembly( - [NotNull] string assemblyName, + public Result CompileScriptAssembly([NotNull] string assemblyName, bool compileWithInternalAccess, ImmutableArray syntaxTrees, ImmutableArray metadataReferences, diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/PluginManagementService.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/PluginManagementService.cs index b87a1d525..a8cf9ec23 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/PluginManagementService.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/_Services/PluginManagementService.cs @@ -588,7 +588,7 @@ public class PluginManagementService : IAssemblyManagementService syntaxTreesBuilder.Add(SyntaxFactory.ParseSyntaxTree( text: sourceCode, options: ScriptParseOptions, - path: null, + path: resourcePath.FullPath, encoding: Encoding.Default, cancellationToken: token ));