* 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 <nixpkgs> { }); then you can say $ nix-build -I nixpkgs=/home/eelco/src/stdenv-updates
This commit is contained in:
parent
1578b2261d
commit
c7101dac0b
5 changed files with 28 additions and 9 deletions
|
@ -213,8 +213,9 @@ private:
|
||||||
|
|
||||||
std::map<Path, Expr *> parseTrees;
|
std::map<Path, Expr *> parseTrees;
|
||||||
|
|
||||||
Paths searchPath;
|
typedef list<std::pair<string, Path> > SearchPath;
|
||||||
Paths::iterator searchPathInsertionPoint;
|
SearchPath searchPath;
|
||||||
|
SearchPath::iterator searchPathInsertionPoint;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -530,18 +530,36 @@ Expr * EvalState::parseExprFromString(const string & s, const Path & basePath)
|
||||||
|
|
||||||
void EvalState::addToSearchPath(const string & s)
|
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)) {
|
if (pathExists(path)) {
|
||||||
debug(format("adding path `%1%' to the search path") % 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)
|
Path EvalState::findFile(const string & path)
|
||||||
{
|
{
|
||||||
foreach (Paths::iterator, i, searchPath) {
|
foreach (SearchPath::iterator, i, searchPath) {
|
||||||
Path res = *i + "/" + path;
|
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);
|
if (pathExists(res)) return canonPath(res);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
"abc"
|
"abcc"
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
-I lang/dir1 -I lang/dir2
|
-I lang/dir1 -I lang/dir2 -I dir5=lang/dir3
|
|
@ -1,3 +1,3 @@
|
||||||
import <a.nix> + import <b.nix> + import <c.nix>
|
import <a.nix> + import <b.nix> + import <c.nix> + import <dir5/c.nix>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue