// SPDX-FileCopyrightText: 2026 Progmasoft // SPDX-License-Identifier: MIT using System; using System.Collections.Generic; using System.IO; using Progmasoft.Tazel.Dsl.Common; using Progmasoft.Tazel.Project; namespace Progmasoft.Tazel.Driver; /// How a command builds, from its command line and the module. internal sealed record BuildOptions { public BuildMode Mode { get; init; } = BuildMode.Debug; public Platform Platform { get; init; } = Host.Platform; public int Jobs { get; init; } = Environment.ProcessorCount; public bool KeepGoing { get; init; } public IReadOnlyList FeaturesOn { get; init; } = []; public IReadOnlyList FeaturesOff { get; init; } = []; public IReadOnlyList CompilerOptions { get; init; } = []; public IReadOnlyList CCompilerOptions { get; init; } = []; public IReadOnlyList CppCompilerOptions { get; init; } = []; public IReadOnlyList LinkerOptions { get; init; } = []; public IReadOnlyList ZigCompilerOptions { get; init; } = []; /// Whether C-family code is built with LLVM source-based coverage, for tazel coverage. public bool Coverage { get; init; } /// What the build may take from its caches: --recompile and --no-cache. public CachePolicy CachePolicy { get; init; } = CachePolicy.Normal; } /// Where a build writes, below the state directory of the main module. internal sealed class OutputLayout(string mainRoot, BuildOptions options) { /// The root of the main module, where every action runs. public string MainRoot { get; } = mainRoot; /// The outputs of this platform and mode, relative to . public string OutRoot { get; } = $"{ModuleFiles.StateDirectory}/out/{options.Platform.Name()}-{options.Mode.ToString().ToLowerInvariant()}" + (options.Coverage ? "-coverage" : ""); /// Where tazel coverage writes its report, relative to . public string CoverageRoot { get; } = $"{ModuleFiles.StateDirectory}/coverage"; /// Where the tests write their logs, relative to . public string TestLogs { get; } = $"{ModuleFiles.StateDirectory}/testlogs"; /// zig's own cache, relative to . public string ZigCache { get; } = $"{ModuleFiles.StateDirectory}/zig-cache"; /// The output directory of the package of , relative to . public string PackageOut(ProjectTarget target) { ArgumentNullException.ThrowIfNull(target); var package = target.Label.Package; var prefix = package.Repository is null ? OutRoot : $"{OutRoot}/external/{package.Repository}"; return package.Path.Length == 0 ? prefix : $"{prefix}/{package.Path}"; } /// The full path of . public string Full(string relative) => Path.GetFullPath(Path.Combine(MainRoot, relative)); }