Skip to content

Commit

Permalink
Robust.Packaging updates (space-wizards#4547)
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth authored Nov 6, 2023
1 parent 170d192 commit 3da04ed
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected override void AcceptFinished()
foreach (var (key, dat) in _foundRsis)
{
if (dat.MetaJson == null)
return;
continue;

RunJob(() =>
{
Expand Down
4 changes: 2 additions & 2 deletions Robust.Packaging/RobustClientAssetGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public sealed class RobustClientAssetGraph
/// </summary>
public IReadOnlyCollection<AssetPass> AllPasses { get; }

public RobustClientAssetGraph()
public RobustClientAssetGraph(bool parallel = true)
{
// The code injecting the list of source files is assumed to be pretty single-threaded.
// We use a parallelizing input to break out all the work on files coming in onto multiple threads.
Input = new AssetPassPipe { Name = "RobustClientAssetGraphInput", Parallelize = true };
Input = new AssetPassPipe { Name = "RobustClientAssetGraphInput", Parallelize = parallel };
PresetPasses = new AssetPassPipe { Name = "RobustClientAssetGraphPresetPasses" };
Output = new AssetPassPipe { Name = "RobustClientAssetGraphOutput", CheckDuplicates = true };
NormalizeText = new AssetPassNormalizeText { Name = "RobustClientAssetGraphNormalizeText" };
Expand Down
47 changes: 4 additions & 43 deletions Robust.Packaging/RobustClientPackaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ namespace Robust.Packaging;

public sealed class RobustClientPackaging
{
public static IReadOnlySet<string> ClientIgnoresResources { get; } = new HashSet<string>
public static IReadOnlySet<string> ClientIgnoredResources { get; } = new HashSet<string>
{
"Maps",
"ConfigPresets",
// Leaving this here for future archaeologists to ponder at.
"emotes.xml",
"Groups",
Expand All @@ -18,48 +19,8 @@ public static async Task WriteClientResources(
AssetPass pass,
CancellationToken cancel = default)
{
var ignoreSet = ClientIgnoresResources.Union(RobustSharedPackaging.SharedIgnoredResources).ToHashSet();
var ignoreSet = ClientIgnoredResources.Union(RobustSharedPackaging.SharedIgnoredResources).ToHashSet();

await RobustSharedPackaging.DoResourceCopy(Path.Combine(contentDir, "Resources"), pass, ignoreSet, cancel);
}

public static async Task WriteContentAssemblies(
AssetPass pass,
string contentDir,
string binDir,
IEnumerable<string> contentAssemblies,
CancellationToken cancel = default)
{
await WriteContentAssemblies("Assemblies", pass, contentDir, binDir, contentAssemblies, cancel);
}

public static Task WriteContentAssemblies(
string target,
AssetPass pass,
string contentDir,
string binDir,
IEnumerable<string> contentAssemblies,
CancellationToken cancel = default)
{
var files = new List<string>();

var sourceDir = Path.Combine(contentDir, "bin", binDir);

foreach (var asm in contentAssemblies)
{
files.Add($"{asm}.dll");

var pdbPath = $"{asm}.pdb";
if (File.Exists(Path.Combine(sourceDir, pdbPath)))
files.Add(pdbPath);
}

foreach (var f in files)
{
cancel.ThrowIfCancellationRequested();
pass.InjectFileFromDisk($"{target}/{f}", Path.Combine(sourceDir, f));
}

return Task.CompletedTask;
await RobustSharedPackaging.DoResourceCopy(Path.Combine(contentDir, "Resources"), pass, ignoreSet, cancel: cancel);
}
}
33 changes: 33 additions & 0 deletions Robust.Packaging/RobustServerPackaging.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Robust.Packaging.AssetProcessing;

namespace Robust.Packaging;

public sealed class RobustServerPackaging
{
public static IReadOnlySet<string> ServerIgnoresResources { get; } = new HashSet<string>
{
"Audio",
"Textures",
"Fonts",
"Shaders",
};

public static async Task WriteServerResources(
string contentDir,
AssetPass pass,
CancellationToken cancel = default)
{
var ignoreSet = ServerIgnoresResources.Union(RobustSharedPackaging.SharedIgnoredResources).ToHashSet();

await RobustSharedPackaging.DoResourceCopy(Path.Combine(contentDir, "Resources"),
pass,
ignoreSet,
"Resources",
cancel);
await RobustSharedPackaging.DoResourceCopy(Path.Combine("RobustToolbox", "Resources"),
pass,
ignoreSet,
"Resources",
cancel);
}
}
51 changes: 47 additions & 4 deletions Robust.Packaging/RobustSharedPackaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,53 @@ public sealed class RobustSharedPackaging
".DS_Store"
};

// IDK what these are supposed to correspond to but targetDir is the target directory.
public static async Task WriteContentAssemblies(
AssetPass pass,
string contentDir,
string binDir,
IEnumerable<string> contentAssemblies,
string targetDir = "Assemblies",
CancellationToken cancel = default)
{
await WriteContentAssemblies(targetDir, pass, contentDir, binDir, contentAssemblies, cancel);
}

public static Task WriteContentAssemblies(
string target,
AssetPass pass,
string contentDir,
string binDir,
IEnumerable<string> contentAssemblies,
CancellationToken cancel = default)
{
var files = new List<string>();

var sourceDir = Path.Combine(contentDir, "bin", binDir);

foreach (var asm in contentAssemblies)
{
files.Add($"{asm}.dll");

var pdbPath = $"{asm}.pdb";
if (File.Exists(Path.Combine(sourceDir, pdbPath)))
files.Add(pdbPath);
}

foreach (var f in files)
{
cancel.ThrowIfCancellationRequested();
pass.InjectFileFromDisk($"{target}/{f}", Path.Combine(sourceDir, f));
}

return Task.CompletedTask;
}

public static Task DoResourceCopy(
string diskSource,
AssetPass pass,
IReadOnlySet<string> ignoreSet,
string targetDir = "",
CancellationToken cancel = default)
{
foreach (var path in Directory.EnumerateFileSystemEntries(diskSource))
Expand All @@ -29,7 +72,7 @@ public static Task DoResourceCopy(
if (ignoreSet.Contains(filename))
continue;

var targetPath = filename;
var targetPath = Path.Combine(targetDir, filename);
if (Directory.Exists(path))
CopyDirIntoZip(path, targetPath, pass);
else
Expand All @@ -44,11 +87,11 @@ private static void CopyDirIntoZip(string directory, string basePath, AssetPass
foreach (var file in Directory.EnumerateFiles(directory, "*.*", SearchOption.AllDirectories))
{
var relPath = Path.GetRelativePath(directory, file);
if (Path.DirectorySeparatorChar != '/')
relPath = relPath.Replace(Path.DirectorySeparatorChar, '/');

var zipPath = $"{basePath}/{relPath}";

if (Path.DirectorySeparatorChar != '/')
zipPath = zipPath.Replace(Path.DirectorySeparatorChar, '/');

// Console.WriteLine($"{directory}/{zipPath} -> /{zipPath}");
pass.InjectFileFromDisk(zipPath, file);
}
Expand Down
4 changes: 2 additions & 2 deletions Robust.Server/ServerStatus/DefaultMagicAczProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public async Task Package(
var inputPass = graph.Input;

var contentDir = FindContentRootPath(_deps);
await RobustClientPackaging.WriteContentAssemblies(
await RobustSharedPackaging.WriteContentAssemblies(
inputPass,
contentDir,
binFolderPath,
assemblyNames,
cancel);
cancel: cancel);

await RobustClientPackaging.WriteClientResources(contentDir, inputPass, cancel);

Expand Down

0 comments on commit 3da04ed

Please sign in to comment.