Skip to content

Commit

Permalink
Merge pull request #10573 from RCoeurjoly/Rename_SearchPath
Browse files Browse the repository at this point in the history
Rename SearchPath to LookupPath and searchPath to lookupPath
  • Loading branch information
roberth committed Apr 21, 2024
2 parents c6526fa + 62ce139 commit 6fd2f42
Show file tree
Hide file tree
Showing 29 changed files with 133 additions and 139 deletions.
4 changes: 2 additions & 2 deletions src/libcmd/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ ref<EvalState> EvalCommand::getEvalState()
evalState =
#if HAVE_BOEHMGC
std::allocate_shared<EvalState>(traceable_allocator<EvalState>(),
searchPath, getEvalStore(), getStore())
lookupPath, getEvalStore(), getStore())
#else
std::make_shared<EvalState>(
searchPath, getEvalStore(), getStore())
lookupPath, getEvalStore(), getStore())
#endif
;

Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/common-eval-args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ MixEvalArgs::MixEvalArgs()
.category = category,
.labels = {"path"},
.handler = {[&](std::string s) {
searchPath.elements.emplace_back(SearchPath::Elem::parse(s));
lookupPath.elements.emplace_back(LookupPath::Elem::parse(s));
}}
});

Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/common-eval-args.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct MixEvalArgs : virtual Args, virtual MixRepair

Bindings * getAutoArgs(EvalState & state);

SearchPath searchPath;
LookupPath lookupPath;

std::optional<std::string> evalStoreUrl;

Expand Down
14 changes: 7 additions & 7 deletions src/libcmd/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct NixRepl

std::unique_ptr<ReplInteracter> interacter;

NixRepl(const SearchPath & searchPath, nix::ref<Store> store,ref<EvalState> state,
NixRepl(const LookupPath & lookupPath, nix::ref<Store> store,ref<EvalState> state,
std::function<AnnotatedValues()> getValues);
virtual ~NixRepl() = default;

Expand Down Expand Up @@ -122,7 +122,7 @@ std::string removeWhitespace(std::string s)
}


NixRepl::NixRepl(const SearchPath & searchPath, nix::ref<Store> store, ref<EvalState> state,
NixRepl::NixRepl(const LookupPath & lookupPath, nix::ref<Store> store, ref<EvalState> state,
std::function<NixRepl::AnnotatedValues()> getValues)
: AbstractNixRepl(state)
, debugTraceIndex(0)
Expand Down Expand Up @@ -508,7 +508,7 @@ ProcessLineResult NixRepl::processLine(std::string line)

// runProgram redirects stdout to a StringSink,
// using runProgram2 to allow editors to display their UI
runProgram2(RunOptions { .program = editor, .searchPath = true, .args = args });
runProgram2(RunOptions { .program = editor, .lookupPath = true, .args = args });

// Reload right after exiting the editor
state->resetFileCache();
Expand Down Expand Up @@ -784,11 +784,11 @@ void NixRepl::evalString(std::string s, Value & v)


std::unique_ptr<AbstractNixRepl> AbstractNixRepl::create(
const SearchPath & searchPath, nix::ref<Store> store, ref<EvalState> state,
const LookupPath & lookupPath, nix::ref<Store> store, ref<EvalState> state,
std::function<AnnotatedValues()> getValues)
{
return std::make_unique<NixRepl>(
searchPath,
lookupPath,
openStore(),
state,
getValues
Expand All @@ -804,9 +804,9 @@ ReplExitStatus AbstractNixRepl::runSimple(
NixRepl::AnnotatedValues values;
return values;
};
SearchPath searchPath = {};
LookupPath lookupPath = {};
auto repl = std::make_unique<NixRepl>(
searchPath,
lookupPath,
openStore(),
evalState,
getValues
Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/repl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct AbstractNixRepl
typedef std::vector<std::pair<Value*,std::string>> AnnotatedValues;

static std::unique_ptr<AbstractNixRepl> create(
const SearchPath & searchPath, nix::ref<Store> store, ref<EvalState> state,
const LookupPath & lookupPath, nix::ref<Store> store, ref<EvalState> state,
std::function<AnnotatedValues()> getValues);

static ReplExitStatus runSimple(
Expand Down
12 changes: 6 additions & 6 deletions src/libexpr-c/nix_api_expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ nix_err nix_value_force_deep(nix_c_context * context, EvalState * state, Value *
NIXC_CATCH_ERRS
}

EvalState * nix_state_create(nix_c_context * context, const char ** searchPath_c, Store * store)
EvalState * nix_state_create(nix_c_context * context, const char ** lookupPath_c, Store * store)
{
if (context)
context->last_err_code = NIX_OK;
try {
nix::Strings searchPath;
if (searchPath_c != nullptr)
for (size_t i = 0; searchPath_c[i] != nullptr; i++)
searchPath.push_back(searchPath_c[i]);
nix::Strings lookupPath;
if (lookupPath_c != nullptr)
for (size_t i = 0; lookupPath_c[i] != nullptr; i++)
lookupPath.push_back(lookupPath_c[i]);

return new EvalState{nix::EvalState(nix::SearchPath::parse(searchPath), store->ptr)};
return new EvalState{nix::EvalState(nix::LookupPath::parse(lookupPath), store->ptr)};
}
NIXC_CATCH_ERRS_NULL
}
Expand Down
4 changes: 2 additions & 2 deletions src/libexpr-c/nix_api_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ nix_err nix_value_force_deep(nix_c_context * context, EvalState * state, Value *
* @brief Create a new Nix language evaluator state.
*
* @param[out] context Optional, stores error information
* @param[in] searchPath Array of strings corresponding to entries in NIX_PATH.
* @param[in] lookupPath Array of strings corresponding to entries in NIX_PATH.
* @param[in] store The Nix store to use.
* @return A new Nix state or NULL on failure.
*/
EvalState * nix_state_create(nix_c_context * context, const char ** searchPath, Store * store);
EvalState * nix_state_create(nix_c_context * context, const char ** lookupPath, Store * store);

/**
* @brief Frees a Nix state.
Expand Down
28 changes: 14 additions & 14 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>"))
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
17 changes: 7 additions & 10 deletions src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,6 @@ struct DebugTrace {
bool isError;
};

// Don't want Windows function
#undef SearchPath

class EvalState : public std::enable_shared_from_this<EvalState>
{
public:
Expand Down Expand Up @@ -311,9 +308,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().
Expand All @@ -335,12 +332,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
Expand Down Expand Up @@ -409,7 +406,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).
Expand All @@ -418,8 +415,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);

/**
Expand Down
14 changes: 7 additions & 7 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/libexpr/search-path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 { "" }
Expand All @@ -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;
}

Expand Down
Loading

0 comments on commit 6fd2f42

Please sign in to comment.