mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-21 21:46:15 +02:00
Merge pull request #10573 from RCoeurjoly/Rename_SearchPath
Rename SearchPath to LookupPath and searchPath to lookupPath
This commit is contained in:
commit
6fd2f42c2d
29 changed files with 133 additions and 139 deletions
|
@ -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
|
||||
;
|
||||
|
||||
|
|
|
@ -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));
|
||||
}}
|
||||
});
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ struct MixEvalArgs : virtual Args, virtual MixRepair
|
|||
|
||||
Bindings * getAutoArgs(EvalState & state);
|
||||
|
||||
SearchPath searchPath;
|
||||
LookupPath lookupPath;
|
||||
|
||||
std::optional<std::string> evalStoreUrl;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
@ -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().
|
||||
|
@ -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
|
||||
|
@ -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).
|
||||
|
@ -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);
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,17 +8,14 @@
|
|||
|
||||
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
|
||||
* `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 +23,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 +40,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 +51,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 +79,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 +88,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);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -385,7 +385,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
|||
|
||||
runProgram(RunOptions {
|
||||
.program = "git",
|
||||
.searchPath = true,
|
||||
.lookupPath = true,
|
||||
// FIXME: git stderr messes up our progress indicator, so
|
||||
// we're using --quiet for now. Should process its stderr.
|
||||
.args = gitArgs,
|
||||
|
|
|
@ -24,7 +24,7 @@ static RunOptions hgOptions(const Strings & args)
|
|||
|
||||
return {
|
||||
.program = "hg",
|
||||
.searchPath = true,
|
||||
.lookupPath = true,
|
||||
.args = args,
|
||||
.environment = env
|
||||
};
|
||||
|
|
|
@ -77,7 +77,7 @@ void handleDiffHook(
|
|||
try {
|
||||
auto diffRes = runProgram(RunOptions {
|
||||
.program = diffHook,
|
||||
.searchPath = true,
|
||||
.lookupPath = true,
|
||||
.args = {tryA, tryB, drvPath, tmpDir},
|
||||
.uid = uid,
|
||||
.gid = gid,
|
||||
|
|
|
@ -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
|
||||
* shell backtick operator).
|
||||
*/
|
||||
std::string runProgram(Path program, bool searchPath = false,
|
||||
std::string runProgram(Path program, bool lookupPath = false,
|
||||
const Strings & args = Strings(),
|
||||
const std::optional<std::string> & input = {}, bool isInteractive = false);
|
||||
|
||||
struct RunOptions
|
||||
{
|
||||
Path program;
|
||||
bool searchPath = true;
|
||||
bool lookupPath = true;
|
||||
Strings args;
|
||||
#ifndef _WIN32
|
||||
std::optional<uid_t> uid;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
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))
|
||||
throw ExecError(res.first, "program '%1%' %2%", program, statusToString(res.first));
|
||||
|
@ -335,7 +335,7 @@ void runProgram2(const RunOptions & options)
|
|||
|
||||
restoreProcessContext();
|
||||
|
||||
if (options.searchPath)
|
||||
if (options.lookupPath)
|
||||
execvp(options.program.c_str(), stringsToCharPtrs(args_).data());
|
||||
// This allows you to refer to a program with a pathname relative
|
||||
// to the PATH variable.
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
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)
|
||||
{
|
||||
throw UnimplementedError("Cannot shell out to git on Windows yet");
|
||||
|
|
|
@ -258,7 +258,7 @@ static void main_nix_build(int argc, char * * argv)
|
|||
auto store = openStore();
|
||||
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;
|
||||
if (myArgs.repair) buildMode = bmRepair;
|
||||
|
||||
|
|
|
@ -1525,7 +1525,7 @@ static int main_nix_env(int argc, char * * argv)
|
|||
|
||||
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.instSource.nixExprPath = std::make_shared<SourcePath>(
|
||||
|
|
|
@ -157,7 +157,7 @@ static int main_nix_instantiate(int argc, char * * argv)
|
|||
auto store = openStore();
|
||||
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;
|
||||
|
||||
Bindings & autoArgs = *myArgs.getAutoArgs(*state);
|
||||
|
|
|
@ -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
|
||||
}
|
||||
};
|
||||
|
|
|
@ -49,7 +49,7 @@ struct CmdFmt : SourceExprCommand {
|
|||
}
|
||||
}
|
||||
|
||||
runProgramInStore(store, UseSearchPath::DontUse, app.program, programArgs);
|
||||
runProgramInStore(store, UseLookupPath::DontUse, app.program, programArgs);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -193,7 +193,7 @@ static int main_nix_prefetch_url(int argc, char * * argv)
|
|||
startProgressBar();
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ struct CmdRepl : RawInstallablesCommand
|
|||
return values;
|
||||
};
|
||||
auto repl = AbstractNixRepl::create(
|
||||
searchPath,
|
||||
lookupPath,
|
||||
openStore(),
|
||||
state,
|
||||
getValues
|
||||
|
|
|
@ -25,7 +25,7 @@ std::string chrootHelperName = "__run_in_chroot";
|
|||
namespace nix {
|
||||
|
||||
void runProgramInStore(ref<Store> store,
|
||||
UseSearchPath useSearchPath,
|
||||
UseLookupPath useLookupPath,
|
||||
const std::string & program,
|
||||
const Strings & args,
|
||||
std::optional<std::string_view> system)
|
||||
|
@ -61,7 +61,7 @@ void runProgramInStore(ref<Store> store,
|
|||
linux::setPersonality(*system);
|
||||
#endif
|
||||
|
||||
if (useSearchPath == UseSearchPath::Use)
|
||||
if (useLookupPath == UseLookupPath::Use)
|
||||
execvp(program.c_str(), stringsToCharPtrs(args).data());
|
||||
else
|
||||
execv(program.c_str(), stringsToCharPtrs(args).data());
|
||||
|
@ -142,7 +142,7 @@ struct CmdShell : InstallablesCommand, MixEnvironment
|
|||
Strings args;
|
||||
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};
|
||||
for (auto & i : args) allArgs.push_back(i);
|
||||
|
||||
runProgramInStore(store, UseSearchPath::DontUse, app.program, allArgs);
|
||||
runProgramInStore(store, UseLookupPath::DontUse, app.program, allArgs);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
enum struct UseSearchPath {
|
||||
enum struct UseLookupPath {
|
||||
Use,
|
||||
DontUse
|
||||
};
|
||||
|
||||
void runProgramInStore(ref<Store> store,
|
||||
UseSearchPath useSearchPath,
|
||||
UseLookupPath useLookupPath,
|
||||
const std::string & program,
|
||||
const Strings & args,
|
||||
std::optional<std::string_view> system = std::nullopt);
|
||||
|
|
|
@ -147,7 +147,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
|
|||
auto req = FileTransferRequest((std::string&) settings.upgradeNixStorePathUrl);
|
||||
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();
|
||||
state->eval(state->parseExprFromString(res.data, state->rootPath(CanonPath("/no-such-path"))), *v);
|
||||
Bindings & bindings(*state->allocBindings(0));
|
||||
|
|
|
@ -5,85 +5,85 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
TEST(SearchPathElem, parse_justPath) {
|
||||
TEST(LookupPathElem, parse_justPath) {
|
||||
ASSERT_EQ(
|
||||
SearchPath::Elem::parse("foo"),
|
||||
(SearchPath::Elem {
|
||||
.prefix = SearchPath::Prefix { .s = "" },
|
||||
.path = SearchPath::Path { .s = "foo" },
|
||||
LookupPath::Elem::parse("foo"),
|
||||
(LookupPath::Elem {
|
||||
.prefix = LookupPath::Prefix { .s = "" },
|
||||
.path = LookupPath::Path { .s = "foo" },
|
||||
}));
|
||||
}
|
||||
|
||||
TEST(SearchPathElem, parse_emptyPrefix) {
|
||||
TEST(LookupPathElem, parse_emptyPrefix) {
|
||||
ASSERT_EQ(
|
||||
SearchPath::Elem::parse("=foo"),
|
||||
(SearchPath::Elem {
|
||||
.prefix = SearchPath::Prefix { .s = "" },
|
||||
.path = SearchPath::Path { .s = "foo" },
|
||||
LookupPath::Elem::parse("=foo"),
|
||||
(LookupPath::Elem {
|
||||
.prefix = LookupPath::Prefix { .s = "" },
|
||||
.path = LookupPath::Path { .s = "foo" },
|
||||
}));
|
||||
}
|
||||
|
||||
TEST(SearchPathElem, parse_oneEq) {
|
||||
TEST(LookupPathElem, parse_oneEq) {
|
||||
ASSERT_EQ(
|
||||
SearchPath::Elem::parse("foo=bar"),
|
||||
(SearchPath::Elem {
|
||||
.prefix = SearchPath::Prefix { .s = "foo" },
|
||||
.path = SearchPath::Path { .s = "bar" },
|
||||
LookupPath::Elem::parse("foo=bar"),
|
||||
(LookupPath::Elem {
|
||||
.prefix = LookupPath::Prefix { .s = "foo" },
|
||||
.path = LookupPath::Path { .s = "bar" },
|
||||
}));
|
||||
}
|
||||
|
||||
TEST(SearchPathElem, parse_twoEqs) {
|
||||
TEST(LookupPathElem, parse_twoEqs) {
|
||||
ASSERT_EQ(
|
||||
SearchPath::Elem::parse("foo=bar=baz"),
|
||||
(SearchPath::Elem {
|
||||
.prefix = SearchPath::Prefix { .s = "foo" },
|
||||
.path = SearchPath::Path { .s = "bar=baz" },
|
||||
LookupPath::Elem::parse("foo=bar=baz"),
|
||||
(LookupPath::Elem {
|
||||
.prefix = LookupPath::Prefix { .s = "foo" },
|
||||
.path = LookupPath::Path { .s = "bar=baz" },
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
TEST(SearchPathElem, suffixIfPotentialMatch_justPath) {
|
||||
SearchPath::Prefix prefix { .s = "" };
|
||||
TEST(LookupPathElem, suffixIfPotentialMatch_justPath) {
|
||||
LookupPath::Prefix prefix { .s = "" };
|
||||
ASSERT_EQ(prefix.suffixIfPotentialMatch("any/thing"), std::optional { "any/thing" });
|
||||
}
|
||||
|
||||
TEST(SearchPathElem, suffixIfPotentialMatch_misleadingPrefix1) {
|
||||
SearchPath::Prefix prefix { .s = "foo" };
|
||||
TEST(LookupPathElem, suffixIfPotentialMatch_misleadingPrefix1) {
|
||||
LookupPath::Prefix prefix { .s = "foo" };
|
||||
ASSERT_EQ(prefix.suffixIfPotentialMatch("fooX"), std::nullopt);
|
||||
}
|
||||
|
||||
TEST(SearchPathElem, suffixIfPotentialMatch_misleadingPrefix2) {
|
||||
SearchPath::Prefix prefix { .s = "foo" };
|
||||
TEST(LookupPathElem, suffixIfPotentialMatch_misleadingPrefix2) {
|
||||
LookupPath::Prefix prefix { .s = "foo" };
|
||||
ASSERT_EQ(prefix.suffixIfPotentialMatch("fooX/bar"), std::nullopt);
|
||||
}
|
||||
|
||||
TEST(SearchPathElem, suffixIfPotentialMatch_partialPrefix) {
|
||||
SearchPath::Prefix prefix { .s = "fooX" };
|
||||
TEST(LookupPathElem, suffixIfPotentialMatch_partialPrefix) {
|
||||
LookupPath::Prefix prefix { .s = "fooX" };
|
||||
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo"), std::nullopt);
|
||||
}
|
||||
|
||||
TEST(SearchPathElem, suffixIfPotentialMatch_exactPrefix) {
|
||||
SearchPath::Prefix prefix { .s = "foo" };
|
||||
TEST(LookupPathElem, suffixIfPotentialMatch_exactPrefix) {
|
||||
LookupPath::Prefix prefix { .s = "foo" };
|
||||
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo"), std::optional { "" });
|
||||
}
|
||||
|
||||
TEST(SearchPathElem, suffixIfPotentialMatch_multiKey) {
|
||||
SearchPath::Prefix prefix { .s = "foo/bar" };
|
||||
TEST(LookupPathElem, suffixIfPotentialMatch_multiKey) {
|
||||
LookupPath::Prefix prefix { .s = "foo/bar" };
|
||||
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/bar/baz"), std::optional { "baz" });
|
||||
}
|
||||
|
||||
TEST(SearchPathElem, suffixIfPotentialMatch_trailingSlash) {
|
||||
SearchPath::Prefix prefix { .s = "foo" };
|
||||
TEST(LookupPathElem, suffixIfPotentialMatch_trailingSlash) {
|
||||
LookupPath::Prefix prefix { .s = "foo" };
|
||||
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/"), std::optional { "" });
|
||||
}
|
||||
|
||||
TEST(SearchPathElem, suffixIfPotentialMatch_trailingDoubleSlash) {
|
||||
SearchPath::Prefix prefix { .s = "foo" };
|
||||
TEST(LookupPathElem, suffixIfPotentialMatch_trailingDoubleSlash) {
|
||||
LookupPath::Prefix prefix { .s = "foo" };
|
||||
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo//"), std::optional { "/" });
|
||||
}
|
||||
|
||||
TEST(SearchPathElem, suffixIfPotentialMatch_trailingPath) {
|
||||
SearchPath::Prefix prefix { .s = "foo" };
|
||||
TEST(LookupPathElem, suffixIfPotentialMatch_trailingPath) {
|
||||
LookupPath::Prefix prefix { .s = "foo" };
|
||||
ASSERT_EQ(prefix.suffixIfPotentialMatch("foo/bar/baz"), std::optional { "bar/baz" });
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue