Skip to content

Commit

Permalink
Add a TGS package option
Browse files Browse the repository at this point in the history
  • Loading branch information
wixoaGit committed Oct 16, 2023
1 parent 43c1b95 commit c5d8ad5
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 7 deletions.
60 changes: 60 additions & 0 deletions OpenDreamPackaging/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ public class Options {
public class ServerOptions : Options {
public PlatformReg? Platform;
public bool HybridAcz;
public bool InPlatformSubDir = true;
public bool TgsEngineBuild;
}

public class ClientOptions : Options {
public PlatformReg? Platform;
}

public class TgsOptions : Options {
public PlatformReg? Platform;
}

public static readonly string[] SharedIgnoredResources = {
Expand All @@ -35,6 +41,9 @@ public static int Main(string[] args) {
case ClientOptions clientOptions:
ClientPackaging.Package(clientOptions);
break;
case TgsOptions tgsOptions:
TgsPackaging.Package(tgsOptions);
break;
}

return 0;
Expand Down Expand Up @@ -103,6 +112,11 @@ private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options?
break;
case "--platform":
case "-p":
if (i + 1 >= args.Length) {
Console.Error.WriteLine("No platform given");
return false;
}

var platformRId = args[++i];

serverOptions.Platform =
Expand Down Expand Up @@ -146,6 +160,52 @@ private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options?
}
}

return true;
} else if (args.Contains("--tgs")) {
var tgsOptions = new TgsOptions();

options = tgsOptions;
for (int i = 0; i < args.Length; i++) {
var arg = args[i];

switch (arg) {
case "--tgs":
break;
case "--output":
case "-o":
tgsOptions.OutputDir = args[++i];
break;
case "--skip-build":
tgsOptions.SkipBuild = true;
break;
case "--platform":
case "-p":
if (i + 1 >= args.Length) {
Console.Error.WriteLine("No platform given");
return false;
}

var platformRId = args[++i];

tgsOptions.Platform =
ServerPackaging.Platforms.First(p => p.RId == platformRId);
if (tgsOptions.Platform == null) {
Console.Error.WriteLine($"Invalid platform '{platformRId}'");
return false;
}

break;
default:
Console.Error.WriteLine($"Unknown argument '{arg}'");
return false;
}
}

if (tgsOptions.Platform == null) {
Console.Error.WriteLine("A '--platform' argument is required for a tgs package");
return false;
}

return true;
}

Expand Down
22 changes: 15 additions & 7 deletions OpenDreamPackaging/ServerPackaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public static class ServerPackaging {
public static void Package(Program.ServerOptions options) {
IEnumerable<PlatformReg> platforms = (options.Platform != null) ? new[] {options.Platform} : PlatformsDefault;

if (!options.InPlatformSubDir && options.Platform == null) {
Console.Error.WriteLine(
"Packaging the server without a platform subdirectory requires selecting a single platform");
}

if (Directory.Exists(options.OutputDir)) {
Console.WriteLine($"Cleaning old release packages ({options.OutputDir})...");
Directory.Delete(options.OutputDir, true);
Expand Down Expand Up @@ -108,23 +113,26 @@ private static void BuildPlatform(PlatformReg platform, Program.ServerOptions op
$"/p:TargetOS={platform.TargetOs}",
"/t:Rebuild",
"/p:FullRelease=True",
"/m"
"/m",
$"/p:TgsEngineBuild={(options.TgsEngineBuild ? "True" : "False")}"
}
});

PublishClientServer(platform.RId, platform.TargetOs);
}

DirectoryInfo releaseDir = new DirectoryInfo(Path.Combine(options.OutputDir, $"OpenDream.Server_{platform.RId}"));
string releaseDir = options.OutputDir;
if (options.InPlatformSubDir)
releaseDir = Path.Combine(releaseDir, $"OpenDream.Server_{platform.RId}");

Console.WriteLine($"Packaging {platform.RId} server...");
releaseDir.Create();
Program.CopyDirectory($"RobustToolbox/bin/Server/{platform.RId}/publish", releaseDir.FullName, BinSkipFolders);
CopyResources(Path.Combine(releaseDir.FullName, "Resources"));
CopyContentAssemblies(Path.Combine(releaseDir.FullName, "Resources", "Assemblies"));
Directory.CreateDirectory(releaseDir);
Program.CopyDirectory($"RobustToolbox/bin/Server/{platform.RId}/publish", releaseDir, BinSkipFolders);
CopyResources(Path.Combine(releaseDir, "Resources"));
CopyContentAssemblies(Path.Combine(releaseDir, "Resources", "Assemblies"));
if (options.HybridAcz) {
// Hybrid ACZ expects "Content.Client.zip" (as it's not OpenDream-specific)
ZipFile.CreateFromDirectory(Path.Combine(options.OutputDir, "OpenDream.Client"), Path.Combine(releaseDir.FullName, "Content.Client.Zip"));
ZipFile.CreateFromDirectory(Path.Combine(options.OutputDir, "OpenDream.Client"), Path.Combine(releaseDir, "Content.Client.Zip"));
}
}

Expand Down
59 changes: 59 additions & 0 deletions OpenDreamPackaging/TgsPackaging.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Diagnostics;

namespace OpenDreamPackaging;

public static class TgsPackaging {
public static void Package(Program.TgsOptions options) {
if (Directory.Exists(options.OutputDir)) {
Console.WriteLine($"Cleaning old release packages ({options.OutputDir})...");
Directory.Delete(options.OutputDir, true);
}

// Package the server to <output dir>/bin/server
ServerPackaging.Package(new Program.ServerOptions {
OutputDir = Path.Combine(options.OutputDir, "bin", "server"),
Platform = options.Platform,
HybridAcz = true, // Force Hybrid ACZ with TGS
SkipBuild = options.SkipBuild,
InPlatformSubDir = false,
TgsEngineBuild = true
});

var platform = options.Platform!;
if (!options.SkipBuild) {
Program.RunSubProcess(new ProcessStartInfo {
FileName = "dotnet",
ArgumentList = {
"build",
"DMCompiler/DMCompiler.csproj",
"-c", "Release",
"--nologo",
"/v:m",
$"/p:TargetOS={platform.TargetOs}",
"/t:Rebuild",
"/m"
}
});

PublishCompiler(platform.RId, platform.TargetOs);
}

// Package the compiler to <output dir>/bin/compiler
Program.CopyDirectory($"bin/DMCompiler/{platform.RId}/publish", Path.Combine(options.OutputDir, "bin", "compiler"));
}

private static void PublishCompiler(string platformRId, string targetOs) {
Program.RunSubProcess(new ProcessStartInfo {
FileName = "dotnet",
ArgumentList = {
"publish",
"DMCompiler/DMCompiler.csproj",
"--runtime", platformRId,
"--no-self-contained",
"-c", "Release",
$"/p:TargetOS={targetOs}",
"/m"
}
});
}
}

0 comments on commit c5d8ad5

Please sign in to comment.