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
51
52
53
54
55
56
57
#pragma once
/**
 * @file
 */

#include <compare>
#include <memory>
#include <string>
#include <optional>

#include "lix/libutil/fmt.hh"

namespace nix {

struct Pos;

/** @brief Information for a @ref Trace that encountered a derivation.
 *
 * This is used for summarizing the derivations involved in an eval error
 * at the end of a trace-print.
 */
struct DrvTrace
{
    std::string drvName;
    // TODO: include more structured information like "element 6 of nativeBuildInputs".

    DrvTrace() = delete;

    explicit DrvTrace(std::string drvName) : drvName(drvName) {}

    friend std::strong_ordering
    operator<=>(DrvTrace const & lhs, DrvTrace const & rhs) noexcept = default;
};

struct Trace;

struct Trace
{
    std::shared_ptr<Pos> pos;
    HintFmt hint;
    std::optional<DrvTrace> drvTrace;

    /** Construct a Trace and canned format message assuming a derivation's
     * position and name.
     */
    static Trace fromDrv(std::shared_ptr<Pos> pos, std::string drvName);

    /** Construct a Trace and canned format message assuming a derivation's
     * position, name, and the attribute of that derivation which caused the
     * trace.
     */
    static Trace fromDrvAttr(std::shared_ptr<Pos> pos, std::string drvName, std::string attrOfDrv);

    friend std::partial_ordering operator<=>(Trace const & lhs, Trace const & rhs);
};

}