about summary refs log tree commit diff
path: root/src/libexpr/parser.y
diff options
context:
space:
mode:
Diffstat (limited to 'src/libexpr/parser.y')
-rw-r--r--src/libexpr/parser.y26
1 files changed, 22 insertions, 4 deletions
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<string, Path>(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 "";