mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-08-03 11:26:13 -04:00
Tidy up assembly referencing
This commit is contained in:
parent
96ebcf29bb
commit
a818e54b85
1
.github/actions/notify_failure/action.yml
vendored
1
.github/actions/notify_failure/action.yml
vendored
@ -25,5 +25,6 @@ runs:
|
||||
steps:
|
||||
- name: Notify failure
|
||||
shell: sh
|
||||
if: ${{ inputs.WEBHOOK_URL != '' }}
|
||||
run: |
|
||||
curl ${{ inputs.WEBHOOK_URL }} -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"username\": \"${{ inputs.BOT_USERNAME }}\", \"avatar_url\": \"${{ inputs.BOT_AVATAR }}\", \"content\": \"${{ inputs.NOTIFY_MESSAGE }}\" }"
|
@ -126,7 +126,7 @@ namespace MCGalaxy.Modules.Compiling
|
||||
|
||||
/// <summary> Converts source file paths to full paths,
|
||||
/// then returns list of parsed referenced assemblies </summary>
|
||||
public static List<string> ProcessInput(string[] srcPaths, string commentPrefix) {
|
||||
protected List<string> ProcessInput(string[] srcPaths, string commentPrefix) {
|
||||
List<string> referenced = new List<string>();
|
||||
|
||||
for (int i = 0; i < srcPaths.Length; i++)
|
||||
@ -142,9 +142,9 @@ namespace MCGalaxy.Modules.Compiling
|
||||
return referenced;
|
||||
}
|
||||
|
||||
static void AddReferences(string path, string commentPrefix, List<string> referenced) {
|
||||
void AddReferences(string path, string commentPrefix, List<string> referenced) {
|
||||
// Allow referencing other assemblies using '//reference [assembly name]' at top of the file
|
||||
using (StreamReader r = new StreamReader(path)) {
|
||||
using (StreamReader r = new StreamReader(path)) {
|
||||
string refPrefix = commentPrefix + "reference ";
|
||||
string plgPrefix = commentPrefix + "pluginref ";
|
||||
string line;
|
||||
@ -156,18 +156,16 @@ namespace MCGalaxy.Modules.Compiling
|
||||
} else if (line.CaselessStarts(plgPrefix)) {
|
||||
path = Path.Combine(IScripting.PLUGINS_DLL_DIR, GetDLL(line));
|
||||
referenced.Add(Path.GetFullPath(path));
|
||||
#if NETSTANDARD
|
||||
} else if (line.CaselessStarts(commentPrefix + "dotnetref")) {
|
||||
referenced.Add(GetDLL(line));
|
||||
#endif
|
||||
} else {
|
||||
continue;
|
||||
ProcessInputLine(line, referenced);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static string GetDLL(string line) {
|
||||
protected virtual void ProcessInputLine(string line, List<string> referenced) { }
|
||||
|
||||
protected static string GetDLL(string line) {
|
||||
int index = line.IndexOf(' ') + 1;
|
||||
// For consistency with C#, treat '//reference X.dll;' as '//reference X.dll'
|
||||
return line.Substring(index).Replace(";", "");
|
||||
|
@ -46,13 +46,12 @@ namespace MCGalaxy.Modules.Compiling
|
||||
/// <summary> Compiles source code files from a particular language, using a CodeDomProvider for the compiler </summary>
|
||||
public static class ICodeDomCompiler
|
||||
{
|
||||
public static CompilerParameters PrepareInput(string[] srcPaths, string dstPath, string commentPrefix) {
|
||||
public static CompilerParameters PrepareInput(string[] srcPaths, string dstPath, List<string> referenced) {
|
||||
CompilerParameters args = new CompilerParameters();
|
||||
args.GenerateExecutable = false;
|
||||
args.IncludeDebugInformation = true;
|
||||
args.OutputAssembly = dstPath;
|
||||
|
||||
List<string> referenced = ICompiler.ProcessInput(srcPaths, commentPrefix);
|
||||
foreach (string assembly in referenced)
|
||||
{
|
||||
args.ReferencedAssemblies.Add(assembly);
|
||||
@ -97,12 +96,8 @@ namespace MCGalaxy.Modules.Compiling
|
||||
{
|
||||
static Regex outputRegWithFileAndLine;
|
||||
static Regex outputRegSimple;
|
||||
|
||||
public static List<string> PrepareInput(string[] srcPaths) {
|
||||
return ICompiler.ProcessInput(srcPaths, "//");
|
||||
}
|
||||
|
||||
public static ICompilerErrors Compile(string[] srcPaths, string dstPath, List<string> referenced) {
|
||||
public static ICompilerErrors Compile(string[] srcPaths, string dstPath, List<string> referenced) {
|
||||
string args = GetCommandLineArguments(srcPaths, dstPath, referenced);
|
||||
string netPath = GetBinaryFile("MCG_DOTNET_PATH", "'dotnet' executable - e.g. /home/test/.dotnet/dotnet");
|
||||
string cscPath = GetBinaryFile("MCG_COMPILER_PATH", "'csc.dll' file - e.g. /home/test/.dotnet/sdk/6.0.300/Roslyn/bincore/csc.dll");
|
||||
|
@ -34,7 +34,8 @@ namespace MCGalaxy.Modules.Compiling
|
||||
CodeDomProvider compiler;
|
||||
|
||||
protected override ICompilerErrors DoCompile(string[] srcPaths, string dstPath) {
|
||||
CompilerParameters args = ICodeDomCompiler.PrepareInput(srcPaths, dstPath, "//");
|
||||
List<string> referenced = ProcessInput(srcPaths, "//");
|
||||
CompilerParameters args = ICodeDomCompiler.PrepareInput(srcPaths, dstPath, referenced);
|
||||
args.CompilerOptions += " /unsafe";
|
||||
// NOTE: Make sure to keep CompilerOptions in sync with RoslynCSharpCompiler
|
||||
|
||||
@ -42,9 +43,15 @@ namespace MCGalaxy.Modules.Compiling
|
||||
return ICodeDomCompiler.Compile(args, srcPaths, compiler);
|
||||
}
|
||||
#else
|
||||
protected override ICompilerErrors DoCompile(string[] srcPaths, string dstPath) {
|
||||
List<string> referenced = RoslynCSharpCompiler.PrepareInput(srcPaths);
|
||||
protected override ICompilerErrors DoCompile(string[] srcPaths, string dstPath) {
|
||||
List<string> referenced = ProcessInput(srcPaths, "//");
|
||||
return RoslynCSharpCompiler.Compile(srcPaths, dstPath, referenced);
|
||||
}
|
||||
|
||||
protected override void ProcessInputLine(string line, List<string> referenced) {
|
||||
if (!line.CaselessStarts("//dotnetref")) return;
|
||||
|
||||
referenced.Add(GetDLL(line));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user