1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 06:31:14 +02:00

Rename SearchPath to LookupPath and searchPath to lookupPath

This commit is contained in:
Roland Coeurjoly 2024-04-13 17:35:15 +02:00
parent 8c4c2156bd
commit 40a6a9fdb8
29 changed files with 136 additions and 136 deletions

View file

@ -343,7 +343,7 @@ void initGC()
}
EvalState::EvalState(
const SearchPath & _searchPath,
const LookupPath & _lookupPath,
ref<Store> store,
std::shared_ptr<Store> buildStore)
: sWith(symbols.create("<with>"))
@ -448,16 +448,16 @@ EvalState::EvalState(
/* Initialise the Nix expression search path. */
if (!evalSettings.pureEval) {
for (auto & i : _searchPath.elements)
searchPath.elements.emplace_back(SearchPath::Elem {i});
for (auto & i : _lookupPath.elements)
lookupPath.elements.emplace_back(LookupPath::Elem {i});
for (auto & i : evalSettings.nixPath.get())
searchPath.elements.emplace_back(SearchPath::Elem::parse(i));
lookupPath.elements.emplace_back(LookupPath::Elem::parse(i));
}
/* Allow access to all paths in the search path. */
if (rootFS.dynamic_pointer_cast<AllowListInputAccessor>())
for (auto & i : searchPath.elements)
resolveSearchPathPath(i.path, true);
for (auto & i : lookupPath.elements)
resolveLookupPathPath(i.path, true);
corepkgsFS->addFile(
CanonPath("fetchurl.nix"),
@ -2820,19 +2820,19 @@ Expr * EvalState::parseStdin()
SourcePath EvalState::findFile(const std::string_view path)
{
return findFile(searchPath, path);
return findFile(lookupPath, path);
}
SourcePath EvalState::findFile(const SearchPath & searchPath, const std::string_view path, const PosIdx pos)
SourcePath EvalState::findFile(const LookupPath & lookupPath, const std::string_view path, const PosIdx pos)
{
for (auto & i : searchPath.elements) {
for (auto & i : lookupPath.elements) {
auto suffixOpt = i.prefix.suffixIfPotentialMatch(path);
if (!suffixOpt) continue;
auto suffix = *suffixOpt;
auto rOpt = resolveSearchPathPath(i.path);
auto rOpt = resolveLookupPathPath(i.path);
if (!rOpt) continue;
auto r = *rOpt;
@ -2852,11 +2852,11 @@ SourcePath EvalState::findFile(const SearchPath & searchPath, const std::string_
}
std::optional<std::string> EvalState::resolveSearchPathPath(const SearchPath::Path & value0, bool initAccessControl)
std::optional<std::string> EvalState::resolveLookupPathPath(const LookupPath::Path & value0, bool initAccessControl)
{
auto & value = value0.s;
auto i = searchPathResolved.find(value);
if (i != searchPathResolved.end()) return i->second;
auto i = lookupPathResolved.find(value);
if (i != lookupPathResolved.end()) return i->second;
std::optional<std::string> res;
@ -2912,7 +2912,7 @@ std::optional<std::string> EvalState::resolveSearchPathPath(const SearchPath::Pa
else
debug("failed to resolve search path element '%s'", value);
searchPathResolved.emplace(value, res);
lookupPathResolved.emplace(value, res);
return res;
}

View file

@ -162,7 +162,7 @@ struct DebugTrace {
};
// Don't want Windows function
#undef SearchPath
#undef LookupPath
class EvalState : public std::enable_shared_from_this<EvalState>
{
@ -311,9 +311,9 @@ private:
#endif
FileEvalCache fileEvalCache;
SearchPath searchPath;
LookupPath lookupPath;
std::map<std::string, std::optional<std::string>> searchPathResolved;
std::map<std::string, std::optional<std::string>> lookupPathResolved;
/**
* Cache used by prim_match().
@ -335,12 +335,12 @@ private:
public:
EvalState(
const SearchPath & _searchPath,
const LookupPath & _lookupPath,
ref<Store> store,
std::shared_ptr<Store> buildStore = nullptr);
~EvalState();
SearchPath getSearchPath() { return searchPath; }
LookupPath getLookupPath() { return lookupPath; }
/**
* Return a `SourcePath` that refers to `path` in the root
@ -409,7 +409,7 @@ public:
* Look up a file in the search path.
*/
SourcePath findFile(const std::string_view path);
SourcePath findFile(const SearchPath & searchPath, const std::string_view path, const PosIdx pos = noPos);
SourcePath findFile(const LookupPath & lookupPath, const std::string_view path, const PosIdx pos = noPos);
/**
* Try to resolve a search path value (not the optional key part).
@ -418,8 +418,8 @@ public:
*
* If it is not found, return `std::nullopt`
*/
std::optional<std::string> resolveSearchPathPath(
const SearchPath::Path & elem,
std::optional<std::string> resolveLookupPathPath(
const LookupPath::Path & elem,
bool initAccessControl = false);
/**

View file

@ -1716,7 +1716,7 @@ static void prim_findFile(EvalState & state, const PosIdx pos, Value * * args, V
{
state.forceList(*args[0], pos, "while evaluating the first argument passed to builtins.findFile");
SearchPath searchPath;
LookupPath lookupPath;
for (auto v2 : args[0]->listItems()) {
state.forceAttrs(*v2, pos, "while evaluating an element of the list passed to builtins.findFile");
@ -1744,15 +1744,15 @@ static void prim_findFile(EvalState & state, const PosIdx pos, Value * * args, V
).atPos(pos).debugThrow();
}
searchPath.elements.emplace_back(SearchPath::Elem {
.prefix = SearchPath::Prefix { .s = prefix },
.path = SearchPath::Path { .s = path },
lookupPath.elements.emplace_back(LookupPath::Elem {
.prefix = LookupPath::Prefix { .s = prefix },
.path = LookupPath::Path { .s = path },
});
}
auto path = state.forceStringNoCtx(*args[1], pos, "while evaluating the second argument passed to builtins.findFile");
v.mkPath(state.findFile(searchPath, path, pos));
v.mkPath(state.findFile(lookupPath, path, pos));
}
static RegisterPrimOp primop_findFile(PrimOp {
@ -4629,8 +4629,8 @@ void EvalState::createBaseEnv()
});
/* Add a value containing the current Nix expression search path. */
auto list = buildList(searchPath.elements.size());
for (const auto & [n, i] : enumerate(searchPath.elements)) {
auto list = buildList(lookupPath.elements.size());
for (const auto & [n, i] : enumerate(lookupPath.elements)) {
auto attrs = buildBindings(2);
attrs.alloc("path").mkString(i.path.s);
attrs.alloc("prefix").mkString(i.prefix.s);

View file

@ -2,7 +2,7 @@
namespace nix {
std::optional<std::string_view> SearchPath::Prefix::suffixIfPotentialMatch(
std::optional<std::string_view> LookupPath::Prefix::suffixIfPotentialMatch(
std::string_view path) const
{
auto n = s.size();
@ -27,11 +27,11 @@ std::optional<std::string_view> SearchPath::Prefix::suffixIfPotentialMatch(
}
SearchPath::Elem SearchPath::Elem::parse(std::string_view rawElem)
LookupPath::Elem LookupPath::Elem::parse(std::string_view rawElem)
{
size_t pos = rawElem.find('=');
return SearchPath::Elem {
return LookupPath::Elem {
.prefix = Prefix {
.s = pos == std::string::npos
? std::string { "" }
@ -44,11 +44,11 @@ SearchPath::Elem SearchPath::Elem::parse(std::string_view rawElem)
}
SearchPath SearchPath::parse(const Strings & rawElems)
LookupPath LookupPath::parse(const Strings & rawElems)
{
SearchPath res;
LookupPath res;
for (auto & rawElem : rawElems)
res.elements.emplace_back(SearchPath::Elem::parse(rawElem));
res.elements.emplace_back(LookupPath::Elem::parse(rawElem));
return res;
}

View file

@ -8,17 +8,17 @@
namespace nix {
// Do not want the windows macro (alias to `SearchPathA`)
#undef SearchPath
// Do not want the windows macro (alias to `LookupPathA`)
#undef LookupPath
/**
* A "search path" is a list of ways look for something, used with
* `builtins.findFile` and `< >` lookup expressions.
*/
struct SearchPath
struct LookupPath
{
/**
* A single element of a `SearchPath`.
* A single element of a `LookupPath`.
*
* Each element is tried in succession when looking up a path. The first
* element to completely match wins.
@ -26,16 +26,16 @@ struct SearchPath
struct Elem;
/**
* The first part of a `SearchPath::Elem` pair.
* The first part of a `LookupPath::Elem` pair.
*
* Called a "prefix" because it takes the form of a prefix of a file
* path (first `n` path components). When looking up a path, to use
* a `SearchPath::Elem`, its `Prefix` must match the path.
* a `LookupPath::Elem`, its `Prefix` must match the path.
*/
struct Prefix;
/**
* The second part of a `SearchPath::Elem` pair.
* The second part of a `LookupPath::Elem` pair.
*
* It is either a path or a URL (with certain restrictions / extra
* structure).
@ -43,7 +43,7 @@ struct SearchPath
* If the prefix of the path we are looking up matches, we then
* check if the rest of the path points to something that exists
* within the directory denoted by this. If so, the
* `SearchPath::Elem` as a whole matches, and that *something* being
* `LookupPath::Elem` as a whole matches, and that *something* being
* pointed to by the rest of the path we are looking up is the
* result.
*/
@ -54,24 +54,24 @@ struct SearchPath
* when looking up. (The actual lookup entry point is in `EvalState`
* not in this class.)
*/
std::list<SearchPath::Elem> elements;
std::list<LookupPath::Elem> elements;
/**
* Parse a string into a `SearchPath`
* Parse a string into a `LookupPath`
*/
static SearchPath parse(const Strings & rawElems);
static LookupPath parse(const Strings & rawElems);
};
struct SearchPath::Prefix
struct LookupPath::Prefix
{
/**
* Underlying string
*
* @todo Should we normalize this when constructing a `SearchPath::Prefix`?
* @todo Should we normalize this when constructing a `LookupPath::Prefix`?
*/
std::string s;
GENERATE_CMP(SearchPath::Prefix, me->s);
GENERATE_CMP(LookupPath::Prefix, me->s);
/**
* If the path possibly matches this search path element, return the
@ -82,7 +82,7 @@ struct SearchPath::Prefix
std::optional<std::string_view> suffixIfPotentialMatch(std::string_view path) const;
};
struct SearchPath::Path
struct LookupPath::Path
{
/**
* The location of a search path item, as a path or URL.
@ -91,21 +91,21 @@ struct SearchPath::Path
*/
std::string s;
GENERATE_CMP(SearchPath::Path, me->s);
GENERATE_CMP(LookupPath::Path, me->s);
};
struct SearchPath::Elem
struct LookupPath::Elem
{
Prefix prefix;
Path path;
GENERATE_CMP(SearchPath::Elem, me->prefix, me->path);
GENERATE_CMP(LookupPath::Elem, me->prefix, me->path);
/**
* Parse a string into a `SearchPath::Elem`
* Parse a string into a `LookupPath::Elem`
*/
static SearchPath::Elem parse(std::string_view rawElem);
static LookupPath::Elem parse(std::string_view rawElem);
};
}