diff options
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/Makefile.am | 2 | ||||
-rw-r--r-- | src/libstore/normalise.cc | 54 | ||||
-rw-r--r-- | src/libstore/normalise.hh | 32 | ||||
-rw-r--r-- | src/libstore/storeexpr.cc (renamed from src/libstore/expr.cc) | 31 | ||||
-rw-r--r-- | src/libstore/storeexpr.hh (renamed from src/libstore/expr.hh) | 24 |
5 files changed, 64 insertions, 79 deletions
diff --git a/src/libstore/Makefile.am b/src/libstore/Makefile.am index 472b1b079313..b365f57c682e 100644 --- a/src/libstore/Makefile.am +++ b/src/libstore/Makefile.am @@ -1,7 +1,7 @@ noinst_LIBRARIES = libstore.a libstore_a_SOURCES = \ - store.cc expr.cc normalise.cc exec.cc \ + store.cc storeexpr.cc normalise.cc exec.cc \ globals.cc db.cc references.cc pathlocks.cc AM_CXXFLAGS = -DSYSTEM=\"@host@\" -Wall \ diff --git a/src/libstore/normalise.cc b/src/libstore/normalise.cc index cb2bf4f5b183..c531e6784bcb 100644 --- a/src/libstore/normalise.cc +++ b/src/libstore/normalise.cc @@ -18,21 +18,21 @@ static Path useSuccessor(const Path & path) } -Path normaliseNixExpr(const Path & _nePath, PathSet pending) +Path normaliseStoreExpr(const Path & _nePath, PathSet pending) { startNest(nest, lvlTalkative, - format("normalising expression in `%1%'") % (string) _nePath); + format("normalising store expression in `%1%'") % (string) _nePath); /* Try to substitute the expression by any known successors in order to speed up the rewrite process. */ Path nePath = useSuccessor(_nePath); - /* Get the Nix expression. */ - NixExpr ne = exprFromPath(nePath, pending); + /* Get the store expression. */ + StoreExpr ne = storeExprFromPath(nePath, pending); /* If this is a normal form (i.e., a closure) we are done. */ - if (ne.type == NixExpr::neClosure) return nePath; - if (ne.type != NixExpr::neDerivation) abort(); + if (ne.type == StoreExpr::neClosure) return nePath; + if (ne.type != StoreExpr::neDerivation) abort(); /* Otherwise, it's a derivation expression, and we have to build it to @@ -51,8 +51,8 @@ Path normaliseNixExpr(const Path & _nePath, PathSet pending) Environment env; /* The result. */ - NixExpr nf; - nf.type = NixExpr::neClosure; + StoreExpr nf; + nf.type = StoreExpr::neClosure; /* The outputs are referenceable paths. */ @@ -78,10 +78,10 @@ Path normaliseNixExpr(const Path & _nePath, PathSet pending) { Path nePath2 = useSuccessor(nePath); if (nePath != nePath2) { - NixExpr ne = exprFromPath(nePath2, pending); + StoreExpr ne = storeExprFromPath(nePath2, pending); debug(format("skipping build of expression `%1%', someone beat us to it") % (string) nePath); - if (ne.type != NixExpr::neClosure) abort(); + if (ne.type != StoreExpr::neClosure) abort(); return nePath2; } } @@ -95,12 +95,12 @@ Path normaliseNixExpr(const Path & _nePath, PathSet pending) for (PathSet::iterator i = ne.derivation.inputs.begin(); i != ne.derivation.inputs.end(); i++) { - Path nfPath = normaliseNixExpr(*i, pending); + Path nfPath = normaliseStoreExpr(*i, pending); realiseClosure(nfPath, pending); /* !!! nfPath should be a root of the garbage collector while we are building */ - NixExpr ne = exprFromPath(nfPath, pending); - if (ne.type != NixExpr::neClosure) abort(); + StoreExpr ne = storeExprFromPath(nfPath, pending); + if (ne.type != StoreExpr::neClosure) abort(); for (ClosureElems::iterator j = ne.closure.elems.begin(); j != ne.closure.elems.end(); j++) { @@ -238,7 +238,7 @@ Path normaliseNixExpr(const Path & _nePath, PathSet pending) /* Write the normal form. This does not have to occur in the transaction below because writing terms is idem-potent. */ - ATerm nfTerm = unparseNixExpr(nf); + ATerm nfTerm = unparseStoreExpr(nf); printMsg(lvlVomit, format("normal form: %1%") % atPrint(nfTerm)); Path nfPath = writeTerm(nfTerm, "-s"); @@ -264,8 +264,8 @@ void realiseClosure(const Path & nePath, PathSet pending) { startNest(nest, lvlDebug, format("realising closure `%1%'") % nePath); - NixExpr ne = exprFromPath(nePath, pending); - if (ne.type != NixExpr::neClosure) + StoreExpr ne = storeExprFromPath(nePath, pending); + if (ne.type != StoreExpr::neClosure) throw Error(format("expected closure in `%1%'") % nePath); for (ClosureElems::const_iterator i = ne.closure.elems.begin(); @@ -286,7 +286,7 @@ void ensurePath(const Path & path, PathSet pending) i != subPaths.end(); i++) { try { - normaliseNixExpr(*i, pending); + normaliseStoreExpr(*i, pending); if (isValidPath(path)) return; throw Error(format("substitute failed to produce expected output path")); } catch (Error & e) { @@ -301,24 +301,24 @@ void ensurePath(const Path & path, PathSet pending) } -NixExpr exprFromPath(const Path & path, PathSet pending) +StoreExpr storeExprFromPath(const Path & path, PathSet pending) { ensurePath(path, pending); ATerm t = ATreadFromNamedFile(path.c_str()); if (!t) throw Error(format("cannot read aterm from `%1%'") % path); - return parseNixExpr(t); + return parseStoreExpr(t); } -PathSet nixExprRoots(const Path & nePath) +PathSet storeExprRoots(const Path & nePath) { PathSet paths; - NixExpr ne = exprFromPath(nePath); + StoreExpr ne = storeExprFromPath(nePath); - if (ne.type == NixExpr::neClosure) + if (ne.type == StoreExpr::neClosure) paths.insert(ne.closure.roots.begin(), ne.closure.roots.end()); - else if (ne.type == NixExpr::neDerivation) + else if (ne.type == StoreExpr::neDerivation) paths.insert(ne.derivation.outputs.begin(), ne.derivation.outputs.end()); else abort(); @@ -334,14 +334,14 @@ static void requisitesWorker(const Path & nePath, if (doneSet.find(nePath) != doneSet.end()) return; doneSet.insert(nePath); - NixExpr ne = exprFromPath(nePath); + StoreExpr ne = storeExprFromPath(nePath); - if (ne.type == NixExpr::neClosure) + if (ne.type == StoreExpr::neClosure) for (ClosureElems::iterator i = ne.closure.elems.begin(); i != ne.closure.elems.end(); i++) paths.insert(i->first); - else if (ne.type == NixExpr::neDerivation) + else if (ne.type == StoreExpr::neDerivation) for (PathSet::iterator i = ne.derivation.inputs.begin(); i != ne.derivation.inputs.end(); i++) requisitesWorker(*i, @@ -358,7 +358,7 @@ static void requisitesWorker(const Path & nePath, } -PathSet nixExprRequisites(const Path & nePath, +PathSet storeExprRequisites(const Path & nePath, bool includeExprs, bool includeSuccessors) { PathSet paths; diff --git a/src/libstore/normalise.hh b/src/libstore/normalise.hh index bbe846404cc0..1003858cbea7 100644 --- a/src/libstore/normalise.hh +++ b/src/libstore/normalise.hh @@ -1,16 +1,16 @@ #ifndef __NORMALISE_H #define __NORMALISE_H -#include "expr.hh" +#include "storeexpr.hh" -/* Normalise a Nix expression. That is, if the expression is a +/* Normalise a store expression. That is, if the expression is a derivation, a path containing an equivalent closure expression is returned. This requires that the derivation is performed, unless a successor is known. */ -Path normaliseNixExpr(const Path & nePath, PathSet pending = PathSet()); +Path normaliseStoreExpr(const Path & nePath, PathSet pending = PathSet()); -/* Realise a closure expression in the file system. +/* Realise a closure store expression in the file system. The pending paths are those that are already being realised. This prevents infinite recursion for paths realised through a substitute @@ -22,23 +22,25 @@ void realiseClosure(const Path & nePath, PathSet pending = PathSet()); realising a substitute. */ void ensurePath(const Path & path, PathSet pending = PathSet()); -/* Read a Nix expression, after ensuring its existence through +/* Read a store expression, after ensuring its existence through ensurePath(). */ -NixExpr exprFromPath(const Path & path, PathSet pending = PathSet()); +StoreExpr storeExprFromPath(const Path & path, PathSet pending = PathSet()); -/* Get the list of root (output) paths of the given Nix expression. */ -PathSet nixExprRoots(const Path & nePath); +/* Get the list of root (output) paths of the given store + expression. */ +PathSet storeExprRoots(const Path & nePath); -/* Get the list of paths that are required to realise the given +/* Get the list of paths that are required to realise the given store expression. For a derive expression, this is the union of - requisites of the inputs; for a closure expression, it is the path of - each element in the closure. If `includeExprs' is true, include the - paths of the Nix expressions themselves. If `includeSuccessors' is - true, include the requisites of successors. */ -PathSet nixExprRequisites(const Path & nePath, + requisites of the inputs; for a closure expression, it is the path + of each element in the closure. If `includeExprs' is true, include + the paths of the store expressions themselves. If + `includeSuccessors' is true, include the requisites of + successors. */ +PathSet storeExprRequisites(const Path & nePath, bool includeExprs, bool includeSuccessors); -/* Return the list of the paths of all known Nix expressions whose +/* Return the list of the paths of all known store expressions whose output paths are completely contained in the set `outputs'. */ PathSet findGenerators(const PathSet & outputs); diff --git a/src/libstore/expr.cc b/src/libstore/storeexpr.cc index 7bb1f5306129..e11cd5bfe55b 100644 --- a/src/libstore/expr.cc +++ b/src/libstore/storeexpr.cc @@ -1,21 +1,8 @@ -#include "expr.hh" +#include "storeexpr.hh" #include "globals.hh" #include "store.hh" -Error badTerm(const format & f, ATerm t) -{ - char * s = ATwriteToString(t); - if (!s) throw Error("cannot print term"); - if (strlen(s) > 1000) { - int len; - s = ATwriteToSharedString(t, &len); - if (!s) throw Error("cannot print term"); - } - return Error(format("%1%, in `%2%'") % f.str() % (string) s); -} - - Hash hashTerm(ATerm t) { return hashString(atPrint(t)); @@ -138,14 +125,14 @@ static bool parseDerivation(ATerm t, Derivation & derivation) } -NixExpr parseNixExpr(ATerm t) +StoreExpr parseStoreExpr(ATerm t) { - NixExpr ne; + StoreExpr ne; if (parseClosure(t, ne.closure)) - ne.type = NixExpr::neClosure; + ne.type = StoreExpr::neClosure; else if (parseDerivation(t, ne.derivation)) - ne.type = NixExpr::neDerivation; - else throw badTerm("not a Nix expression", t); + ne.type = StoreExpr::neDerivation; + else throw badTerm("not a store expression", t); return ne; } @@ -200,11 +187,11 @@ static ATerm unparseDerivation(const Derivation & derivation) } -ATerm unparseNixExpr(const NixExpr & ne) +ATerm unparseStoreExpr(const StoreExpr & ne) { - if (ne.type == NixExpr::neClosure) + if (ne.type == StoreExpr::neClosure) return unparseClosure(ne.closure); - else if (ne.type == NixExpr::neDerivation) + else if (ne.type == StoreExpr::neDerivation) return unparseDerivation(ne.derivation); else abort(); } diff --git a/src/libstore/expr.hh b/src/libstore/storeexpr.hh index f5abf9af0d3a..07676c3ccedb 100644 --- a/src/libstore/expr.hh +++ b/src/libstore/storeexpr.hh @@ -1,11 +1,11 @@ -#ifndef __FSTATE_H -#define __FSTATE_H +#ifndef __STOREEXPR_H +#define __STOREEXPR_H #include "aterm.hh" #include "store.hh" -/* Abstract syntax of Nix expressions. */ +/* Abstract syntax of store expressions. */ struct ClosureElem { @@ -25,14 +25,14 @@ typedef map<string, string> StringPairs; struct Derivation { PathSet outputs; - PathSet inputs; /* Nix expressions, not actual inputs */ + PathSet inputs; /* Store expressions, not actual inputs */ string platform; Path builder; Strings args; StringPairs env; }; -struct NixExpr +struct StoreExpr { enum { neClosure, neDerivation } type; Closure closure; @@ -40,21 +40,17 @@ struct NixExpr }; -/* Throw an exception with an error message containing the given - aterm. */ -Error badTerm(const format & f, ATerm t); - /* Hash an aterm. */ Hash hashTerm(ATerm t); /* Write an aterm to the Nix store directory, and return its path. */ Path writeTerm(ATerm t, const string & suffix); -/* Parse a Nix expression. */ -NixExpr parseNixExpr(ATerm t); +/* Parse a store expression. */ +StoreExpr parseStoreExpr(ATerm t); -/* Parse a Nix expression. */ -ATerm unparseNixExpr(const NixExpr & ne); +/* Parse a store expression. */ +ATerm unparseStoreExpr(const StoreExpr & ne); -#endif /* !__FSTATE_H */ +#endif /* !__STOREEXPR_H */ |