From c10c61449f954702ae6d8092120321744acd82ff Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 4 Feb 2016 14:28:26 +0100 Subject: Eliminate the "store" global variable Also, move a few free-standing functions into StoreAPI and Derivation. Also, introduce a non-nullable smart pointer, ref, which is just a wrapper around std::shared_ptr ensuring that the pointer is never null. (For reference-counted values, this is better than passing a "T&", because the latter doesn't maintain the refcount. Usually, the caller will have a shared_ptr keeping the value alive, but that's not always the case, e.g., when passing a reference to a std::thread via std::bind.) --- src/nix-instantiate/nix-instantiate.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/nix-instantiate') diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc index 13a145a3b53e..a20c5ce6398d 100644 --- a/src/nix-instantiate/nix-instantiate.cc +++ b/src/nix-instantiate/nix-instantiate.cc @@ -9,7 +9,6 @@ #include "util.hh" #include "store-api.hh" #include "common-opts.hh" -#include "misc.hh" #include #include @@ -33,7 +32,7 @@ static bool indirectRoot = false; enum OutputKind { okPlain, okXML, okJSON }; -void processExpr(EvalState & state, const Strings & attrPaths, +void processExpr(ref store, EvalState & state, const Strings & attrPaths, bool parseOnly, bool strict, Bindings & autoArgs, bool evalOnly, OutputKind output, bool location, Expr * e) { @@ -80,7 +79,7 @@ void processExpr(EvalState & state, const Strings & attrPaths, else { Path rootName = gcRoot; if (++rootNr > 1) rootName += "-" + std::to_string(rootNr); - drvPath = addPermRoot(*store, drvPath, rootName, indirectRoot); + drvPath = addPermRoot(store, drvPath, rootName, indirectRoot); } std::cout << format("%1%%2%\n") % drvPath % (outputName != "out" ? "!" + outputName : ""); } @@ -158,9 +157,9 @@ int main(int argc, char * * argv) if (evalOnly && !wantsReadWrite) settings.readOnlyMode = true; - store = openStore(); + auto store = openStore(); - EvalState state(searchPath); + EvalState state(searchPath, store); state.repair = repair; Bindings & autoArgs(*evalAutoArgs(state, autoArgs_)); @@ -178,7 +177,7 @@ int main(int argc, char * * argv) if (readStdin) { Expr * e = parseStdin(state); - processExpr(state, attrPaths, parseOnly, strict, autoArgs, + processExpr(store, state, attrPaths, parseOnly, strict, autoArgs, evalOnly, outputKind, xmlOutputSourceLocation, e); } else if (files.empty() && !fromArgs) files.push_back("./default.nix"); @@ -187,7 +186,7 @@ int main(int argc, char * * argv) Expr * e = fromArgs ? state.parseExprFromString(i, absPath(".")) : state.parseExprFromFile(resolveExprPath(lookupFileArg(state, i))); - processExpr(state, attrPaths, parseOnly, strict, autoArgs, + processExpr(store, state, attrPaths, parseOnly, strict, autoArgs, evalOnly, outputKind, xmlOutputSourceLocation, e); } -- cgit 1.4.1