-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into RightType
- Loading branch information
Showing
25 changed files
with
766 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
[Dd]ebugPublic/ | ||
[Rr]elease/ | ||
[Rr]eleases/ | ||
release/ | ||
x64/ | ||
x86/ | ||
bld/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using System.Diagnostics; | ||
using Robust.Packaging.Utility; | ||
|
||
namespace OpenDreamPackageTool; | ||
|
||
/// <summary> | ||
/// Packages the client's resources & assemblies in a format ready to be downloaded by connecting clients | ||
/// </summary> | ||
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)..."); | ||
|
||
if (Directory.Exists("bin")) | ||
Directory.Delete("bin", true); | ||
} | ||
|
||
private static void Build(Program.ClientOptions options) { | ||
Console.WriteLine("Building project..."); | ||
|
||
if (!options.SkipBuild) { | ||
ProcessHelpers.RunCheck(new ProcessStartInfo { | ||
FileName = "dotnet", | ||
ArgumentList = { | ||
"build", | ||
"OpenDreamClient/OpenDreamClient.csproj", | ||
"-c", "Release", | ||
"--nologo", | ||
"/v:m", | ||
"/t:Rebuild", | ||
"/p:FullRelease=True", | ||
"/m" | ||
} | ||
}).Wait(); | ||
} | ||
|
||
DirectoryInfo releaseDir = new DirectoryInfo(Path.Combine(options.OutputDir, "OpenDreamClient")); | ||
|
||
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<string> 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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\RobustToolbox\Robust.Packaging\Robust.Packaging.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace OpenDreamPackageTool; | ||
|
||
public record PlatformReg(string RId, string TargetOs, bool BuildByDefault) { | ||
public string RId = RId; | ||
public string TargetOs = TargetOs; | ||
public bool BuildByDefault = BuildByDefault; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
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 string? Platform; | ||
public bool HybridAcz; | ||
public bool InPlatformSubDir = true; | ||
public bool TgsEngineBuild; | ||
} | ||
|
||
public class ClientOptions : Options { | ||
|
||
} | ||
|
||
public class TgsOptions : Options { | ||
// Avoid adding arguments for TGS, to give us more flexibility while keeping compatibility | ||
} | ||
|
||
public static readonly string[] SharedIgnoredResources = { | ||
".gitignore", | ||
".directory", | ||
".DS_Store" | ||
}; | ||
|
||
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); | ||
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<string>(); | ||
|
||
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; | ||
} | ||
|
||
serverOptions.Platform = args[++i]; | ||
break; | ||
case "--hybrid-acz": | ||
serverOptions.HybridAcz = true; | ||
break; | ||
default: | ||
Console.Error.WriteLine($"Invalid 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($"Invalid 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; | ||
default: | ||
Console.Error.WriteLine($"Invalid argument '{arg}'"); | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
options = null; | ||
Console.Error.WriteLine("One of '--server' or '--client' must be given"); | ||
return false; | ||
} | ||
} |
Oops, something went wrong.