diff --git a/OpenDreamPackaging/Program.cs b/OpenDreamPackaging/Program.cs index 8b660aad4b..9bba242173 100644 --- a/OpenDreamPackaging/Program.cs +++ b/OpenDreamPackaging/Program.cs @@ -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 = { @@ -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; @@ -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 = @@ -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; } diff --git a/OpenDreamPackaging/ServerPackaging.cs b/OpenDreamPackaging/ServerPackaging.cs index acb410c557..a9bc099baa 100644 --- a/OpenDreamPackaging/ServerPackaging.cs +++ b/OpenDreamPackaging/ServerPackaging.cs @@ -70,6 +70,11 @@ public static class ServerPackaging { public static void Package(Program.ServerOptions options) { IEnumerable 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); @@ -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")); } } diff --git a/OpenDreamPackaging/TgsPackaging.cs b/OpenDreamPackaging/TgsPackaging.cs new file mode 100644 index 0000000000..702b8533ca --- /dev/null +++ b/OpenDreamPackaging/TgsPackaging.cs @@ -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 /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 /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" + } + }); + } +}