Merge pull request #10573 from RCoeurjoly/Rename_SearchPath

Rename SearchPath to LookupPath and searchPath to lookupPath
This commit is contained in:
Robert Hensing 2024-04-21 17:33:46 +02:00 committed by GitHub
commit 6fd2f42c2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
29 changed files with 133 additions and 139 deletions

View File

@ -128,10 +128,10 @@ ref<EvalState> EvalCommand::getEvalState()
evalState = evalState =
#if HAVE_BOEHMGC #if HAVE_BOEHMGC
std::allocate_shared<EvalState>(traceable_allocator<EvalState>(), std::allocate_shared<EvalState>(traceable_allocator<EvalState>(),
searchPath, getEvalStore(), getStore()) lookupPath, getEvalStore(), getStore())
#else #else
std::make_shared<EvalState>( std::make_shared<EvalState>(
searchPath, getEvalStore(), getStore()) lookupPath, getEvalStore(), getStore())
#endif #endif
; ;

View File

@ -125,7 +125,7 @@ MixEvalArgs::MixEvalArgs()
.category = category, .category = category,
.labels = {"path"}, .labels = {"path"},
.handler = {[&](std::string s) { .handler = {[&](std::string s) {
searchPath.elements.emplace_back(SearchPath::Elem::parse(s)); lookupPath.elements.emplace_back(LookupPath::Elem::parse(s));
}} }}
}); });

View File

@ -23,7 +23,7 @@ struct MixEvalArgs : virtual Args, virtual MixRepair
Bindings * getAutoArgs(EvalState & state); Bindings * getAutoArgs(EvalState & state);
SearchPath searchPath; LookupPath lookupPath;
std::optional<std::string> evalStoreUrl; std::optional<std::string> evalStoreUrl;

View File

