Skip to content

Commit

Permalink
Don't hardcode CLI path when updating dotnet build
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Jul 5, 2024
1 parent dee6bee commit dd8ff42
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 24 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
if: ${{ always() && steps.compile.outcome == 'success' }}
with:
SOURCE_FILE: 'bin/Release'
DEST_NAME: 'MCGalaxy_net2.0'
DEST_NAME: 'MCGalaxy-net2.0'

- uses: ./.github/actions/notify_success
if: ${{ always() && steps.compile.outcome == 'success' }}
Expand Down Expand Up @@ -70,13 +70,13 @@ jobs:
if: ${{ always() && steps.compile.outcome == 'success' }}
with:
SOURCE_FILE: 'bin/Release_normal'
DEST_NAME: 'MCGalaxy'
DEST_NAME: 'MCGalaxy-net40'

- uses: ./.github/actions/upload_build
if: ${{ always() && steps.compile.outcome == 'success' }}
with:
SOURCE_FILE: 'bin/Release'
DEST_NAME: 'MCGalaxy-infid'
DEST_NAME: 'MCGalaxy-net40-infid'

- uses: ./.github/actions/notify_success
if: ${{ always() && steps.compile.outcome == 'success' }}
Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
if: ${{ always() && steps.compile.outcome == 'success' }}
with:
SOURCE_FILE: 'CLI/bin/Debug/net6.0'
DEST_NAME: 'MCGalaxy-dotnet6.0'
DEST_NAME: 'MCGalaxy-net6.0'

# publish standalone windows binaries
- name: Publish-win64
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
if: ${{ always() && steps.compile.outcome == 'success' }}
with:
SOURCE_FILE: 'CLI/bin/Debug/net8.0'
DEST_NAME: 'MCGalaxy-dotnet8.0'
DEST_NAME: 'MCGalaxy-net8.0'


- uses: ./.github/actions/notify_success
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Modules/Compiling/CompilerBackends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static class RoslynCSharpCompiler
static string Quote(string value) { return "\"" + value + "\""; }

static string GetDotnetPath() {
string path = Server.GetRuntimeProcessExePath();
string path = Server.GetRuntimeExePath();
if (path.EndsWith("dotnet")) return path;

return GetBinaryFile("MCG_DOTNET_PATH", "'dotnet' executable - e.g. /home/test/.dotnet/dotnet");
Expand Down
16 changes: 11 additions & 5 deletions MCGalaxy/Server/Maintenance/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,23 @@ public static class Updater
foreach (Player pl in players) pl.SaveStats();

string serverDLL = Server.GetServerDLLPath();
string serverGUI = "MCGalaxy.exe";
#if !MCG_DOTNET
string serverCLI = "MCGalaxyCLI.exe";
#else
string serverCLI = Server.GetServerExePath();
#endif

// Move current files to previous files (by moving instead of copying,
// can overwrite original the files without breaking the server)
AtomicIO.TryMove(serverDLL, "prev_MCGalaxy_.dll");
AtomicIO.TryMove("MCGalaxy.exe", "prev_MCGalaxy.exe");
AtomicIO.TryMove("MCGalaxyCLI.exe", "prev_MCGalaxyCLI.exe");
AtomicIO.TryMove(serverDLL, "prev_MCGalaxy_.dll");
AtomicIO.TryMove(serverGUI, "prev_MCGalaxy.exe");
AtomicIO.TryMove(serverCLI, "prev_MCGalaxyCLI.exe");

// Move update files to current files
AtomicIO.TryMove("MCGalaxy_.update", serverDLL);
AtomicIO.TryMove("MCGalaxy.update", "MCGalaxy.exe");
AtomicIO.TryMove("MCGalaxyCLI.update", "MCGalaxyCLI.exe");
AtomicIO.TryMove("MCGalaxy.update", serverGUI);
AtomicIO.TryMove("MCGalaxyCLI.update", serverCLI);

Server.Stop(true, "Updating server.");
} catch (Exception ex) {
Expand Down
10 changes: 5 additions & 5 deletions MCGalaxy/Server/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public sealed partial class Server
/// <summary> Returns the full path to the server core DLL </summary>
public static string GetServerDLLPath() {
#if MCG_STANDALONE
return GetRuntimeProcessExePath();
return GetRuntimeExePath();
#else
return Assembly.GetExecutingAssembly().Location;
#endif
Expand All @@ -272,14 +272,14 @@ public sealed partial class Server
/// <summary> Returns the full path to the server executable </summary>
public static string GetServerExePath() {
#if MCG_STANDALONE
return GetRuntimeProcessExePath();
return GetRuntimeExePath();
#else
return DotNetBackend.GetExePath(RestartPath);
return RestartPath;
#endif
}

/// <summary> Returns the full path to the runtime executable path </summary>
public static string GetRuntimeProcessExePath() {
/// <summary> Returns the full path to the runtime executable </summary>
public static string GetRuntimeExePath() {
return Process.GetCurrentProcess().MainModule.FileName;
}

Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/util/DotnetBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static class DotNetBackend

public static string GetExePath(string path) {
// NET core/5/6 executables tend to use the following structure:
// MCGalaxyCLI_core --> MCGalaxyCLI_core.dll
// MCGalaxyCLI --> MCGalaxyCLI.dll
// in this case, 'RestartPath' will include '.dll' since this file
// is actually the managed assembly, but we need to remove '.dll'
// as the actual executable which must be started is the non .dll file
Expand Down
19 changes: 12 additions & 7 deletions MCGalaxy/util/OperatingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ public abstract class IOperatingSystem
/// <summary> Attempts to restart the current process </summary>
/// <remarks> Does not return if the restart is performed in-place
/// (since the current process image is replaced) </remarks>
public virtual void RestartProcess() {
Process.Start(Server.GetServerExePath());
public virtual void RestartProcess() {
string path = Server.GetServerExePath();
string exe = DotNetBackend.GetExePath(path);

Process.Start(exe);
}


Expand Down Expand Up @@ -179,13 +182,15 @@ class UnixOS : IOperatingSystem

// try to exec using actual runtime path first
// e.g. /usr/bin/mono-sgen, /home/test/.dotnet/dotnet
string exe = Server.GetRuntimeProcessExePath();
execvp(exe, new string[] { exe, Server.RestartPath, null });
Console.WriteLine("execvp {0} failed: {1}", exe, Marshal.GetLastWin32Error());
string runtime = Server.GetRuntimeExePath();
string exePath = Server.GetServerExePath();

execvp(runtime, new string[] { runtime, exePath, null });
Console.WriteLine("execvp {0} failed: {1}", runtime, Marshal.GetLastWin32Error());

#if !MCG_DOTNET
// .. and fallback to mono if that doesn't work for some reason
execvp("mono", new string[] { "mono", Server.RestartPath, null });
execvp("mono", new string[] { "mono", exePath, null });
Console.WriteLine("execvp mono failed: {0}", Marshal.GetLastWin32Error());
#endif
}
Expand Down Expand Up @@ -265,7 +270,7 @@ class LinuxOS : UnixOS
try {
// try to restart using process's original command line arguments so that they are preserved
// e.g. for "mono --debug MCGalaxyCLI.exe"
string exe = Server.GetRuntimeProcessExePath();
string exe = Server.GetRuntimeExePath();
string[] args = GetProcessCommandLineArgs();
execvp(exe, args);
} catch (Exception ex) {
Expand Down

0 comments on commit dd8ff42

Please sign in to comment.