-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStableAbiModuleCatalog.cs
More file actions
50 lines (45 loc) · 1.73 KB
/
Copy pathStableAbiModuleCatalog.cs
File metadata and controls
50 lines (45 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections.ObjectModel;
using DotPython.Runtime.Native;
namespace DotPython.Worker.Host;
internal sealed record StableAbiModuleCatalogEntry(
StableAbiModuleConfiguration Configuration,
StableAbiSymbolManifest Manifest
);
internal static class StableAbiModuleCatalog
{
internal static IReadOnlyList<StableAbiModuleCatalogEntry> ValidateAndFreeze(
IReadOnlyList<StableAbiModuleCatalogEntry> entries
)
{
ArgumentNullException.ThrowIfNull(entries);
if (entries.Count is 0 or > 64)
{
throw new ArgumentException(
"A Stable-ABI module catalog must contain between 1 and 64 entries.",
nameof(entries)
);
}
var pathComparer = OperatingSystem.IsWindows()
? StringComparer.OrdinalIgnoreCase
: StringComparer.Ordinal;
var moduleNames = new HashSet<string>(StringComparer.Ordinal);
var modulePaths = new HashSet<string>(pathComparer);
var manifestPaths = new HashSet<string>(pathComparer);
foreach (var entry in entries)
{
ArgumentNullException.ThrowIfNull(entry);
if (
!moduleNames.Add(entry.Manifest.ModuleName)
|| !modulePaths.Add(Path.GetFullPath(entry.Configuration.ModulePath))
|| !manifestPaths.Add(Path.GetFullPath(entry.Configuration.ManifestPath))
)
{
throw new ArgumentException(
"Stable-ABI module names, native paths, and manifest paths must be unique.",
nameof(entries)
);
}
}
return new ReadOnlyCollection<StableAbiModuleCatalogEntry>(entries.ToArray());
}
}