AetheriaBuild.Build: one player entry point; AetheriaStores.Open refuses a missing catalog

AetheriaBuild (Assets/Editor) sets the version, builds Addressables, builds the
Win64 player, stages GameData through PlayerStaging, publishes AetherDb to
ModTools and removes the Burst debug folder; any failure exits 1 naming the step.
PlayerStaging is Unity-free and linked into Aetheria.Shared.Tests. A read-only
AetheriaStores.Open of a nonexistent catalog throws.

Builds on the headless side; the Unity .meta files and the batchmode run follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-10 06:55:32 +02:00
commit b997b80f81
5 changed files with 255 additions and 0 deletions

View file

@ -0,0 +1,106 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditor.AddressableAssets.Settings;
using UnityEditor.Build.Reporting;
using Debug = UnityEngine.Debug;
// The one way to make a Win64 player directory. Owns what the directory contains: Aetheria.exe and its data,
// GameData/Aetheria.cc, GameData/Narrative/**, GameData/Mods/** and ModTools/AetherDb. Manual builds, smokes and
// release cuts all call this and stage nothing themselves.
//
// Unity -batchmode -quit -projectPath <repo> -executeMethod AetheriaBuild.Build
// -aetheriaVersion <semver> -aetheriaOut <dir> -logFile <log>
//
// AetherDb is published from tools/AetherDb, so the headless build's CULTLIB_ROOT / CULTMATH_ROOT (Directory.Build.props)
// must be set for dotnet when the defaults do not hold the pinned revisions.
// Any failure logs "AetheriaBuild FAILED at <step>" and exits 1.
public static class AetheriaBuild
{
private static readonly Regex SemVer = new Regex(@"^\d+\.\d+\.\d+([-+][0-9A-Za-z.-]+)?$");
public static void Build()
{
var step = "arguments";
try
{
var version = Argument("-aetheriaVersion");
if (!SemVer.IsMatch(version)) throw new InvalidOperationException("-aetheriaVersion is not a semver");
var output = Path.GetFullPath(Argument("-aetheriaOut"));
var repoRoot = Directory.GetParent(UnityEngine.Application.dataPath).FullName;
step = "version";
PlayerSettings.bundleVersion = version;
step = "addressables";
AddressableAssetSettings.BuildPlayerContent(out var content);
if (!string.IsNullOrEmpty(content.Error)) throw new InvalidOperationException("Addressables build reported an error: " + content.Error);
step = "player";
Directory.CreateDirectory(output);
var scenes = EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(scene => scene.path).ToArray();
if (scenes.Length == 0) throw new InvalidOperationException("EditorBuildSettings has no enabled scene");
var report = BuildPipeline.BuildPlayer(new BuildPlayerOptions
{
scenes = scenes,
locationPathName = Path.Combine(output, "Aetheria.exe"),
target = BuildTarget.StandaloneWindows64,
options = BuildOptions.None,
});
if (report.summary.result != BuildResult.Succeeded || report.summary.totalErrors != 0)
throw new InvalidOperationException($"BuildPlayer ended {report.summary.result} with {report.summary.totalErrors} errors");
step = "gamedata";
PlayerStaging.Stage(repoRoot, output);
step = "aetherdb";
Publish(repoRoot, Path.Combine(output, "ModTools"));
step = "burst";
var burst = Path.Combine(output, "Aetheria_BurstDebugInformation_DoNotShip");
if (Directory.Exists(burst)) Directory.Delete(burst, true);
Debug.Log($"AetheriaBuild OK {version} {output}");
}
catch (Exception error)
{
Debug.LogError($"AetheriaBuild FAILED at {step}: {error.GetType().Name}: {error.Message}");
EditorApplication.Exit(1);
return;
}
EditorApplication.Exit(0);
}
private static void Publish(string repoRoot, string modTools)
{
var info = new ProcessStartInfo("dotnet")
{
Arguments = $"publish tools/AetherDb -c Release -r win-x64 --self-contained -p:PublishSingleFile=true -o \"{modTools}\"",
WorkingDirectory = repoRoot,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
};
using (var process = Process.Start(info))
{
var errors = process.StandardError.ReadToEndAsync();
var text = process.StandardOutput.ReadToEnd();
process.WaitForExit();
if (process.ExitCode != 0)
throw new InvalidOperationException($"dotnet publish exited {process.ExitCode}:\n{text}\n{errors.Result}");
}
if (!File.Exists(Path.Combine(modTools, "AetherDb.exe")))
throw new InvalidOperationException("dotnet publish produced no ModTools/AetherDb.exe");
}
private static string Argument(string name)
{
var args = Environment.GetCommandLineArgs();
var at = Array.IndexOf(args, name);
if (at < 0 || at + 1 >= args.Length) throw new InvalidOperationException(name + " is required");
return args[at + 1];
}
}

