Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite the package scripts in C# #1511

Merged
merged 9 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
release/
x64/
x86/
bld/
Expand Down
13 changes: 13 additions & 0 deletions OpenDream.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
93 changes: 93 additions & 0 deletions OpenDreamPackageTool/ClientPackaging.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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)...");

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));
}
}
}
14 changes: 14 additions & 0 deletions OpenDreamPackageTool/OpenDreamPackageTool.csproj
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>
7 changes: 7 additions & 0 deletions OpenDreamPackageTool/PlatformReg.cs
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;
}
172 changes: 172 additions & 0 deletions OpenDreamPackageTool/Program.cs
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;
}
}
Loading
Loading