@ -77,7 +77,7 @@ struct NixRepl
std::unique_ptr<ReplInteracter> interacter; 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); std::function<AnnotatedValues()> getValues);
virtual ~NixRepl() = default; virtual ~NixRepl() = default;
@ -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) std::function<NixRepl::AnnotatedValues()> getValues)
: AbstractNixRepl(state) : AbstractNixRepl(state)
, debugTraceIndex(0) , debugTraceIndex(0)
@ -508,7 +508,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
// runProgram redirects stdout to a StringSink, // runProgram redirects stdout to a StringSink,
// using runProgram2 to allow editors to display their UI // 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 // Reload right after exiting the editor
state->resetFileCache(); state->resetFileCache();
@ -784,11 +784,11 @@ void NixRepl::evalString(std::string s, Value & v)
std::unique_ptr<AbstractNixRepl> AbstractNixRepl::create( 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) std::function<AnnotatedValues()> getValues)
{ {
return std::make_unique<NixRepl>( return std::make_unique<NixRepl>(
searchPath, lookupPath,
openStore(), openStore(),
state, state,
getValues getValues
@ -804,9 +804,9 @@ ReplExitStatus AbstractNixRepl::runSimple(
NixRepl::AnnotatedValues values; NixRepl::AnnotatedValues values;
return values; return values;
}; };
SearchPath searchPath = {}; LookupPath lookupPath = {};
auto repl = std::make_unique<NixRepl>( auto repl = std::make_unique<NixRepl>(
searchPath, lookupPath,
openStore(), openStore(),
evalState, evalState,
getValues getValues

View File

@ -20,7 +20,7 @@ struct AbstractNixRepl
typedef std::vector<std::pair<Value*,std::string>> AnnotatedValues; typedef std::vector<std::pair<Value*,std::string>> AnnotatedValues;
static std::unique_ptr<AbstractNixRepl> create( 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); std::function<AnnotatedValues()> getValues);
static ReplExitStatus runSimple( static ReplExitStatus runSimple(

View File

@ -85,17 +85,17 @@ nix_err nix_value_force_deep(nix_c_context * context, EvalState * state, Value *
NIXC_CATCH_ERRS 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) if (context)
context->last_err_code = NIX_OK; context->last_err_code = NIX_OK;
try { try {
nix::Strings searchPath; nix::Strings lookupPath;
if (searchPath_c != nullptr) if (lookupPath_c != nullptr)
for (size_t i = 0; searchPath_c[i] != nullptr; i++) for (size_t i = 0; lookupPath_c[i] != nullptr; i++)
searchPath.push_back(searchPath_c[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 NIXC_CATCH_ERRS_NULL
} }

View File

@ -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. * @brief Create a new Nix language evaluator state.
* *
* @param[out] context Optional, stores error information * @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. * @param[in] store The Nix store to use.
* @return A new Nix state or NULL on failure. * @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. * @brief Frees a Nix state.

View File

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

View File

@ -161,9 +161,6 @@ struct DebugTrace {
bool isError; bool isError;
}; };
// Don't want Windows function
#undef SearchPath
class EvalState : public std::enable_shared_from_this<EvalState> class EvalState : public std::enable_shared_from_this<EvalState>
{ {
public: public:
@ -311,9 +308,9 @@ private:
#endif #endif
FileEvalCache fileEvalCache; 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(). * Cache used by prim_match().
@ -335,12 +332,12 @@ private:
public: public:
EvalState( EvalState(
const SearchPath & _searchPath, const LookupPath & _lookupPath,
ref<Store> store, ref<Store> store,
std::shared_ptr<Store> buildStore = nullptr); std::shared_ptr<Store> buildStore = nullptr);
~EvalState(); ~EvalState();
SearchPath getSearchPath() { return searchPath; } LookupPath getLookupPath() { return lookupPath; }
/** /**
* Return a `SourcePath` that refers to `path` in the root * Return a `SourcePath` that refers to `path` in the root
@ -409,7 +406,7 @@ public:
* Look up a file in the search path. * Look up a file in the search path.
*/ */
SourcePath findFile(const std::string_view 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). * Try to resolve a search path value (not the optional key part).
@ -418,8 +415,8 @@ public:
* *
* If it is not found, return `std::nullopt` * If it is not found, return `std::nullopt`
*/ */
std::optional<std::string> resolveSearchPathPath( std::optional<std::string> resolveLookupPathPath(
const SearchPath::Path & elem, const LookupPath::Path & elem,
bool initAccessControl = false); 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"); state.forceList(*args[0], pos, "while evaluating the first argument passed to builtins.findFile");
SearchPath searchPath; LookupPath lookupPath;
for (auto v2 : args[0]->listItems()) { for (auto v2 : args[0]->listItems()) {
state.forceAttrs(*v2, pos, "while evaluating an element of the list passed to builtins.findFile"); 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(); ).atPos(pos).debugThrow();
} }
searchPath.elements.emplace_back(SearchPath::Elem { lookupPath.elements.emplace_back(LookupPath::Elem {
.prefix = SearchPath::Prefix { .s = prefix }, .prefix = LookupPath::Prefix { .s = prefix },
.path = SearchPath::Path { .s = path }, .path = LookupPath::Path { .s = path },
}); });
} }
auto path = state.forceStringNoCtx(*args[1], pos, "while evaluating the second argument passed to builtins.findFile"); 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 { static RegisterPrimOp primop_findFile(PrimOp {
@ -4629,8 +4629,8 @@ void EvalState::createBaseEnv()
}); });
/* Add a value containing the current Nix expression search path. */ /* Add a value containing the current Nix expression search path. */
auto list = buildList(searchPath.elements.size()); auto list = buildList(lookupPath.elements.size());
for (const auto & [n, i] : enumerate(searchPath.elements)) { for (const auto & [n, i] : enumerate(lookupPath.elements)) {
auto attrs = buildBindings(2); auto attrs = buildBindings(2);
attrs.alloc("path").mkString(i.path.s); attrs.alloc("path").mkString(i.path.s);
attrs.alloc("prefix").mkString(i.prefix.s); attrs.alloc("prefix").mkString(i.prefix.s);

View File

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

View File

@ -8,17 +8,14 @@
namespace nix { namespace nix {
// Do not want the windows macro (alias to `SearchPathA`)
#undef SearchPath
/** /**
* A "search path" is a list of ways look for something, used with * A "search path" is a list of ways look for something, used with
* `builtins.findFile` and `< >` lookup expressions. * `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 * Each element is tried in succession when looking up a path. The first
* element to completely match wins. * element to completely match wins.
@ -26,16 +23,16 @@ struct SearchPath
struct Elem; 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 * 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 * 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; 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 * It is either a path or a URL (with certain restrictions / extra
* structure). * structure).
@ -43,7 +40,7 @@ struct SearchPath
* If the prefix of the path we are looking up matches, we then * 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 * check if the rest of the path points to something that exists
* within the directory denoted by this. If so, the * 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 * pointed to by the rest of the path we are looking up is the
* result. * result.
*/ */
@ -54,24 +51,24 @@ struct SearchPath
* when looking up. (The actual lookup entry point is in `EvalState` * when looking up. (The actual lookup entry point is in `EvalState`
* not in this class.) * 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 * 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; 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 * If the path possibly matches this search path element, return the
@ -82,7 +79,7 @@ struct SearchPath::Prefix
std::optional<std::string_view> suffixIfPotentialMatch(std::string_view path) const; 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. * The location of a search path item, as a path or URL.
@ -91,21 +88,21 @@ struct SearchPath::Path
*/ */
std::string s; std::string s;
GENERATE_CMP(SearchPath::Path, me->s); GENERATE_CMP(LookupPath::Path, me->s);
}; };
struct SearchPath::Elem struct LookupPath::Elem
{ {
Prefix prefix; Prefix prefix;
Path path; 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);
}; };
} }

View File

@ -385,7 +385,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
runProgram(RunOptions { runProgram(RunOptions {
.program = "git", .program = "git",
.searchPath = true, .lookupPath = true,
// FIXME: git stderr messes up our progress indicator, so // FIXME: git stderr messes up our progress indicator, so
// we're using --quiet for now. Should process its stderr. // we're using --quiet for now. Should process its stderr.
.args = gitArgs, .args = gitArgs,

View File

@ -24,7 +24,7 @@ static RunOptions hgOptions(const Strings & args)
return { return {
.program = "hg", .program = "hg",
.searchPath = true, .lookupPath = true,
.args = args, .args = args,
.environment = env .environment = env
}; };

View File

@ -77,7 +77,7 @@ void handleDiffHook(
try { try {
auto diffRes = runProgram(RunOptions { auto diffRes = runProgram(RunOptions {
.program = diffHook, .program = diffHook,
.searchPath = true, .lookupPath = true,
.args = {tryA, tryB, drvPath, tmpDir}, .args = {tryA, tryB, drvPath, tmpDir},
.uid = uid, .uid = uid,
.gid = gid, .gid = gid,

View File

@ -80,14 +80,14 @@ pid_t startProcess(std::function<void()> fun, const ProcessOptions & options = P
* Run a program and return its stdout in a string (i.e., like the * Run a program and return its stdout in a string (i.e., like the
* shell backtick operator). * shell backtick operator).
*/ */
std::string runProgram(Path program, bool searchPath = false, std::string runProgram(Path program, bool lookupPath = false,
const Strings & args = Strings(), const Strings & args = Strings(),
const std::optional<std::string> & input = {}, bool isInteractive = false); const std::optional<std::string> & input = {}, bool isInteractive = false);
struct RunOptions struct RunOptions
{ {
Path program; Path program;
bool searchPath = true; bool lookupPath = true;
Strings args; Strings args;
#ifndef _WIN32 #ifndef _WIN32
std::optional<uid_t> uid; std::optional<uid_t> uid;

View File

@ -245,10 +245,10 @@ pid_t startProcess(std::function<void()> fun, const ProcessOptions & options)
} }
std::string runProgram(Path program, bool searchPath, const Strings & args, std::string runProgram(Path program, bool lookupPath, const Strings & args,
const std::optional<std::string> & input, bool isInteractive) const std::optional<std::string> & input, bool isInteractive)
{ {
auto res = runProgram(RunOptions {.program = program, .searchPath = searchPath, .args = args, .input = input, .isInteractive = isInteractive}); auto res = runProgram(RunOptions {.program = program, .lookupPath = lookupPath, .args = args, .input = input, .isInteractive = isInteractive});
if (!statusOk(res.first)) if (!statusOk(res.first))
throw ExecError(res.first, "program '%1%' %2%", program, statusToString(res.first)); throw ExecError(res.first, "program '%1%' %2%", program, statusToString(res.first));
@ -335,7 +335,7 @@ void runProgram2(const RunOptions & options)
restoreProcessContext(); restoreProcessContext();
if (options.searchPath) if (options.lookupPath)
execvp(options.program.c_str(), stringsToCharPtrs(args_).data()); execvp(options.program.c_str(), stringsToCharPtrs(args_).data());
// This allows you to refer to a program with a pathname relative // This allows you to refer to a program with a pathname relative
// to the PATH variable. // to the PATH variable.

View File

@ -28,7 +28,7 @@
namespace nix { namespace nix {
std::string runProgram(Path program, bool searchPath, const Strings & args, std::string runProgram(Path program, bool lookupPath, const Strings & args,
const std::optional<std::string> & input, bool isInteractive) const std::optional<std::string> & input, bool isInteractive)
{ {
throw UnimplementedError("Cannot shell out to git on Windows yet"); throw UnimplementedError("Cannot shell out to git on Windows yet");

View File

@ -258,7 +258,7 @@ static void main_nix_build(int argc, char * * argv)
auto store = openStore(); auto store = openStore();
auto evalStore = myArgs.evalStoreUrl ? openStore(*myArgs.evalStoreUrl) : store; auto evalStore = myArgs.evalStoreUrl ? openStore(*myArgs.evalStoreUrl) : store;
auto state = std::make_unique<EvalState>(myArgs.searchPath, evalStore, store); auto state = std::make_unique<EvalState>(myArgs.lookupPath, evalStore, store);
state->repair = myArgs.repair; state->repair = myArgs.repair;
if (myArgs.repair) buildMode = bmRepair; if (myArgs.repair) buildMode = bmRepair;

View File

@ -1525,7 +1525,7 @@ static int main_nix_env(int argc, char * * argv)
auto store = openStore(); auto store = openStore();
globals.state = std::shared_ptr<EvalState>(new EvalState(myArgs.searchPath, store)); globals.state = std::shared_ptr<EvalState>(new EvalState(myArgs.lookupPath, store));
globals.state->repair = myArgs.repair; globals.state->repair = myArgs.repair;
globals.instSource.nixExprPath = std::make_shared<SourcePath>( globals.instSource.nixExprPath = std::make_shared<SourcePath>(

View File

@ -157,7 +157,7 @@ static int main_nix_instantiate(int argc, char * * argv)
auto store = openStore(); auto store = openStore();
auto evalStore = myArgs.evalStoreUrl ? openStore(*myArgs.evalStoreUrl) : store; auto evalStore = myArgs.evalStoreUrl ? openStore(*myArgs.evalStoreUrl) : store;
auto state = std::make_unique<EvalState>(myArgs.searchPath, evalStore, store); auto state = std::make_unique<EvalState>(myArgs.lookupPath, evalStore, store);
state->repair = myArgs.repair; state->repair = myArgs.repair;
Bindings & autoArgs = *myArgs.getAutoArgs(*state); Bindings & autoArgs = *myArgs.getAutoArgs(*state);

View File

@ -687,7 +687,7 @@ struct CmdDevelop : Common, MixEnvironment
} }
} }
runProgramInStore(store, UseSearchPath::Use, shell, args, buildEnvironment.getSystem()); runProgramInStore(store, UseLookupPath::Use, shell, args, buildEnvironment.getSystem());
#endif #endif
} }
}; };

View File

@ -49,7 +49,7 @@ struct CmdFmt : SourceExprCommand {
} }
} }
runProgramInStore(store, UseSearchPath::DontUse, app.program, programArgs); runProgramInStore(store, UseLookupPath::DontUse, app.program, programArgs);
}; };
}; };

View File

@ -193,7 +193,7 @@ static int main_nix_prefetch_url(int argc, char * * argv)
startProgressBar(); startProgressBar();
auto store = openStore(); auto store = openStore();
auto state = std::make_unique<EvalState>(myArgs.searchPath, store); auto state = std::make_unique<EvalState>(myArgs.lookupPath, store);
Bindings & autoArgs = *myArgs.getAutoArgs(*state); Bindings & autoArgs = *myArgs.getAutoArgs(*state);

View File

@ -78,7 +78,7 @@ struct CmdRepl : RawInstallablesCommand
return values; return values;
}; };
auto repl = AbstractNixRepl::create( auto repl = AbstractNixRepl::create(
searchPath, lookupPath,
openStore(), openStore(),
state, state,
getValues getValues

View File

@ -25,7 +25,7 @@ std::string chrootHelperName = "__run_in_chroot";
namespace nix { namespace nix {
void runProgramInStore(ref<Store> store, void runProgramInStore(ref<Store> store,
UseSearchPath useSearchPath, UseLookupPath useLookupPath,
const std::string & program, const std::string & program,
const Strings & args, const Strings & args,
std::optional<std::string_view> system) std::optional<std::string_view> system)
@ -61,7 +61,7 @@ void runProgramInStore(ref<Store> store,
linux::setPersonality(*system); linux::setPersonality(*system);
#endif #endif
if (useSearchPath == UseSearchPath::Use) if (useLookupPath == UseLookupPath::Use)
execvp(program.c_str(), stringsToCharPtrs(args).data()); execvp(program.c_str(), stringsToCharPtrs(args).data());
else else
execv(program.c_str(), stringsToCharPtrs(args).data()); execv(program.c_str(), stringsToCharPtrs(args).data());
@ -142,7 +142,7 @@ struct CmdShell : InstallablesCommand, MixEnvironment
Strings args; Strings args;
for (auto & arg : command) args.push_back(arg); for (auto & arg : command) args.push_back(arg);
runProgramInStore(store, UseSearchPath::Use, *command.begin(), args); runProgramInStore(store, UseLookupPath::Use, *command.begin(), args);
} }
}; };
@ -204,7 +204,7 @@ struct CmdRun : InstallableValueCommand
Strings allArgs{app.program}; Strings allArgs{app.program};
for (auto & i : args) allArgs.push_back(i); for (auto & i : args) allArgs.push_back(i);
runProgramInStore(store, UseSearchPath::DontUse, app.program, allArgs); runProgramInStore(store, UseLookupPath::DontUse, app.program, allArgs);
} }
}; };

View File

@ -5,13 +5,13 @@
namespace nix { namespace nix {
enum struct UseSearchPath { enum struct UseLookupPath {
Use, Use,
DontUse DontUse
}; };
void runProgramInStore(ref<Store> store, void runProgramInStore(ref<Store> store,
UseSearchPath useSearchPath, UseLookupPath useLookupPath,
const std::string & program, const std::string & program,
const Strings & args, const Strings & args,
std::optional<std::string_view> system = std::nullopt); std::optional<std::string_view> system = std::nullopt);

View File

@ -147,7 +147,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
auto req = FileTransferRequest((std::string&) settings.upgradeNixStorePathUrl); auto req = FileTransferRequest((std::string&) settings.upgradeNixStorePathUrl);
auto res = getFileTransfer()->download(req); auto res = getFileTransfer()->download(req);
auto state = std::make_unique<EvalState>(SearchPath{}, store); auto state = std::make_unique<EvalState>(LookupPath{}, store);
auto v = state->allocValue(); auto v = state->allocValue();
state->eval(state->parseExprFromString(res.data, state->rootPath(CanonPath("/no-such-path"))), *v); state->eval(state->parseExprFromString(res.data, state->rootPath(CanonPath("/no-such-path"))), *v);
Bindings & bindings(*state->allocBindings(0)); Bindings & bindings(*state->allocBindings(0));

View File

@ -5,85 +5,85 @@
namespace nix { namespace nix {
TEST(SearchPathElem, parse_justPath) { TEST(LookupPathElem, parse_justPath) {
ASSERT_EQ( ASSERT_EQ(
SearchPath::Elem::parse("foo"), LookupPath::Elem::parse("foo"),
(SearchPath::Elem { (LookupPath::Elem {
.prefix = SearchPath::Prefix { .s = "" }, .prefix = LookupPath::Prefix { .s = "" },
.path = SearchPath::Path { .s = "foo" }, .path = LookupPath::Path { .s = "foo" },
})); }));
} }
TEST(SearchPathElem, parse_emptyPrefix) { TEST(LookupPathElem, parse_emptyPrefix) {
ASSERT_EQ( ASSERT_EQ(
SearchPath::Elem::parse("=foo"), LookupPath::Elem::parse("=foo"),
(SearchPath::Elem { (LookupPath::Elem {
.prefix = SearchPath::Prefix { .s = "" }, .prefix = LookupPath::Prefix { .s = "" },
.path = SearchPath::Path { .s = "foo" }, .path = LookupPath::Path { .s = "foo" },
})); }));
} }
TEST(SearchPathElem, parse_oneEq) { TEST(LookupPathElem, parse_oneEq) {
ASSERT_EQ( ASSERT_EQ(
SearchPath::Elem::parse("foo=bar"), LookupPath::Elem::parse("foo=bar"),
(SearchPath::Elem { (LookupPath::Elem {
.prefix = SearchPath::Prefix { .s = "foo" }, .prefix = LookupPath::Prefix { .s = "foo" },
.path = SearchPath::Path { .s = "bar" }, .path = LookupPath::Path { .s = "bar" },
})); }));
} }
TEST(SearchPathElem, parse_twoEqs) { TEST(LookupPathElem, parse_twoEqs) {
ASSERT_EQ( ASSERT_EQ(
SearchPath::Elem::parse("foo=bar=baz"), LookupPath::Elem::parse("foo=bar=baz"),
(SearchPath::Elem { (LookupPath::Elem {
.prefix = SearchPath::Prefix { .s = "foo" }, .prefix = LookupPath::Prefix { .s = "foo" },
.path = SearchPath::Path { .s = "bar=baz" }, .path = LookupPath::Path { .s = "bar=baz" },
})); }));
} }
TEST(SearchPathElem, suffixIfPotentialMatch_justPath) { TEST(LookupPathElem, suffixIfPotentialMatch_justPath) {
SearchPath::Prefix prefix { .s = "" }; LookupPath::Prefix prefix { .s = "" };
ASSERT_EQ(prefix.suffixIfPotentialMatch("any/thing"), std::optional { "any/thing" }); ASSERT_EQ(prefix.suffixIfPotentialMatch("any/thing"), std::optional { "any/thing" });
} }
TEST(SearchPathElem, suffixIfPotentialMatch_misleadingPrefix1) { TEST(LookupPathElem, suffixIfPotentialMatch_misleadingPrefix1) {
SearchPath::Prefix prefix { .s = "foo" }; LookupPath::Prefix prefix { .s = "foo" };
ASSERT_EQ(prefix.suffixIfPotentialMatch("fooX"), std::nullopt); ASSERT_EQ(prefix.suffixIfPotentialMatch("fooX"), std::nullopt);
} }
TEST(SearchPathElem, suffixIfPotentialMatch_misleadingPrefix2) { TEST(LookupPathElem, suffixIfPotentialMatch_misleadingPrefix2) {
SearchPath::Prefix prefix { .s = "foo" }; LookupPath::Prefix prefix { .s = "foo" };
ASSERT_EQ(prefix.suffixIfPotentialMatch("fooX/bar"), std::nullopt); ASSERT_EQ(prefix.suffixIfPotentialMatch("fooX/bar"), std::nullopt);
} }
TEST(SearchPathElem, suffixIfPotentialMatch_partialPrefix) { TEST(LookupPathElem, suffixIfPotentialMatch_partialPrefix) {
SearchPath::Prefix prefix { .s = "fooX" }; LookupPath::Prefix prefix { .s = "fooX" };
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo"), std::nullopt); ASSERT_EQ(prefix.suffixIfPotentialMatch("foo"), std::nullopt);
} }
TEST(SearchPathElem, suffixIfPotentialMatch_exactPrefix) { TEST(LookupPathElem, suffixIfPotentialMatch_exactPrefix) {
SearchPath::Prefix prefix { .s = "foo" }; LookupPath::Prefix prefix { .s = "foo" };
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo"), std::optional { "" }); ASSERT_EQ(prefix.suffixIfPotentialMatch("foo"), std::optional { "" });
} }
TEST(SearchPathElem, suffixIfPotentialMatch_multiKey) { TEST(LookupPathElem, suffixIfPotentialMatch_multiKey) {
SearchPath::Prefix prefix { .s = "foo/bar" }; LookupPath::Prefix prefix { .s = "foo/bar" };
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/bar/baz"), std::optional { "baz" }); ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/bar/baz"), std::optional { "baz" });
} }
TEST(SearchPathElem, suffixIfPotentialMatch_trailingSlash) { TEST(LookupPathElem, suffixIfPotentialMatch_trailingSlash) {
SearchPath::Prefix prefix { .s = "foo" }; LookupPath::Prefix prefix { .s = "foo" };
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/"), std::optional { "" }); ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/"), std::optional { "" });
} }
TEST(SearchPathElem, suffixIfPotentialMatch_trailingDoubleSlash) { TEST(LookupPathElem, suffixIfPotentialMatch_trailingDoubleSlash) {
SearchPath::Prefix prefix { .s = "foo" }; LookupPath::Prefix prefix { .s = "foo" };
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo//"), std::optional { "/" }); ASSERT_EQ(prefix.suffixIfPotentialMatch("foo//"), std::optional { "/" });
} }
TEST(SearchPathElem, suffixIfPotentialMatch_trailingPath) { TEST(LookupPathElem, suffixIfPotentialMatch_trailingPath) {
SearchPath::Prefix prefix { .s = "foo" }; LookupPath::Prefix prefix { .s = "foo" };
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/bar/baz"), std::optional { "bar/baz" }); ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/bar/baz"), std::optional { "bar/baz" });
} }