View file

@ -0,0 +1,42 @@
using System;
using System.IO;
// What a player directory holds beside the executable's data: GameData/Aetheria.cc, GameData/Narrative/** and, when
// the repo has one, GameData/Mods/**. Nothing else under GameData ships (run.cc and player.cc are the player's own;
// SoundbanksInfo.json is read by no code). Unity-free so the headless suite can prove the rules; AetheriaBuild is the
// only caller.
internal static class PlayerStaging
{
public const string Catalog = "Aetheria.cc";
public const string Narrative = "Narrative";
public const string Mods = "Mods";
// Replaces <playerDir>/GameData with a copy of the three shipped entries of <repoRoot>/GameData.
// Throws InvalidOperationException naming the entry when the catalog or Narrative is absent.
public static void Stage(string repoRoot, string playerDir)
{
var source = Path.Combine(repoRoot, "GameData");
var destination = Path.Combine(playerDir, "GameData");
var catalog = Path.Combine(source, Catalog);
var narrative = Path.Combine(source, Narrative);
var mods = Path.Combine(source, Mods);
if (!File.Exists(catalog)) throw new InvalidOperationException($"GameData/{Catalog} is missing; a player never ships without its catalog.");
if (!Directory.Exists(narrative)) throw new InvalidOperationException($"GameData/{Narrative} is missing.");
if (Directory.Exists(destination)) Directory.Delete(destination, true);
Directory.CreateDirectory(destination);
File.Copy(catalog, Path.Combine(destination, Catalog));
CopyTree(narrative, Path.Combine(destination, Narrative));
if (Directory.Exists(mods)) CopyTree(mods, Path.Combine(destination, Mods));
}
private static void CopyTree(string from, string to)
{
Directory.CreateDirectory(to);
foreach (var directory in Directory.GetDirectories(from, "*", SearchOption.AllDirectories))
Directory.CreateDirectory(Path.Combine(to, directory.Substring(from.Length + 1)));
foreach (var file in Directory.GetFiles(from, "*", SearchOption.AllDirectories))
File.Copy(file, Path.Combine(to, file.Substring(from.Length + 1)));
}
}

View file

