// SPDX-FileCopyrightText: 2026 Progmasoft // SPDX-License-Identifier: MIT using System; using System.Collections.Generic; using Progmasoft.Tazel.Dsl.Common; namespace Progmasoft.Tazel.Dsl.Module.Prelude; /// What a module says about itself. public sealed class ModuleDefinition { /// The group, as in com.example. public string Group { get; init; } = ""; /// The name of the module. public string Name { get; init; } = ""; /// The SemVer version. public string Version { get; init; } = ""; /// One sentence about the module. public string? Description { get; init; } /// Who wrote it. public IReadOnlyList Authors { get; init; } = []; /// The SPDX expression of its license. public string? License { get; init; } /// Its README; default: README.md. public string Readme { get; init; } = "README.md"; /// The Tazel versions it builds with; default: any. public TazelVersion? Compatibility { get; init; } } /// The module of a MODULE.csx. public sealed class Module { private Module(ModuleDefinition definition) => Definition = definition; /// What the module says about itself. public ModuleDefinition Definition { get; } /// The module of this file. public static Module Define(ModuleDefinition definition) { ArgumentNullException.ThrowIfNull(definition); return new Module(definition); } /// A dependency on a module of Tazel Portal Modules. public static Dependency From(ModuleCoordinates coordinates) { ArgumentNullException.ThrowIfNull(coordinates); return new Dependency(coordinates, null); } } /// A module of Tazel Portal Modules, by group, name and version. public sealed class ModuleCoordinates { /// The group. public string Group { get; init; } = ""; /// The name. public string Name { get; init; } = ""; /// The version. public string Version { get; init; } = ""; /// The name its labels use instead of . public string? Alias { get; init; } } /// A module in an archive of this module. public sealed class LocalModuleSettings { /// The name its labels use: @name//:x. public string Name { get; init; } = ""; /// The archive, a .tazel.tar.xz file. public string Include { get; init; } = ""; /// The SHA-256 of the archive. public string? Sha256 { get; init; } /// A .sha256sums file that names the archive. public string? Sha256Sums { get; init; } } /// A module in an archive of this module. public static class LocalModule { /// A dependency on an archive. public static Dependency From(LocalModuleSettings settings) { ArgumentNullException.ThrowIfNull(settings); return new Dependency(null, settings); } } /// A module this module depends on. public sealed class Dependency { internal Dependency(ModuleCoordinates? portal, LocalModuleSettings? local) { Portal = portal; Local = local; } /// The module of Tazel Portal Modules, if it is one. public ModuleCoordinates? Portal { get; } /// The archive, if it is one. public LocalModuleSettings? Local { get; } } /// The modules a module depends on. public sealed class Dependencies { private Dependencies(IReadOnlyList items) => Items = items; /// The dependencies, in their order. public IReadOnlyList Items { get; } /// The dependencies of this module. public static Dependencies Define(params Dependency[] items) { ArgumentNullException.ThrowIfNull(items); return new Dependencies(items); } } /// Whether and how the module goes to Tazel Portal Modules. public sealed class PortalModulesSettings { /// Whether tazel push may push it; default: false. public bool Push { get; init; } /// Files left out of its archive. public Files Exclude { get; init; } = Files.None; } /// Whether and how the module goes to Tazel Portal Modules. public sealed class PortalModules { private PortalModules(PortalModulesSettings settings) => Settings = settings; /// The settings. public PortalModulesSettings Settings { get; } /// The settings of this module. public static PortalModules Define(PortalModulesSettings settings) { ArgumentNullException.ThrowIfNull(settings); return new PortalModules(settings); } } /// A remote cache or remote execution service. public sealed class RemoteSettings { /// Whether results are read from it; default: true. public bool Read { get; init; } = true; /// Whether results are written to it; default: false. public bool Write { get; init; } /// The token that signs in. public string? Token { get; init; } /// The key that checks what is read. public string? PublicKey { get; init; } /// The key that signs what is written. public string? SigningKey { get; init; } } /// A service at a URL. public sealed class Remote { private Remote(Uri url, RemoteSettings settings) { Url = url; Settings = settings; } /// Where the service is. public Uri Url { get; } /// How it is used. public RemoteSettings Settings { get; } /// The service at . public static Remote From(string url, RemoteSettings settings) { ArgumentNullException.ThrowIfNull(settings); // http only for a service on this machine, such as a cache beside the build. if (!Uri.TryCreate(url, UriKind.Absolute, out var parsed) || !(parsed.Scheme == Uri.UriSchemeHttps || (parsed.Scheme == Uri.UriSchemeHttp && parsed.IsLoopback))) { throw new DslException($"'{url}' is not an https URL"); } return new Remote(parsed, settings); } } /// The local and remote cache of results. public sealed class CacheSettings { /// Whether results are kept on this machine; default: true. public bool Local { get; init; } = true; /// How many results are kept per target; default: 8. public int Keep { get; init; } = 8; /// A remote cache; default: none. public Remote? Remote { get; init; } } /// The cache of a module. public sealed class Cache { private Cache(CacheSettings settings) => Settings = settings; /// The settings. public CacheSettings Settings { get; } /// The cache of this module. public static Cache Define(CacheSettings settings) { ArgumentNullException.ThrowIfNull(settings); return new Cache(settings); } } /// How a build runs. public sealed class ExecutionSettings { /// How many actions run at once; default: the processors. public int? Jobs { get; init; } /// How much memory the actions may use together; default: no limit. public ByteSize? Memory { get; init; } /// Whether a build goes on after an action failed; default: false. public bool KeepGoing { get; init; } /// A remote execution service; default: none. public Remote? Remote { get; init; } } /// How the builds of a module run. public sealed class Execution { private Execution(ExecutionSettings settings) => Settings = settings; /// The settings. public ExecutionSettings Settings { get; } /// How the builds of this module run. public static Execution Define(ExecutionSettings settings) { ArgumentNullException.ThrowIfNull(settings); return new Execution(settings); } } /// A plugin, from Tazel Portal or from an archive of this module. public sealed class PluginReference { internal PluginReference(string? group, string? name, string? version, string? path) { Group = group; Name = name; Version = version; Path = path; } /// The group of a plugin of Tazel Portal. public string? Group { get; } /// The name of a plugin of Tazel Portal. public string? Name { get; } /// The version; none takes the highest by SemVer. public string? Version { get; } /// The archive of a local plugin. public string? Path { get; } } /// A plugin of Tazel Portal. public static class Plugin { /// The plugin ., at a version or the highest. public static PluginReference From(string group, string name) => From(group, name, null); /// public static PluginReference From(string group, string name, string? version) => new(group, name, version, null); } /// A plugin in an archive of this module. public static class LocalPlugin { /// The plugin in the .tazel.tar.xz at . public static PluginReference From(string path) => new(null, null, null, path); } /// The plugins of a module. public sealed class Plugins { private Plugins(IReadOnlyList items) => Items = items; /// The plugins, in their order. public IReadOnlyList Items { get; } /// The plugins of this module. public static Plugins Define(params PluginReference[] items) { ArgumentNullException.ThrowIfNull(items); return new Plugins(items); } } /// The toolchains a module registers, in the order they are tried. public sealed class Toolchains { private Toolchains(IReadOnlyList labels) => Labels = labels; /// The labels of the toolchains. public IReadOnlyList Labels { get; } /// Registers toolchains by label. public static Toolchains Define(params string[] labels) { ArgumentNullException.ThrowIfNull(labels); return new Toolchains(labels); } } /// What a MODULE.csx sets. public sealed class ModuleGlobals { /// The module. public Module? module { get; set; } /// The modules it depends on. public Dependencies? dependencies { get; set; } /// Its settings for Tazel Portal Modules. public PortalModules? portalModules { get; set; } /// Its cache. public Cache? cache { get; set; } /// How its builds run. public Execution? execution { get; set; } /// Its plugins. public Plugins? plugins { get; set; } /// Its toolchains. public Toolchains? toolchains { get; set; } }