1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 12:41:15 +02:00

Backport SourcePath from the lazy-trees branch

This introduces the SourcePath type from lazy-trees as an abstraction
for accessing files from inputs that may not be materialized in the
real filesystem (e.g. Git repositories). Currently, however, it's just
a wrapper around CanonPath, so it shouldn't change any behaviour. (On
lazy-trees, SourcePath is a <InputAccessor, CanonPath> tuple.)
This commit is contained in:
Eelco Dolstra 2023-04-06 13:15:50 +02:00
parent 5256ba6d87
commit 94812cca98
35 changed files with 567 additions and 263 deletions

View file

@ -5,6 +5,7 @@
#include "symbol-table.hh"
#include "value/context.hh"
#include "input-accessor.hh"
#if HAVE_BOEHMGC
#include <gc/gc_allocator.h>
@ -171,7 +172,7 @@ public:
const char * * context; // must be in sorted order
} string;
const char * path;
const char * _path;
Bindings * attrs;
struct {
size_t size;
@ -251,15 +252,20 @@ public:
void mkStringMove(const char * s, const PathSet & context);
inline void mkPath(const char * s)
inline void mkString(const Symbol & s)
{
mkString(((const std::string &) s).c_str());
}
void mkPath(const SourcePath & path);
inline void mkPath(const char * path)
{
clearValue();
internalType = tPath;
path = s;
_path = path;
}
void mkPath(std::string_view s);
inline void mkNull()
{
clearValue();
@ -400,6 +406,18 @@ public:
auto begin = listElems();
return ConstListIterable { begin, begin + listSize() };
}
SourcePath path() const
{
assert(internalType == tPath);
return SourcePath{CanonPath(_path)};
}
std::string_view str() const
{
assert(internalType == tString);
return std::string_view(string.s);
}
};