From c7101dac0bd2631e50846194fc841ef5ef77461f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 6 Aug 2011 17:48:57 +0000 Subject: * Allow redirections in search path entries. E.g. if you have a directory /home/eelco/src/stdenv-updates that you want to use as the directory for import such as with (import { }); then you can say $ nix-build -I nixpkgs=/home/eelco/src/stdenv-updates --- src/libexpr/eval.hh | 5 +++-- src/libexpr/parser.y | 26 ++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) (limited to 'src/libexpr') diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 1583665bad19..413234f2bf19 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -213,8 +213,9 @@ private: std::map parseTrees; - Paths searchPath; - Paths::iterator searchPathInsertionPoint; + typedef list > SearchPath; + SearchPath searchPath; + SearchPath::iterator searchPathInsertionPoint; public: diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index cd63666dc5f0..e54f6fe0a7b5 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -530,18 +530,36 @@ Expr * EvalState::parseExprFromString(const string & s, const Path & basePath) void EvalState::addToSearchPath(const string & s) { - Path path = absPath(s); + size_t pos = s.find('='); + string prefix; + Path path; + if (pos == string::npos) { + path = s; + } else { + prefix = string(s, 0, pos); + path = string(s, pos + 1); + } + + path = absPath(path); if (pathExists(path)) { debug(format("adding path `%1%' to the search path") % path); - searchPath.insert(searchPathInsertionPoint, path); + searchPath.insert(searchPathInsertionPoint, std::pair(prefix, path)); } } Path EvalState::findFile(const string & path) { - foreach (Paths::iterator, i, searchPath) { - Path res = *i + "/" + path; + foreach (SearchPath::iterator, i, searchPath) { + Path res; + if (i->first.empty()) + res = i->second + "/" + path; + else { + if (path.compare(0, i->first.size(), i->first) != 0 || + (path.size() > i->first.size() && path[i->first.size()] != '/')) + continue; + res = i->second + "/" + string(path, i->first.size()); + } if (pathExists(res)) return canonPath(res); } return ""; -- cgit 1.4.1