Skip to content
Open
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
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,25 @@ jobs:

build-linux:
runs-on: ubuntu-latest
container:
image: debian:bookworm-slim

steps:
- name: Install prerequisites
run: |
apt-get update
apt-get install -y --no-install-recommends ca-certificates clang lld git curl

- name: Checkout
uses: actions/checkout@v6
with:
submodules: "recursive"

- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"

- name: Test
run: dotnet test

Expand Down
26 changes: 21 additions & 5 deletions RLBotCS/ManagerTools/ConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using RLBotCS.Model;
using Tomlyn;
using Tomlyn.Model;
using Tomlyn.Serialization;

namespace RLBotCS.ManagerTools;

Expand All @@ -16,6 +17,7 @@ public static class Fields
public const string RlBotLauncherArg = "launcher_arg";
public const string RlBotAutoStartAgents = "auto_start_agents";
public const string RlBotWaitForAgents = "wait_for_agents";
public const string RlBotPerformanceMonitor = "performance_monitor";

public const string MatchTable = "match";
public const string MatchGameMode = "game_mode";
Expand All @@ -27,7 +29,6 @@ public static class Fields
public const string MatchStateSetting = "enable_state_setting";
public const string MatchAutoSaveReplays = "auto_save_replays";
public const string MatchFreePlay = "freeplay";
public const string MatchPerformanceMonitor = "performance_monitor";

public const string MutatorsTable = "mutators";
public const string MutatorsMatchLength = "match_length";
Expand Down Expand Up @@ -112,7 +113,21 @@ public class ConfigParserException(string? message, Exception? innerException =
private readonly ConfigContextTracker _context = new();

/// <summary>Holds field names that were not present in the config. Used for debugging.</summary>
private readonly List<string> _missingValues = new();
private readonly List<string> _missingValues = [];

/// <summary>
/// AOT-safe TOML serializer context for parsing documents into <see cref="TomlTable"/>.
/// </summary>
private sealed class ParserTomlContext : TomlSerializerContext
{
public static readonly ParserTomlContext Default = new();

private ParserTomlContext()
: base(new()) { }

public override TomlTypeInfo? GetTypeInfo(Type type, TomlSerializerOptions options) =>
type == typeof(TomlTable) ? GetBuiltInTypeInfo<TomlTable>(options) : null;
}

private TomlTable LoadTomlFile(string path)
{
Expand All @@ -127,7 +142,8 @@ private TomlTable LoadTomlFile(string path)
}

path = Path.GetFullPath(path);
return Toml.ToModel(File.ReadAllText(path), path);
using var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
return TomlSerializer.Deserialize<TomlTable>(stream, ParserTomlContext.Default)!;
}
catch (Exception e)
{
Expand Down Expand Up @@ -729,7 +745,7 @@ public MatchConfigurationT LoadMatchConfig(string path)
path = Path.GetFullPath(path);
TomlTable outerTable = LoadTomlFile(path);

MatchConfigurationT matchConfig = new MatchConfigurationT();
MatchConfigurationT matchConfig = new();

TomlTable rlbotTable = GetValue<TomlTable>(outerTable, Fields.RlBotTable, []);
using (_context.Begin(Fields.RlBotTable))
Expand All @@ -752,7 +768,7 @@ public MatchConfigurationT LoadMatchConfig(string path)
);
matchConfig.PerformanceMonitor = GetEnum(
rlbotTable,
Fields.MatchPerformanceMonitor,
Fields.RlBotPerformanceMonitor,
PerformanceMonitor.ShowWhenSuboptimal
);
}
Expand Down
4 changes: 1 addition & 3 deletions RLBotCS/RLBotCS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@
<OptimizationPreference>Speed</OptimizationPreference>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<PublishWmiLightStaticallyLinked>true</PublishWmiLightStaticallyLinked>
<SelfContained>true</SelfContained>
<StaticExecutable>true</StaticExecutable>
<LinkerFlavor
Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))'"
>lld</LinkerFlavor>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Tomlyn" Version="0.20.0" />
<PackageReference Include="Tomlyn" Version="2.5.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.2" />
</ItemGroup>
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
Expand Down
Loading