@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using GameCult.Caching;
using GameCult.Caching.MessagePack;
@ -15,6 +16,9 @@ public static class AetheriaStores
// no records at all, a seed store being authored from nothing; a populated catalog is held to it however it opens.
public static CultCache Open(string catalogPath, string runPath = null, string playerPath = null, bool catalogWritable = false)
{
// A read-only open of an absent catalog would hydrate an empty game; a shipped player missing its catalog stops here.
if (!catalogWritable && !File.Exists(catalogPath))
throw new InvalidOperationException($"Catalog {catalogPath} does not exist; a read-only open never invents one.");
var cache = new CultCache();
try
{

View file

@ -11,6 +11,8 @@
<!-- AuthoredSettings (Unity Settings.asset YAML reader), so fixtures load the shipped gameplay settings
instead of hand-copying them. -->
<ProjectReference Include="..\..\tools\AetherDb\AetherDb.csproj" />
<!-- The player build's staging rules: Unity-free, owned by Assets/Editor, compiled here so the suite can prove them. -->
<Compile Include="..\..\Assets\Editor\PlayerStaging.cs" Link="PlayerStaging.cs" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />

View file

@ -0,0 +1,101 @@
using System;
using System.IO;
using System.Linq;
using Xunit;
// A player directory's GameData is exactly the catalog, Narrative/** and (when the repo has them) Mods/**.
public sealed class PlayerStagingTests : IDisposable
{
private readonly string _root = Path.Combine(Path.GetTempPath(), "aetheria-staging-" + Guid.NewGuid().ToString("N"));
private string Repo => Path.Combine(_root, "repo");
private string Player => Path.Combine(_root, "player");
private string Source(string relative) => Path.Combine(Repo, "GameData", relative);
private string Staged(string relative) => Path.Combine(Player, "GameData", relative);
public PlayerStagingTests()
{
Write(Source("Aetheria.cc"), "catalog-bytes");
Write(Source("Narrative/Main.ink"), "main");
Write(Source("Narrative/Quests/Deep/First.ink"), "first");
Write(Source("SoundbanksInfo.json"), "{}");
Write(Source("run.cc"), "a developer's run");
Write(Source("player.cc"), "a developer's settings");
Directory.CreateDirectory(Player);
}
public void Dispose() => Directory.Delete(_root, true);
[Fact]
public void StagesTheCatalogAndNarrativeFileForFile()
{
PlayerStaging.Stage(Repo, Player);
Assert.Equal("catalog-bytes", File.ReadAllText(Staged("Aetheria.cc")));
Assert.Equal("main", File.ReadAllText(Staged("Narrative/Main.ink")));
Assert.Equal("first", File.ReadAllText(Staged("Narrative/Quests/Deep/First.ink")));
}
[Fact]
public void StagesModsWhenTheRepoHasThemAndNoModsFolderWhenItDoesNot()
{
PlayerStaging.Stage(Repo, Player);
Assert.False(Directory.Exists(Staged("Mods")));
Write(Source("Mods/ship-a/ship.cc"), "ship");
Write(Source("Mods/ship-a/mesh/hull.glb"), "hull");
PlayerStaging.Stage(Repo, Player);
Assert.Equal("ship", File.ReadAllText(Staged("Mods/ship-a/ship.cc")));
Assert.Equal("hull", File.ReadAllText(Staged("Mods/ship-a/mesh/hull.glb")));
}
[Fact]
public void StagesNothingElseFromGameData()
{
PlayerStaging.Stage(Repo, Player);
var staged = Directory.GetFileSystemEntries(Path.Combine(Player, "GameData")).Select(Path.GetFileName).OrderBy(name => name).ToArray();
Assert.Equal(new[] { "Aetheria.cc", "Narrative" }, staged);
}
[Fact]
public void ReplacesWhatAnEarlierBuildLeftInGameData()
{
Write(Staged("Aetheria.cc"), "stale");
Write(Staged("run.cc"), "a played run");
Write(Staged("Mods/gone/ship.cc"), "removed mod");
PlayerStaging.Stage(Repo, Player);
Assert.Equal("catalog-bytes", File.ReadAllText(Staged("Aetheria.cc")));
Assert.False(File.Exists(Staged("run.cc")));
Assert.False(Directory.Exists(Staged("Mods")));
}
[Fact]
public void RefusesAMissingCatalogNamingItAndLeavesNoGameData()
{
File.Delete(Source("Aetheria.cc"));
var error = Assert.Throws<InvalidOperationException>(() => PlayerStaging.Stage(Repo, Player));
Assert.Contains("GameData/Aetheria.cc", error.Message);
Assert.False(Directory.Exists(Path.Combine(Player, "GameData")));
}
[Fact]
public void RefusesMissingNarrative()
{
Directory.Delete(Source("Narrative"), true);
var error = Assert.Throws<InvalidOperationException>(() => PlayerStaging.Stage(Repo, Player));
Assert.Contains("GameData/Narrative", error.Message);
}
private static void Write(string path, string text)
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
File.WriteAllText(path, text);
}
}