[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
08/118: Ensure that -I flags get included in nixPath
From: |
Ludovic Courtès |
Subject: |
08/118: Ensure that -I flags get included in nixPath |
Date: |
Tue, 19 May 2015 14:45:10 +0000 |
civodul pushed a commit to branch nix
in repository guix.
commit 39d72640c2459dc2fa689bfe8b756ee193f7b98a
Author: Eelco Dolstra <address@hidden>
Date: Mon May 26 16:50:36 2014 +0200
Ensure that -I flags get included in nixPath
Also fixes #261.
---
src/libexpr/common-opts.cc | 4 ++--
src/libexpr/common-opts.hh | 4 ++--
src/libexpr/eval.cc | 7 +++----
src/libexpr/eval.hh | 3 +--
src/libexpr/parser.y | 2 +-
src/nix-env/nix-env.cc | 15 ++++++++++++---
src/nix-instantiate/nix-instantiate.cc | 14 +++++++++++---
tests/lang/eval-okay-search-path.nix | 2 +-
8 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/src/libexpr/common-opts.cc b/src/libexpr/common-opts.cc
index 9b3421f..14a75f7 100644
--- a/src/libexpr/common-opts.cc
+++ b/src/libexpr/common-opts.cc
@@ -35,11 +35,11 @@ bool parseOptionArg(const string & arg, Strings::iterator &
i,
bool parseSearchPathArg(const string & arg, Strings::iterator & i,
- const Strings::iterator & argsEnd, EvalState & state)
+ const Strings::iterator & argsEnd, Strings & searchPath)
{
if (arg != "-I") return false;
if (i == argsEnd) throw UsageError(format("`%1%' requires an argument") %
arg);;
- state.addToSearchPath(*i++, true);
+ searchPath.push_back(*i++);
return true;
}
diff --git a/src/libexpr/common-opts.hh b/src/libexpr/common-opts.hh
index e2e3fe7..7593589 100644
--- a/src/libexpr/common-opts.hh
+++ b/src/libexpr/common-opts.hh
@@ -8,9 +8,9 @@ namespace nix {
bool parseOptionArg(const string & arg, Strings::iterator & i,
const Strings::iterator & argsEnd, EvalState & state,
Bindings & autoArgs);
-
+
bool parseSearchPathArg(const string & arg, Strings::iterator & i,
- const Strings::iterator & argsEnd, EvalState & state);
+ const Strings::iterator & argsEnd, Strings & searchPath);
Path lookupFileArg(EvalState & state, string s);
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 81abe5b..b6b69c2 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -153,7 +153,7 @@ static Symbol getName(const AttrName & name, EvalState &
state, Env & env)
}
-EvalState::EvalState()
+EvalState::EvalState(const Strings & _searchPath)
: sWith(symbols.create("<with>"))
, sOutPath(symbols.create("outPath"))
, sDrvPath(symbols.create("drvPath"))
@@ -219,11 +219,10 @@ EvalState::EvalState()
#endif
/* Initialise the Nix expression search path. */
- searchPathInsertionPoint = searchPath.end();
Strings paths = tokenizeString<Strings>(getEnv("NIX_PATH", ""), ":");
- foreach (Strings::iterator, i, paths) addToSearchPath(*i);
+ for (auto & i : _searchPath) addToSearchPath(i);
+ for (auto & i : paths) addToSearchPath(i);
addToSearchPath("nix=" + settings.nixDataDir + "/nix/corepkgs");
- searchPathInsertionPoint = searchPath.begin();
createBaseEnv();
}
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index ad4c6a4..200ec75 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -113,11 +113,10 @@ private:
typedef list<std::pair<string, Path> > SearchPath;
SearchPath searchPath;
- SearchPath::iterator searchPathInsertionPoint;
public:
- EvalState();
+ EvalState(const Strings & _searchPath);
~EvalState();
void addToSearchPath(const string & s, bool warn = false);
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 06d6d64..698e8ce 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -629,7 +629,7 @@ void EvalState::addToSearchPath(const string & s, bool warn)
path = absPath(path);
if (pathExists(path)) {
debug(format("adding path `%1%' to the search path") % path);
- searchPath.insert(searchPathInsertionPoint, std::pair<string,
Path>(prefix, path));
+ searchPath.push_back(std::pair<string, Path>(prefix, path));
} else if (warn)
printMsg(lvlError, format("warning: Nix search path entry `%1%' does
not exist, ignoring") % path);
}
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index 3db84ff..2d38f2a 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -58,6 +58,7 @@ struct Globals
bool removeAll;
string forceName;
bool prebuiltOnly;
+ Globals(const Strings & searchPath) : state(searchPath) { }
};
@@ -1351,7 +1352,17 @@ void run(Strings args)
Strings opFlags, opArgs, remaining;
Operation op = 0;
- Globals globals;
+ /* FIXME: hack. */
+ Strings searchPath;
+ Strings args2;
+ for (Strings::iterator i = args.begin(); i != args.end(); ) {
+ string arg = *i++;
+ if (!parseSearchPathArg(arg, i, args.end(), searchPath))
+ args2.push_back(arg);
+ }
+ args = args2;
+
+ Globals globals(searchPath);
globals.instSource.type = srcUnknown;
globals.instSource.nixExprPath = getDefNixExprPath();
@@ -1372,8 +1383,6 @@ void run(Strings args)
else if (parseOptionArg(arg, i, args.end(),
globals.state, globals.instSource.autoArgs))
;
- else if (parseSearchPathArg(arg, i, args.end(), globals.state))
- ;
else if (arg == "--force-name") // undocumented flag for
nix-install-package
globals.forceName = needArg(i, args, arg);
else if (arg == "--uninstall" || arg == "-e")
diff --git a/src/nix-instantiate/nix-instantiate.cc
b/src/nix-instantiate/nix-instantiate.cc
index 7cdabcb..cdd7452 100644
--- a/src/nix-instantiate/nix-instantiate.cc
+++ b/src/nix-instantiate/nix-instantiate.cc
@@ -91,7 +91,17 @@ void processExpr(EvalState & state, const Strings &
attrPaths,
void run(Strings args)
{
- EvalState state;
+ /* FIXME: hack. */
+ Strings searchPath;
+ Strings args2;
+ for (Strings::iterator i = args.begin(); i != args.end(); ) {
+ string arg = *i++;
+ if (!parseSearchPathArg(arg, i, args.end(), searchPath))
+ args2.push_back(arg);
+ }
+ args = args2;
+
+ EvalState state(searchPath);
Strings files;
bool readStdin = false;
bool fromArgs = false;
@@ -127,8 +137,6 @@ void run(Strings args)
}
else if (parseOptionArg(arg, i, args.end(), state, autoArgs))
;
- else if (parseSearchPathArg(arg, i, args.end(), state))
- ;
else if (arg == "--add-root") {
if (i == args.end())
throw UsageError("`--add-root' requires an argument");
diff --git a/tests/lang/eval-okay-search-path.nix
b/tests/lang/eval-okay-search-path.nix
index c9ea768..501d5f3 100644
--- a/tests/lang/eval-okay-search-path.nix
+++ b/tests/lang/eval-okay-search-path.nix
@@ -3,7 +3,7 @@ with builtins;
assert pathExists <nix/buildenv.nix>;
-assert length nixPath == 3;
+assert length nixPath == 6;
assert length (filter (x: x.prefix == "nix") nixPath) == 1;
assert length (filter (x: baseNameOf x.path == "dir4") nixPath) == 1;
- branch nix updated (a1dd396 -> 3bfa70b), Ludovic Courtès, 2015/05/19
- 01/118: Provide a more useful error message when a dynamic attr lookup fails, Ludovic Courtès, 2015/05/19
- 08/118: Ensure that -I flags get included in nixPath,
Ludovic Courtès <=
- 05/118: Shut up some signedness warnings, Ludovic Courtès, 2015/05/19
- 02/118: nix-store -l: Fetch build logs from the Internet, Ludovic Courtès, 2015/05/19
- 03/118: Disable parallel.sh test, Ludovic Courtès, 2015/05/19
- 07/118: Add constant ‘nixPath’, Ludovic Courtès, 2015/05/19
- 14/118: Use std::unordered_set, Ludovic Courtès, 2015/05/19
- 13/118: nix-build: --add-root also takes 1 parameter, Ludovic Courtès, 2015/05/19
- 16/118: Fix test, Ludovic Courtès, 2015/05/19
- 15/118: Sort nixPath attributes, Ludovic Courtès, 2015/05/19
- 10/118: Remove ExprBuiltin, Ludovic Courtès, 2015/05/19
- 09/118: Make the Nix search path declarative, Ludovic Courtès, 2015/05/19