From 43c1b95f3fe3a0966ac3f042924243c54b322ea2 Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Mon, 16 Oct 2023 15:37:07 -0400 Subject: [PATCH 1/9] Rewrite the package scripts in C# --- .gitignore | 1 + OpenDreamPackaging/ClientPackaging.cs | 89 +++++++++++++ OpenDreamPackaging/PlatformReg.cs | 7 + OpenDreamPackaging/Program.cs | 153 ++++++++++++++++++++- OpenDreamPackaging/ServerPackaging.cs | 184 ++++++++++++++++++++++++++ 5 files changed, 432 insertions(+), 2 deletions(-) create mode 100644 OpenDreamPackaging/ClientPackaging.cs create mode 100644 OpenDreamPackaging/PlatformReg.cs create mode 100644 OpenDreamPackaging/ServerPackaging.cs diff --git a/.gitignore b/.gitignore index cffdfda247..e1634ea096 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ [Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ +release/ x64/ x86/ bld/ diff --git a/OpenDreamPackaging/ClientPackaging.cs b/OpenDreamPackaging/ClientPackaging.cs new file mode 100644 index 0000000000..532832fe65 --- /dev/null +++ b/OpenDreamPackaging/ClientPackaging.cs @@ -0,0 +1,89 @@ +using System.Diagnostics; + +namespace OpenDreamPackaging; + +public static class ClientPackaging { + private static readonly string[] ClientIgnoredResources = { + "Maps", + "emotes.xml", + "Groups", + "engineCommandPerms.yml", + "clientCommandPerms.yml" + }; + + private static readonly string[] ClientContentAssemblies = { + "OpenDreamClient", + "OpenDreamShared" + }; + + public static void Package(Program.ClientOptions options) { + Directory.CreateDirectory(options.OutputDir); + + if (!options.SkipBuild) + WipeBin(); + + Build(options); + } + + private static void WipeBin() { + Console.WriteLine("Clearing old build artifacts (if any)..."); + + Directory.Delete("bin", true); + } + + private static void Build(Program.ClientOptions options) { + Console.WriteLine("Building project..."); + + if (!options.SkipBuild) { + Program.RunSubProcess(new ProcessStartInfo { + FileName = "dotnet", + ArgumentList = { + "build", + "OpenDreamClient/OpenDreamClient.csproj", + "-c", "Release", + "--nologo", + "/v:m", + "/t:Rebuild", + "/p:FullRelease=True", + "/m" + } + }); + } + + DirectoryInfo releaseDir = new DirectoryInfo(Path.Combine(options.OutputDir, "OpenDream.Client")); + + Console.WriteLine("Packaging client..."); + releaseDir.Create(); + CopyResources(releaseDir.FullName); + CopyContentAssemblies(Path.Combine(releaseDir.FullName, "Assemblies")); + } + + private static void CopyResources(string dest) { + var ignoreSet = Program.SharedIgnoredResources.Union(ClientIgnoredResources).ToArray(); + + Program.CopyDirectory("Resources", dest, ignoreSet); + } + + private static void CopyContentAssemblies(string dest) { + List files = new(); + string sourceDir = Path.Combine("bin", "Content.Client"); + string[] baseAssemblies = ClientContentAssemblies; + + // Include content assemblies. + foreach (var assembly in baseAssemblies) { + files.Add(assembly + ".dll"); + + // If PDB available, include it as well. + var pdbPath = assembly + ".pdb"; + if (File.Exists(Path.Combine(sourceDir, pdbPath))) + files.Add(pdbPath); + } + + // Create assemblies dir if necessary. + Directory.CreateDirectory(dest); + + foreach (var file in files) { + File.Copy(Path.Combine(sourceDir, file), Path.Combine(dest, file)); + } + } +} diff --git a/OpenDreamPackaging/PlatformReg.cs b/OpenDreamPackaging/PlatformReg.cs new file mode 100644 index 0000000000..e75e7549f8 --- /dev/null +++ b/OpenDreamPackaging/PlatformReg.cs @@ -0,0 +1,7 @@ +namespace OpenDreamPackaging; + +public record PlatformReg(string RId, string TargetOs, bool BuildByDefault) { + public string RId = RId; + public string TargetOs = TargetOs; + public bool BuildByDefault = BuildByDefault; +} diff --git a/OpenDreamPackaging/Program.cs b/OpenDreamPackaging/Program.cs index 4c63beb151..8b660aad4b 100644 --- a/OpenDreamPackaging/Program.cs +++ b/OpenDreamPackaging/Program.cs @@ -1,7 +1,156 @@ +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + namespace OpenDreamPackaging; public static class Program { - public static void Main() { - throw new NotImplementedException(); + public class Options { + public string OutputDir = "release/"; + public bool SkipBuild; + } + + public class ServerOptions : Options { + public PlatformReg? Platform; + public bool HybridAcz; + } + + public class ClientOptions : Options { + + } + + public static readonly string[] SharedIgnoredResources = { + ".gitignore", + ".directory", + ".DS_Store" + }; + + public static int Main(string[] args) { + if (!TryParseArgs(args, out var options)) + return 1; + + switch (options) { + case ServerOptions serverOptions: + ServerPackaging.Package(serverOptions); + break; + case ClientOptions clientOptions: + ClientPackaging.Package(clientOptions); + break; + } + + return 0; + } + + public static void RunSubProcess(ProcessStartInfo startInfo) { + using Process process = new(); + + process.StartInfo = startInfo; + process.OutputDataReceived += ProcessOutputDataReceived; + process.Start(); + process.WaitForExit(); + if (process.ExitCode != 0) { + Environment.Exit(process.ExitCode); + } + } + + public static void CopyDirectory(string src, string dest, string[]? skip = null) { + skip ??= Array.Empty(); + + var srcDir = new DirectoryInfo(src); + if (!srcDir.Exists) + throw new Exception($"Source directory not found: {src}"); + + Directory.CreateDirectory(dest); + + foreach (var file in srcDir.EnumerateFiles()) { + if (skip.Contains(file.Name)) + continue; + + file.CopyTo(Path.Combine(dest, file.Name)); + } + + foreach (var subDir in srcDir.EnumerateDirectories()) { + if (skip.Contains(subDir.Name)) + continue; + + CopyDirectory(subDir.FullName, Path.Combine(dest, subDir.Name)); + } + } + + private static void ProcessOutputDataReceived(object sender, DataReceivedEventArgs args) { + if (args.Data == null) + return; + + Console.Write(args.Data); + } + + private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options? options) { + if (args.Contains("--server")) { + var serverOptions = new ServerOptions(); + + options = serverOptions; + for (int i = 0; i < args.Length; i++) { + var arg = args[i]; + + switch (arg) { + case "--server": + break; + case "--output": + case "-o": + serverOptions.OutputDir = args[++i]; + break; + case "--skip-build": + serverOptions.SkipBuild = true; + break; + case "--platform": + case "-p": + var platformRId = args[++i]; + + serverOptions.Platform = + ServerPackaging.Platforms.First(p => p.RId == platformRId); + if (serverOptions.Platform == null) { + Console.Error.WriteLine($"Invalid platform '{platformRId}'"); + return false; + } + + break; + case "--hybrid-acz": + serverOptions.HybridAcz = true; + break; + default: + Console.Error.WriteLine($"Unknown argument '{arg}'"); + return false; + } + } + + return true; + } else if (args.Contains("--client")) { + var clientOptions = new ClientOptions(); + + options = clientOptions; + for (int i = 0; i < args.Length; i++) { + var arg = args[i]; + + switch (arg) { + case "--client": + break; + case "--output": + case "-o": + clientOptions.OutputDir = args[++i]; + break; + case "--skip-build": + clientOptions.SkipBuild = true; + break; + default: + Console.Error.WriteLine($"Unknown argument '{arg}'"); + return false; + } + } + + return true; + } + + options = null; + Console.Error.WriteLine("One of '--server' or '--client' must be given"); + return false; } } diff --git a/OpenDreamPackaging/ServerPackaging.cs b/OpenDreamPackaging/ServerPackaging.cs new file mode 100644 index 0000000000..acb410c557 --- /dev/null +++ b/OpenDreamPackaging/ServerPackaging.cs @@ -0,0 +1,184 @@ +using System.Diagnostics; +using System.IO.Compression; + +namespace OpenDreamPackaging; + +public static class ServerPackaging { + public static readonly PlatformReg[] Platforms = { + new("win-x64", "Windows", true), + new("linux-x64", "Linux", true), + new("linux-arm64", "Linux", true), + new("osx-x64", "MacOS", true), + + // Non-default platforms (i.e. for Watchdog Git) + new("win-x86", "Windows", false), + new("linux-x86", "Linux", false), + new("linux-arm", "Linux", false), + }; + + private static readonly string[] ServerIgnoredResources = { + "Textures", + "Fonts", + "Audio", + "Shaders" + }; + + // Assembly names to copy from content. + // PDBs are included if available, .dll/.pdb appended automatically. + private static readonly string[] ServerContentAssemblies = { + "OpenDreamServer", + "OpenDreamShared", + "OpenDreamRuntime", + "Byond.TopicSender", + "DMCompiler" + }; + + // Extra assemblies to copy on the server, with a startswith + private static readonly string[] ServerExtraAssemblies = { + "OpenDreamServer", + "OpenDreamShared", + "OpenDreamRuntime", + "Byond.TopicSender", + "DMCompiler" + }; + + private static readonly string[] ServerNotExtraAssemblies = { + "Microsoft.CodeAnalysis" + }; + + private static readonly string[] BinSkipFolders = { + // Roslyn localization files, screw em. + "cs", + "de", + "es", + "fr", + "it", + "ja", + "ko", + "pl", + "pt-BR", + "ru", + "tr", + "zh-Hans", + "zh-Hant" + }; + + public static IEnumerable PlatformRIds => Platforms.Select(platform => platform.RId); + + public static IEnumerable PlatformsDefault => Platforms.Where(platform => platform.BuildByDefault); + + public static void Package(Program.ServerOptions options) { + IEnumerable platforms = (options.Platform != null) ? new[] {options.Platform} : PlatformsDefault; + + if (Directory.Exists(options.OutputDir)) { + Console.WriteLine($"Cleaning old release packages ({options.OutputDir})..."); + Directory.Delete(options.OutputDir, true); + } + + Directory.CreateDirectory(options.OutputDir); + + if (options.HybridAcz) { + // Hybrid ACZ involves a file "Content.Client.zip" in the server executable directory. + // Rather than hosting the client ZIP on the watchdog or on a separate server, + // Hybrid ACZ uses the ACZ hosting functionality to host it as part of the status host, + // which means that features such as automatic UPnP forwarding still work properly. + ClientPackaging.Package(new Program.ClientOptions { + OutputDir = options.OutputDir, + SkipBuild = options.SkipBuild + }); + } + + foreach (var platform in platforms) { + BuildPlatform(platform, options); + } + } + + private static void BuildPlatform(PlatformReg platform, Program.ServerOptions options) { + Console.WriteLine($"Building project for {platform.RId}"); + + if (!options.SkipBuild) { + Program.RunSubProcess(new ProcessStartInfo { + FileName = "dotnet", + ArgumentList = { + "build", + "OpenDreamServer/OpenDreamServer.csproj", + "-c", "Release", + "--nologo", + "/v:m", + $"/p:TargetOS={platform.TargetOs}", + "/t:Rebuild", + "/p:FullRelease=True", + "/m" + } + }); + + PublishClientServer(platform.RId, platform.TargetOs); + } + + DirectoryInfo releaseDir = new DirectoryInfo(Path.Combine(options.OutputDir, $"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")); + 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")); + } + } + + private static void PublishClientServer(string platformRId, string targetOs) { + Program.RunSubProcess(new ProcessStartInfo { + FileName = "dotnet", + ArgumentList = { + "publish", + "RobustToolbox/Robust.Server/Robust.Server.csproj", + "--runtime", platformRId, + "--no-self-contained", + "-c", "Release", + $"/p:TargetOS={targetOs}", + "/p:FullRelease=True", + "/m" + } + }); + } + + private static void CopyResources(string dest) { + // Content repo goes FIRST so that it won't override engine files as that's forbidden. + var ignoreSet = Program.SharedIgnoredResources.Union(ServerIgnoredResources).ToArray(); + + Program.CopyDirectory("Resources", dest, ignoreSet); + Program.CopyDirectory("RobustToolbox/Resources", dest, ignoreSet); + } + + private static void CopyContentAssemblies(string dest) { + List files = new(); + string sourceDir = Path.Combine("bin", "Content.Server"); + string[] baseAssemblies = ServerContentAssemblies; + + // Additional assemblies that need to be copied such as EFCore. + foreach (var filename in Directory.EnumerateFiles(sourceDir)) { + if (ServerExtraAssemblies.Any(assembly => filename.StartsWith(assembly)) && + !ServerNotExtraAssemblies.Any(assembly => filename.StartsWith(assembly))) + files.Add(filename); + } + + // Include content assemblies. + foreach (var assembly in baseAssemblies) { + files.Add(assembly + ".dll"); + + // If PDB available, include it as well. + var pdbPath = assembly + ".pdb"; + if (File.Exists(Path.Combine(sourceDir, pdbPath))) + files.Add(pdbPath); + } + + // Create assemblies dir if necessary. + Directory.CreateDirectory(dest); + + foreach (var file in files) { + File.Copy(Path.Combine(sourceDir, file), Path.Combine(dest, file)); + } + } +} From c5d8ad56303c29eefaadd7feab2ac73eb363943c Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Mon, 16 Oct 2023 16:32:27 -0400 Subject: [PATCH 2/9] Add a TGS package option --- OpenDreamPackaging/Program.cs | 60 +++++++++++++++++++++++++++ OpenDreamPackaging/ServerPackaging.cs | 22 ++++++---- OpenDreamPackaging/TgsPackaging.cs | 59 ++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 OpenDreamPackaging/TgsPackaging.cs 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" + } + }); + } +} From 7bb3985e1238d757451cfaff17600053c9de0e89 Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Thu, 19 Oct 2023 22:51:40 -0400 Subject: [PATCH 3/9] Move to a new `OpenDreamPackageTool` project Ran into file locking issues with OpenDreamPackaging as a dependency --- OpenDream.sln | 13 ++ .../ClientPackaging.cs | 2 +- .../PlatformReg.cs | 2 +- .../ServerPackaging.cs | 2 +- .../TgsPackaging.cs | 2 +- OpenDreamPackaging/Program.cs | 213 +----------------- 6 files changed, 19 insertions(+), 215 deletions(-) rename {OpenDreamPackaging => OpenDreamPackageTool}/ClientPackaging.cs (98%) rename {OpenDreamPackaging => OpenDreamPackageTool}/PlatformReg.cs (86%) rename {OpenDreamPackaging => OpenDreamPackageTool}/ServerPackaging.cs (99%) rename {OpenDreamPackaging => OpenDreamPackageTool}/TgsPackaging.cs (98%) diff --git a/OpenDream.sln b/OpenDream.sln index bc0d5a7dd3..7c81824472 100644 --- a/OpenDream.sln +++ b/OpenDream.sln @@ -99,6 +99,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenDreamPackaging", "OpenD EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Robust.Serialization.Generator", "RobustToolbox\Robust.Serialization.Generator\Robust.Serialization.Generator.csproj", "{366AA569-0889-491B-AB00-F038EAEC5221}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenDreamPackageTool", "OpenDreamPackageTool\OpenDreamPackageTool.csproj", "{351729DE-F70D-4136-AD48-1E08A715C1B1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -428,6 +430,16 @@ Global {366AA569-0889-491B-AB00-F038EAEC5221}.Release|x64.Build.0 = Release|Any CPU {366AA569-0889-491B-AB00-F038EAEC5221}.Tools|Any CPU.ActiveCfg = Debug|Any CPU {366AA569-0889-491B-AB00-F038EAEC5221}.Tools|Any CPU.Build.0 = Debug|Any CPU + {351729DE-F70D-4136-AD48-1E08A715C1B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {351729DE-F70D-4136-AD48-1E08A715C1B1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {351729DE-F70D-4136-AD48-1E08A715C1B1}.Debug|x64.ActiveCfg = Debug|Any CPU + {351729DE-F70D-4136-AD48-1E08A715C1B1}.Debug|x64.Build.0 = Debug|Any CPU + {351729DE-F70D-4136-AD48-1E08A715C1B1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {351729DE-F70D-4136-AD48-1E08A715C1B1}.Release|Any CPU.Build.0 = Release|Any CPU + {351729DE-F70D-4136-AD48-1E08A715C1B1}.Release|x64.ActiveCfg = Release|Any CPU + {351729DE-F70D-4136-AD48-1E08A715C1B1}.Release|x64.Build.0 = Release|Any CPU + {351729DE-F70D-4136-AD48-1E08A715C1B1}.Tools|Any CPU.ActiveCfg = Debug|Any CPU + {351729DE-F70D-4136-AD48-1E08A715C1B1}.Tools|Any CPU.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -459,6 +471,7 @@ Global {CBF4EBB8-A6A0-446F-82D4-B1D24FF5B3FF} = {534AFACE-24AF-4F54-B7B0-951C5D62DF34} {F3735A7F-44A2-4BEE-ADD6-952577D4DC33} = {DBFD7471-84E2-4AAB-86E9-F8DFF917ED5B} {D080D3FA-CE53-40D2-AC9A-940FD9EB5055} = {DBFD7471-84E2-4AAB-86E9-F8DFF917ED5B} + {366AA569-0889-491B-AB00-F038EAEC5221} = {DBFD7471-84E2-4AAB-86E9-F8DFF917ED5B} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {970174FD-D22D-44D9-A410-F82A015E6F74} diff --git a/OpenDreamPackaging/ClientPackaging.cs b/OpenDreamPackageTool/ClientPackaging.cs similarity index 98% rename from OpenDreamPackaging/ClientPackaging.cs rename to OpenDreamPackageTool/ClientPackaging.cs index 532832fe65..55e8fa6537 100644 --- a/OpenDreamPackaging/ClientPackaging.cs +++ b/OpenDreamPackageTool/ClientPackaging.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace OpenDreamPackaging; +namespace OpenDreamPackageTool; public static class ClientPackaging { private static readonly string[] ClientIgnoredResources = { diff --git a/OpenDreamPackaging/PlatformReg.cs b/OpenDreamPackageTool/PlatformReg.cs similarity index 86% rename from OpenDreamPackaging/PlatformReg.cs rename to OpenDreamPackageTool/PlatformReg.cs index e75e7549f8..baf7524b9c 100644 --- a/OpenDreamPackaging/PlatformReg.cs +++ b/OpenDreamPackageTool/PlatformReg.cs @@ -1,4 +1,4 @@ -namespace OpenDreamPackaging; +namespace OpenDreamPackageTool; public record PlatformReg(string RId, string TargetOs, bool BuildByDefault) { public string RId = RId; diff --git a/OpenDreamPackaging/ServerPackaging.cs b/OpenDreamPackageTool/ServerPackaging.cs similarity index 99% rename from OpenDreamPackaging/ServerPackaging.cs rename to OpenDreamPackageTool/ServerPackaging.cs index a9bc099baa..124b8b84b4 100644 --- a/OpenDreamPackaging/ServerPackaging.cs +++ b/OpenDreamPackageTool/ServerPackaging.cs @@ -1,7 +1,7 @@ using System.Diagnostics; using System.IO.Compression; -namespace OpenDreamPackaging; +namespace OpenDreamPackageTool; public static class ServerPackaging { public static readonly PlatformReg[] Platforms = { diff --git a/OpenDreamPackaging/TgsPackaging.cs b/OpenDreamPackageTool/TgsPackaging.cs similarity index 98% rename from OpenDreamPackaging/TgsPackaging.cs rename to OpenDreamPackageTool/TgsPackaging.cs index 702b8533ca..4e4ac96024 100644 --- a/OpenDreamPackaging/TgsPackaging.cs +++ b/OpenDreamPackageTool/TgsPackaging.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace OpenDreamPackaging; +namespace OpenDreamPackageTool; public static class TgsPackaging { public static void Package(Program.TgsOptions options) { diff --git a/OpenDreamPackaging/Program.cs b/OpenDreamPackaging/Program.cs index 9bba242173..4c63beb151 100644 --- a/OpenDreamPackaging/Program.cs +++ b/OpenDreamPackaging/Program.cs @@ -1,216 +1,7 @@ -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; - namespace OpenDreamPackaging; public static class Program { - public class Options { - public string OutputDir = "release/"; - public bool SkipBuild; - } - - 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 = { - ".gitignore", - ".directory", - ".DS_Store" - }; - - public static int Main(string[] args) { - if (!TryParseArgs(args, out var options)) - return 1; - - switch (options) { - case ServerOptions serverOptions: - ServerPackaging.Package(serverOptions); - break; - case ClientOptions clientOptions: - ClientPackaging.Package(clientOptions); - break; - case TgsOptions tgsOptions: - TgsPackaging.Package(tgsOptions); - break; - } - - return 0; - } - - public static void RunSubProcess(ProcessStartInfo startInfo) { - using Process process = new(); - - process.StartInfo = startInfo; - process.OutputDataReceived += ProcessOutputDataReceived; - process.Start(); - process.WaitForExit(); - if (process.ExitCode != 0) { - Environment.Exit(process.ExitCode); - } - } - - public static void CopyDirectory(string src, string dest, string[]? skip = null) { - skip ??= Array.Empty(); - - var srcDir = new DirectoryInfo(src); - if (!srcDir.Exists) - throw new Exception($"Source directory not found: {src}"); - - Directory.CreateDirectory(dest); - - foreach (var file in srcDir.EnumerateFiles()) { - if (skip.Contains(file.Name)) - continue; - - file.CopyTo(Path.Combine(dest, file.Name)); - } - - foreach (var subDir in srcDir.EnumerateDirectories()) { - if (skip.Contains(subDir.Name)) - continue; - - CopyDirectory(subDir.FullName, Path.Combine(dest, subDir.Name)); - } - } - - private static void ProcessOutputDataReceived(object sender, DataReceivedEventArgs args) { - if (args.Data == null) - return; - - Console.Write(args.Data); - } - - private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options? options) { - if (args.Contains("--server")) { - var serverOptions = new ServerOptions(); - - options = serverOptions; - for (int i = 0; i < args.Length; i++) { - var arg = args[i]; - - switch (arg) { - case "--server": - break; - case "--output": - case "-o": - serverOptions.OutputDir = args[++i]; - break; - case "--skip-build": - serverOptions.SkipBuild = true; - break; - case "--platform": - case "-p": - if (i + 1 >= args.Length) { - Console.Error.WriteLine("No platform given"); - return false; - } - - var platformRId = args[++i]; - - serverOptions.Platform = - ServerPackaging.Platforms.First(p => p.RId == platformRId); - if (serverOptions.Platform == null) { - Console.Error.WriteLine($"Invalid platform '{platformRId}'"); - return false; - } - - break; - case "--hybrid-acz": - serverOptions.HybridAcz = true; - break; - default: - Console.Error.WriteLine($"Unknown argument '{arg}'"); - return false; - } - } - - return true; - } else if (args.Contains("--client")) { - var clientOptions = new ClientOptions(); - - options = clientOptions; - for (int i = 0; i < args.Length; i++) { - var arg = args[i]; - - switch (arg) { - case "--client": - break; - case "--output": - case "-o": - clientOptions.OutputDir = args[++i]; - break; - case "--skip-build": - clientOptions.SkipBuild = true; - break; - default: - Console.Error.WriteLine($"Unknown argument '{arg}'"); - return false; - } - } - - 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; - } - - options = null; - Console.Error.WriteLine("One of '--server' or '--client' must be given"); - return false; + public static void Main() { + throw new NotImplementedException(); } } From 763c84db6004dc4b0869c2595a26a0e48375f927 Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Thu, 19 Oct 2023 22:54:48 -0400 Subject: [PATCH 4/9] Use RT's `ProcessHelpers.RunCheck()` helper --- OpenDreamPackageTool/ClientPackaging.cs | 5 +++-- OpenDreamPackageTool/ServerPackaging.cs | 9 +++++---- OpenDreamPackageTool/TgsPackaging.cs | 9 +++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/OpenDreamPackageTool/ClientPackaging.cs b/OpenDreamPackageTool/ClientPackaging.cs index 55e8fa6537..b813dbc265 100644 --- a/OpenDreamPackageTool/ClientPackaging.cs +++ b/OpenDreamPackageTool/ClientPackaging.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using Robust.Packaging.Utility; namespace OpenDreamPackageTool; @@ -35,7 +36,7 @@ private static void Build(Program.ClientOptions options) { Console.WriteLine("Building project..."); if (!options.SkipBuild) { - Program.RunSubProcess(new ProcessStartInfo { + ProcessHelpers.RunCheck(new ProcessStartInfo { FileName = "dotnet", ArgumentList = { "build", @@ -47,7 +48,7 @@ private static void Build(Program.ClientOptions options) { "/p:FullRelease=True", "/m" } - }); + }).Wait(); } DirectoryInfo releaseDir = new DirectoryInfo(Path.Combine(options.OutputDir, "OpenDream.Client")); diff --git a/OpenDreamPackageTool/ServerPackaging.cs b/OpenDreamPackageTool/ServerPackaging.cs index 124b8b84b4..fdc83c4023 100644 --- a/OpenDreamPackageTool/ServerPackaging.cs +++ b/OpenDreamPackageTool/ServerPackaging.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using System.IO.Compression; +using Robust.Packaging.Utility; namespace OpenDreamPackageTool; @@ -102,7 +103,7 @@ private static void BuildPlatform(PlatformReg platform, Program.ServerOptions op Console.WriteLine($"Building project for {platform.RId}"); if (!options.SkipBuild) { - Program.RunSubProcess(new ProcessStartInfo { + ProcessHelpers.RunCheck(new ProcessStartInfo { FileName = "dotnet", ArgumentList = { "build", @@ -116,7 +117,7 @@ private static void BuildPlatform(PlatformReg platform, Program.ServerOptions op "/m", $"/p:TgsEngineBuild={(options.TgsEngineBuild ? "True" : "False")}" } - }); + }).Wait(); PublishClientServer(platform.RId, platform.TargetOs); } @@ -137,7 +138,7 @@ private static void BuildPlatform(PlatformReg platform, Program.ServerOptions op } private static void PublishClientServer(string platformRId, string targetOs) { - Program.RunSubProcess(new ProcessStartInfo { + ProcessHelpers.RunCheck(new ProcessStartInfo { FileName = "dotnet", ArgumentList = { "publish", @@ -149,7 +150,7 @@ private static void PublishClientServer(string platformRId, string targetOs) { "/p:FullRelease=True", "/m" } - }); + }).Wait(); } private static void CopyResources(string dest) { diff --git a/OpenDreamPackageTool/TgsPackaging.cs b/OpenDreamPackageTool/TgsPackaging.cs index 4e4ac96024..cab39c5923 100644 --- a/OpenDreamPackageTool/TgsPackaging.cs +++ b/OpenDreamPackageTool/TgsPackaging.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using Robust.Packaging.Utility; namespace OpenDreamPackageTool; @@ -21,7 +22,7 @@ public static void Package(Program.TgsOptions options) { var platform = options.Platform!; if (!options.SkipBuild) { - Program.RunSubProcess(new ProcessStartInfo { + ProcessHelpers.RunCheck(new ProcessStartInfo { FileName = "dotnet", ArgumentList = { "build", @@ -33,7 +34,7 @@ public static void Package(Program.TgsOptions options) { "/t:Rebuild", "/m" } - }); + }).Wait(); PublishCompiler(platform.RId, platform.TargetOs); } @@ -43,7 +44,7 @@ public static void Package(Program.TgsOptions options) { } private static void PublishCompiler(string platformRId, string targetOs) { - Program.RunSubProcess(new ProcessStartInfo { + ProcessHelpers.RunCheck(new ProcessStartInfo { FileName = "dotnet", ArgumentList = { "publish", @@ -54,6 +55,6 @@ private static void PublishCompiler(string platformRId, string targetOs) { $"/p:TargetOS={targetOs}", "/m" } - }); + }).Wait(); } } From e2aa920feb385e3e4ecaac9655e9826c68acc05f Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Thu, 19 Oct 2023 22:55:36 -0400 Subject: [PATCH 5/9] Add missing files --- .../OpenDreamPackageTool.csproj | 14 ++ OpenDreamPackageTool/Program.cs | 196 ++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 OpenDreamPackageTool/OpenDreamPackageTool.csproj create mode 100644 OpenDreamPackageTool/Program.cs diff --git a/OpenDreamPackageTool/OpenDreamPackageTool.csproj b/OpenDreamPackageTool/OpenDreamPackageTool.csproj new file mode 100644 index 0000000000..469182ada8 --- /dev/null +++ b/OpenDreamPackageTool/OpenDreamPackageTool.csproj @@ -0,0 +1,14 @@ + + + + Exe + net7.0 + enable + enable + + + + + + + diff --git a/OpenDreamPackageTool/Program.cs b/OpenDreamPackageTool/Program.cs new file mode 100644 index 0000000000..2c56bc54e6 --- /dev/null +++ b/OpenDreamPackageTool/Program.cs @@ -0,0 +1,196 @@ +using System.Diagnostics.CodeAnalysis; + +namespace OpenDreamPackageTool; + +public static class Program { + public class Options { + public string OutputDir = "release/"; + public bool SkipBuild; + } + + 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 = { + ".gitignore", + ".directory", + ".DS_Store" + }; + + public static int Main(string[] args) { + if (!TryParseArgs(args, out var options)) + return 1; + + switch (options) { + case ServerOptions serverOptions: + ServerPackaging.Package(serverOptions); + break; + case ClientOptions clientOptions: + ClientPackaging.Package(clientOptions); + break; + case TgsOptions tgsOptions: + TgsPackaging.Package(tgsOptions); + break; + } + + return 0; + } + + public static void CopyDirectory(string src, string dest, string[]? skip = null) { + skip ??= Array.Empty(); + + var srcDir = new DirectoryInfo(src); + if (!srcDir.Exists) + throw new Exception($"Source directory not found: {src}"); + + Directory.CreateDirectory(dest); + + foreach (var file in srcDir.EnumerateFiles()) { + if (skip.Contains(file.Name)) + continue; + + file.CopyTo(Path.Combine(dest, file.Name)); + } + + foreach (var subDir in srcDir.EnumerateDirectories()) { + if (skip.Contains(subDir.Name)) + continue; + + CopyDirectory(subDir.FullName, Path.Combine(dest, subDir.Name)); + } + } + + private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options? options) { + if (args.Contains("--server")) { + var serverOptions = new ServerOptions(); + + options = serverOptions; + for (int i = 0; i < args.Length; i++) { + var arg = args[i]; + + switch (arg) { + case "--server": + break; + case "--output": + case "-o": + serverOptions.OutputDir = args[++i]; + break; + case "--skip-build": + serverOptions.SkipBuild = true; + break; + case "--platform": + case "-p": + if (i + 1 >= args.Length) { + Console.Error.WriteLine("No platform given"); + return false; + } + + var platformRId = args[++i]; + + serverOptions.Platform = + ServerPackaging.Platforms.First(p => p.RId == platformRId); + if (serverOptions.Platform == null) { + Console.Error.WriteLine($"Invalid platform '{platformRId}'"); + return false; + } + + break; + case "--hybrid-acz": + serverOptions.HybridAcz = true; + break; + default: + Console.Error.WriteLine($"Unknown argument '{arg}'"); + return false; + } + } + + return true; + } else if (args.Contains("--client")) { + var clientOptions = new ClientOptions(); + + options = clientOptions; + for (int i = 0; i < args.Length; i++) { + var arg = args[i]; + + switch (arg) { + case "--client": + break; + case "--output": + case "-o": + clientOptions.OutputDir = args[++i]; + break; + case "--skip-build": + clientOptions.SkipBuild = true; + break; + default: + Console.Error.WriteLine($"Unknown argument '{arg}'"); + return false; + } + } + + 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; + } + + options = null; + Console.Error.WriteLine("One of '--server' or '--client' must be given"); + return false; + } +} From b877680bff2d2a7471f6286a8f8ff1627427b6ac Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Thu, 19 Oct 2023 23:16:44 -0400 Subject: [PATCH 6/9] Assume `--platform` argument for TGS --- OpenDreamPackageTool/Program.cs | 44 ++++--------------------- OpenDreamPackageTool/ServerPackaging.cs | 21 ++++++++---- OpenDreamPackageTool/TgsPackaging.cs | 34 +++++++++++++++++-- 3 files changed, 54 insertions(+), 45 deletions(-) diff --git a/OpenDreamPackageTool/Program.cs b/OpenDreamPackageTool/Program.cs index 2c56bc54e6..5da86d3830 100644 --- a/OpenDreamPackageTool/Program.cs +++ b/OpenDreamPackageTool/Program.cs @@ -9,18 +9,18 @@ public class Options { } public class ServerOptions : Options { - public PlatformReg? Platform; + public string? 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; + // Avoid adding arguments for TGS, to give us more flexibility while keeping compatibility } public static readonly string[] SharedIgnoredResources = { @@ -97,21 +97,13 @@ private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options? return false; } - var platformRId = args[++i]; - - serverOptions.Platform = - ServerPackaging.Platforms.First(p => p.RId == platformRId); - if (serverOptions.Platform == null) { - Console.Error.WriteLine($"Invalid platform '{platformRId}'"); - return false; - } - + serverOptions.Platform = args[++i]; break; case "--hybrid-acz": serverOptions.HybridAcz = true; break; default: - Console.Error.WriteLine($"Unknown argument '{arg}'"); + Console.Error.WriteLine($"Invalid argument '{arg}'"); return false; } } @@ -135,7 +127,7 @@ private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options? clientOptions.SkipBuild = true; break; default: - Console.Error.WriteLine($"Unknown argument '{arg}'"); + Console.Error.WriteLine($"Invalid argument '{arg}'"); return false; } } @@ -157,35 +149,13 @@ private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options? 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}'"); + Console.Error.WriteLine($"Invalid 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/OpenDreamPackageTool/ServerPackaging.cs b/OpenDreamPackageTool/ServerPackaging.cs index fdc83c4023..5517f8ae10 100644 --- a/OpenDreamPackageTool/ServerPackaging.cs +++ b/OpenDreamPackageTool/ServerPackaging.cs @@ -5,7 +5,7 @@ namespace OpenDreamPackageTool; public static class ServerPackaging { - public static readonly PlatformReg[] Platforms = { + private static readonly PlatformReg[] Platforms = { new("win-x64", "Windows", true), new("linux-x64", "Linux", true), new("linux-arm64", "Linux", true), @@ -64,16 +64,17 @@ public static class ServerPackaging { "zh-Hant" }; - public static IEnumerable PlatformRIds => Platforms.Select(platform => platform.RId); - - public static IEnumerable PlatformsDefault => Platforms.Where(platform => platform.BuildByDefault); + private static IEnumerable PlatformsDefault => Platforms.Where(platform => platform.BuildByDefault); public static void Package(Program.ServerOptions options) { - IEnumerable platforms = (options.Platform != null) ? new[] {options.Platform} : PlatformsDefault; + IEnumerable platforms = PlatformsDefault; + if (options.Platform != null) { + platforms = new[] { GetPlatform(options.Platform) }; + } if (!options.InPlatformSubDir && options.Platform == null) { Console.Error.WriteLine( - "Packaging the server without a platform subdirectory requires selecting a single platform"); + "Packaging the server without a platform subdirectory requires a '--platform' argument"); } if (Directory.Exists(options.OutputDir)) { @@ -99,6 +100,14 @@ public static void Package(Program.ServerOptions options) { } } + public static PlatformReg GetPlatform(string rId) { + var platform = Platforms.FirstOrDefault(p => p.RId == rId); + if (platform == null) + throw new NotSupportedException($"Platform \"{rId}\" is not supported"); + + return platform; + } + private static void BuildPlatform(PlatformReg platform, Program.ServerOptions options) { Console.WriteLine($"Building project for {platform.RId}"); diff --git a/OpenDreamPackageTool/TgsPackaging.cs b/OpenDreamPackageTool/TgsPackaging.cs index cab39c5923..78a5a90894 100644 --- a/OpenDreamPackageTool/TgsPackaging.cs +++ b/OpenDreamPackageTool/TgsPackaging.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Runtime.InteropServices; using Robust.Packaging.Utility; namespace OpenDreamPackageTool; @@ -10,17 +11,18 @@ public static void Package(Program.TgsOptions options) { Directory.Delete(options.OutputDir, true); } + var platform = DeterminePlatform(); + // Package the server to /bin/server ServerPackaging.Package(new Program.ServerOptions { OutputDir = Path.Combine(options.OutputDir, "bin", "server"), - Platform = options.Platform, + Platform = platform.RId, HybridAcz = true, // Force Hybrid ACZ with TGS SkipBuild = options.SkipBuild, InPlatformSubDir = false, TgsEngineBuild = true }); - var platform = options.Platform!; if (!options.SkipBuild) { ProcessHelpers.RunCheck(new ProcessStartInfo { FileName = "dotnet", @@ -57,4 +59,32 @@ private static void PublishCompiler(string platformRId, string targetOs) { } }).Wait(); } + + /// + /// Determine what platform to package for, based on what OS we're currently running on + /// + /// The platform + private static PlatformReg DeterminePlatform() { + string rId; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { + rId = "win"; + } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { + rId = "linux"; + } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { + rId = "osx"; + } else { + throw new NotSupportedException("Your OS is not supported"); + } + + rId += RuntimeInformation.OSArchitecture switch { + Architecture.X64 => "-x64", + Architecture.X86 => "-x86", + Architecture.Arm64 => "-arm64", + Architecture.Arm => "-arm", + _ => throw new NotSupportedException( + $"Your architecture ({RuntimeInformation.OSArchitecture}) is not supported") + }; + + return ServerPackaging.GetPlatform(rId); + } } From 9cca7e66cff9f977873fa9a2982f2fe7f9def868 Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Thu, 19 Oct 2023 23:19:46 -0400 Subject: [PATCH 7/9] Remove dot in package dirs Brings it closer to the name of the actual projects --- OpenDreamPackageTool/ClientPackaging.cs | 2 +- OpenDreamPackageTool/ServerPackaging.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenDreamPackageTool/ClientPackaging.cs b/OpenDreamPackageTool/ClientPackaging.cs index b813dbc265..26970c0eb0 100644 --- a/OpenDreamPackageTool/ClientPackaging.cs +++ b/OpenDreamPackageTool/ClientPackaging.cs @@ -51,7 +51,7 @@ private static void Build(Program.ClientOptions options) { }).Wait(); } - DirectoryInfo releaseDir = new DirectoryInfo(Path.Combine(options.OutputDir, "OpenDream.Client")); + DirectoryInfo releaseDir = new DirectoryInfo(Path.Combine(options.OutputDir, "OpenDreamClient")); Console.WriteLine("Packaging client..."); releaseDir.Create(); diff --git a/OpenDreamPackageTool/ServerPackaging.cs b/OpenDreamPackageTool/ServerPackaging.cs index 5517f8ae10..d3ecf57585 100644 --- a/OpenDreamPackageTool/ServerPackaging.cs +++ b/OpenDreamPackageTool/ServerPackaging.cs @@ -133,7 +133,7 @@ private static void BuildPlatform(PlatformReg platform, Program.ServerOptions op string releaseDir = options.OutputDir; if (options.InPlatformSubDir) - releaseDir = Path.Combine(releaseDir, $"OpenDream.Server_{platform.RId}"); + releaseDir = Path.Combine(releaseDir, $"OpenDreamServer_{platform.RId}"); Console.WriteLine($"Packaging {platform.RId} server..."); Directory.CreateDirectory(releaseDir); @@ -142,7 +142,7 @@ private static void BuildPlatform(PlatformReg platform, Program.ServerOptions op 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, "Content.Client.Zip")); + ZipFile.CreateFromDirectory(Path.Combine(options.OutputDir, "OpenDreamClient"), Path.Combine(releaseDir, "Content.Client.Zip")); } } From c7c651529c662ed6792eed174e52dd658f2b0352 Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Thu, 19 Oct 2023 23:22:29 -0400 Subject: [PATCH 8/9] Verify the CWD --- OpenDreamPackageTool/Program.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/OpenDreamPackageTool/Program.cs b/OpenDreamPackageTool/Program.cs index 5da86d3830..34096e0999 100644 --- a/OpenDreamPackageTool/Program.cs +++ b/OpenDreamPackageTool/Program.cs @@ -33,6 +33,12 @@ public static int Main(string[] args) { if (!TryParseArgs(args, out var options)) return 1; + if (!File.Exists("OpenDream.sln")) { + Console.Error.WriteLine( + "You must run this tool from the root of the OpenDream repo. OpenDream.sln was not found."); + return 1; + } + switch (options) { case ServerOptions serverOptions: ServerPackaging.Package(serverOptions); From 3b5d64703f50d6ecbb70b3bc2d5a9a1922d5d9a1 Mon Sep 17 00:00:00 2001 From: wixoaGit Date: Thu, 19 Oct 2023 23:29:21 -0400 Subject: [PATCH 9/9] Slight documentation --- OpenDreamPackageTool/ClientPackaging.cs | 3 +++ OpenDreamPackageTool/ServerPackaging.cs | 3 +++ OpenDreamPackageTool/TgsPackaging.cs | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/OpenDreamPackageTool/ClientPackaging.cs b/OpenDreamPackageTool/ClientPackaging.cs index 26970c0eb0..0b2c1c8fd8 100644 --- a/OpenDreamPackageTool/ClientPackaging.cs +++ b/OpenDreamPackageTool/ClientPackaging.cs @@ -3,6 +3,9 @@ namespace OpenDreamPackageTool; +/// +/// Packages the client's resources & assemblies in a format ready to be downloaded by connecting clients +/// public static class ClientPackaging { private static readonly string[] ClientIgnoredResources = { "Maps", diff --git a/OpenDreamPackageTool/ServerPackaging.cs b/OpenDreamPackageTool/ServerPackaging.cs index d3ecf57585..fa0a810c8c 100644 --- a/OpenDreamPackageTool/ServerPackaging.cs +++ b/OpenDreamPackageTool/ServerPackaging.cs @@ -4,6 +4,9 @@ namespace OpenDreamPackageTool; +/// +/// Packages the server, and optionally the client alongside for hybrid ACZ +/// public static class ServerPackaging { private static readonly PlatformReg[] Platforms = { new("win-x64", "Windows", true), diff --git a/OpenDreamPackageTool/TgsPackaging.cs b/OpenDreamPackageTool/TgsPackaging.cs index 78a5a90894..c65f6c0f2c 100644 --- a/OpenDreamPackageTool/TgsPackaging.cs +++ b/OpenDreamPackageTool/TgsPackaging.cs @@ -4,6 +4,10 @@ namespace OpenDreamPackageTool; +/// +/// Packages the OpenDream server, client (hybrid ACZ), and compiler in a format friendly for TGS +/// See https://github.com/OpenDreamProject/OpenDream/issues/1495 +/// public static class TgsPackaging { public static void Package(Program.TgsOptions options) { if (Directory.Exists(options.OutputDir)) {