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
#include "lix/libutil/error-trace.hh"
#include "lix/libutil/error.hh"
#include "lix/libutil/position.hh"

namespace nix {

Trace Trace::fromDrv(std::shared_ptr<Pos> pos, std::string drvName)
{
    DrvTrace dt(drvName);

    HintFmt h(
        "while evaluating derivation '%s'\n"
        "  whose name attribute is located at %s",
        dt.drvName,
        *pos
    );

    return Trace{
        .pos = pos,
        .hint = h,
        .drvTrace = dt,
    };
}

Trace Trace::fromDrvAttr(std::shared_ptr<Pos> pos, std::string drvName, std::string attrOfDrv)
{
    DrvTrace dt(drvName);

    HintFmt h("while evaluating attribute '%s' of derivation '%s'", attrOfDrv, dt.drvName);

    return Trace{
        .pos = pos,
        .hint = h,
        .drvTrace = dt,
    };
}

std::partial_ordering operator<=>(Trace const & lhs, Trace const & rhs)
{
    // If either's position is nullptr, then we compare without dereferencing either.
    if (!lhs.pos || !rhs.pos) {
        return std::forward_as_tuple(lhs.pos != nullptr, lhs.hint.str())
            <=> std::forward_as_tuple(rhs.pos != nullptr, rhs.hint.str());
    }

    return std::forward_as_tuple(*lhs.pos, lhs.hint.str())
        <=> std::forward_as_tuple(*rhs.pos, rhs.hint.str());
}

}