From ce92d1bf1434562f5b80320c503768c4d06f1f8d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 18 Nov 2003 11:22:29 +0000 Subject: * "Nix expression" -> "store expression". * More refactoring. --- src/fix-ng/Makefile.am | 2 +- src/fix-ng/eval.cc | 1 - src/fix-ng/eval.hh | 5 +- src/fix-ng/fix-expr.cc | 215 ---------------------------------------------- src/fix-ng/fix-expr.hh | 75 ---------------- src/fix-ng/fix.cc | 1 - src/fix-ng/fixexpr.cc | 215 ++++++++++++++++++++++++++++++++++++++++++++++ src/fix-ng/fixexpr.hh | 75 ++++++++++++++++ src/fix-ng/parser.cc | 4 +- src/fix-ng/parser.hh | 2 +- src/fix-ng/primops.cc | 28 +++--- src/libstore/Makefile.am | 2 +- src/libstore/expr.cc | 210 -------------------------------------------- src/libstore/expr.hh | 60 ------------- src/libstore/normalise.cc | 54 ++++++------ src/libstore/normalise.hh | 32 +++---- src/libstore/storeexpr.cc | 197 ++++++++++++++++++++++++++++++++++++++++++ src/libstore/storeexpr.hh | 56 ++++++++++++ src/libutil/aterm.cc | 13 +++ src/libutil/aterm.hh | 5 ++ src/nix/dotgraph.cc | 8 +- src/nix/dotgraph.hh | 2 +- src/nix/nix-help.txt | 4 +- src/nix/nix.cc | 18 ++-- 24 files changed, 643 insertions(+), 641 deletions(-) delete mode 100644 src/fix-ng/fix-expr.cc delete mode 100644 src/fix-ng/fix-expr.hh create mode 100644 src/fix-ng/fixexpr.cc create mode 100644 src/fix-ng/fixexpr.hh delete mode 100644 src/libstore/expr.cc delete mode 100644 src/libstore/expr.hh create mode 100644 src/libstore/storeexpr.cc create mode 100644 src/libstore/storeexpr.hh diff --git a/src/fix-ng/Makefile.am b/src/fix-ng/Makefile.am index df3d1730892d..d30a5b2ea065 100644 --- a/src/fix-ng/Makefile.am +++ b/src/fix-ng/Makefile.am @@ -1,6 +1,6 @@ bin_PROGRAMS = fix-ng -fix_ng_SOURCES = fix-expr.cc parser.cc eval.cc primops.cc fix.cc +fix_ng_SOURCES = fixexpr.cc parser.cc eval.cc primops.cc fix.cc fix_ng_LDADD = ../libmain/libmain.a ../libstore/libstore.a ../libutil/libutil.a \ ../boost/format/libformat.a -L../../externals/inst/lib -ldb_cxx \ -lsglr -lATB -lconversion -lasfix2 -lmept -lATerm diff --git a/src/fix-ng/eval.cc b/src/fix-ng/eval.cc index 57cca4c4a827..b110c3a4a41c 100644 --- a/src/fix-ng/eval.cc +++ b/src/fix-ng/eval.cc @@ -1,5 +1,4 @@ #include "eval.hh" -#include "expr.hh" #include "parser.hh" #include "primops.hh" diff --git a/src/fix-ng/eval.hh b/src/fix-ng/eval.hh index 9be3ae2da073..061c840a7576 100644 --- a/src/fix-ng/eval.hh +++ b/src/fix-ng/eval.hh @@ -3,8 +3,9 @@ #include -#include "fix-expr.hh" -#include "expr.hh" +#include "aterm.hh" +#include "hash.hh" +#include "fixexpr.hh" typedef map DrvPaths; diff --git a/src/fix-ng/fix-expr.cc b/src/fix-ng/fix-expr.cc deleted file mode 100644 index e9c5a3ba633f..000000000000 --- a/src/fix-ng/fix-expr.cc +++ /dev/null @@ -1,215 +0,0 @@ -#include "fix-expr.hh" -#include "expr.hh" - - -ATermMap::ATermMap(unsigned int initialSize, unsigned int maxLoadPct) -{ - table = ATtableCreate(initialSize, maxLoadPct); - if (!table) throw Error("cannot create ATerm table"); -} - - -ATermMap::ATermMap(const ATermMap & map) - : table(0) -{ - ATermList keys = map.keys(); - - /* !!! adjust allocation for load pct */ - table = ATtableCreate(ATgetLength(keys), map.maxLoadPct); - if (!table) throw Error("cannot create ATerm table"); - - for (ATermIterator i(keys); i; ++i) - set(*i, map.get(*i)); -} - - -ATermMap::~ATermMap() -{ - if (table) ATtableDestroy(table); -} - - -void ATermMap::set(ATerm key, ATerm value) -{ - return ATtablePut(table, key, value); -} - - -void ATermMap::set(const string & key, ATerm value) -{ - set(string2ATerm(key), value); -} - - -ATerm ATermMap::get(ATerm key) const -{ - return ATtableGet(table, key); -} - - -ATerm ATermMap::get(const string & key) const -{ - return get(string2ATerm(key)); -} - - -void ATermMap::remove(ATerm key) -{ - ATtableRemove(table, key); -} - - -void ATermMap::remove(const string & key) -{ - remove(string2ATerm(key)); -} - - -ATermList ATermMap::keys() const -{ - ATermList keys = ATtableKeys(table); - if (!keys) throw Error("cannot query aterm map keys"); - return keys; -} - - -ATerm string2ATerm(const string & s) -{ - return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s.c_str(), 0, ATtrue)); -} - - -string aterm2String(ATerm t) -{ - return ATgetName(ATgetAFun(t)); -} - - -ATerm bottomupRewrite(TermFun & f, ATerm e) -{ - if (ATgetType(e) == AT_APPL) { - AFun fun = ATgetAFun(e); - int arity = ATgetArity(fun); - ATermList args = ATempty; - - for (int i = arity - 1; i >= 0; i--) - args = ATinsert(args, bottomupRewrite(f, ATgetArgument(e, i))); - - e = (ATerm) ATmakeApplList(fun, args); - } - - else if (ATgetType(e) == AT_LIST) { - ATermList in = (ATermList) e; - ATermList out = ATempty; - - for (ATermIterator i(in); i; ++i) - out = ATinsert(out, bottomupRewrite(f, *i)); - - e = (ATerm) ATreverse(out); - } - - return f(e); -} - - -void queryAllAttrs(Expr e, ATermMap & attrs) -{ - ATMatcher m; - ATermList bnds; - if (!(atMatch(m, e) >> "Attrs" >> bnds)) - throw badTerm("expected attribute set", e); - - for (ATermIterator i(bnds); i; ++i) { - string s; - Expr e; - if (!(atMatch(m, *i) >> "Bind" >> s >> e)) - abort(); /* can't happen */ - attrs.set(s, e); - } -} - - -Expr queryAttr(Expr e, const string & name) -{ - ATermMap attrs; - queryAllAttrs(e, attrs); - return attrs.get(name); -} - - -Expr makeAttrs(const ATermMap & attrs) -{ - ATermList bnds = ATempty; - for (ATermIterator i(attrs.keys()); i; ++i) - bnds = ATinsert(bnds, - ATmake("Bind(, )", *i, attrs.get(*i))); - return ATmake("Attrs()", ATreverse(bnds)); -} - - -Expr substitute(const ATermMap & subs, Expr e) -{ - ATMatcher m; - string s; - - if (atMatch(m, e) >> "Var" >> s) { - Expr sub = subs.get(s); - return sub ? sub : e; - } - - /* In case of a function, filter out all variables bound by this - function. */ - ATermList formals; - ATerm body; - if (atMatch(m, e) >> "Function" >> formals >> body) { - ATermMap subs2(subs); - for (ATermIterator i(formals); i; ++i) { - Expr def; - if (!(atMatch(m, *i) >> "NoDefFormal" >> s) && - !(atMatch(m, *i) >> "DefFormal" >> s >> def)) - abort(); - subs2.remove(s); - } - return ATmake("Function(, )", formals, - substitute(subs2, body)); - } - - /* Idem for a mutually recursive attribute set. */ - ATermList bindings; - if (atMatch(m, e) >> "Rec" >> bindings) { - ATermMap subs2(subs); - for (ATermIterator i(bindings); i; ++i) { - Expr e; - if (!(atMatch(m, *i) >> "Bind" >> s >> e)) - abort(); /* can't happen */ - subs2.remove(s); - } - return ATmake("Rec()", substitute(subs2, (ATerm) bindings)); - } - - if (ATgetType(e) == AT_APPL) { - AFun fun = ATgetAFun(e); - int arity = ATgetArity(fun); - ATermList args = ATempty; - - for (int i = arity - 1; i >= 0; i--) - args = ATinsert(args, substitute(subs, ATgetArgument(e, i))); - - return (ATerm) ATmakeApplList(fun, args); - } - - if (ATgetType(e) == AT_LIST) { - ATermList out = ATempty; - for (ATermIterator i((ATermList) e); i; ++i) - out = ATinsert(out, substitute(subs, *i)); - return (ATerm) ATreverse(out); - } - - return e; -} - - -Expr makeBool(bool b) -{ - return b ? ATmake("Bool(True)") : ATmake("Bool(False)"); -} diff --git a/src/fix-ng/fix-expr.hh b/src/fix-ng/fix-expr.hh deleted file mode 100644 index 6c1e51d9ccd6..000000000000 --- a/src/fix-ng/fix-expr.hh +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef __FIXEXPR_H -#define __FIXEXPR_H - -#include - -#include - -#include "util.hh" - - -/* Fix expressions are represented as ATerms. The maximal sharing - property of the ATerm library allows us to implement caching of - normals forms efficiently. */ -typedef ATerm Expr; - - -/* Mappings from ATerms to ATerms. This is just a wrapper around - ATerm tables. */ -class ATermMap -{ -private: - unsigned int maxLoadPct; - ATermTable table; - -public: - ATermMap(unsigned int initialSize = 16, unsigned int maxLoadPct = 75); - ATermMap(const ATermMap & map); - ~ATermMap(); - - void set(ATerm key, ATerm value); - void set(const string & key, ATerm value); - - ATerm get(ATerm key) const; - ATerm get(const string & key) const; - - void remove(ATerm key); - void remove(const string & key); - - ATermList keys() const; -}; - - -/* Convert a string to an ATerm (i.e., a quoted nullary function - applicaton). */ -ATerm string2ATerm(const string & s); -string aterm2String(ATerm t); - -/* Generic bottomup traversal over ATerms. The traversal first - recursively descends into subterms, and then applies the given term - function to the resulting term. */ -struct TermFun -{ - virtual ATerm operator () (ATerm e) = 0; -}; -ATerm bottomupRewrite(TermFun & f, ATerm e); - -/* Query all attributes in an attribute set expression. The - expression must be in normal form. */ -void queryAllAttrs(Expr e, ATermMap & attrs); - -/* Query a specific attribute from an attribute set expression. The - expression must be in normal form. */ -Expr queryAttr(Expr e, const string & name); - -/* Create an attribute set expression from an Attrs value. */ -Expr makeAttrs(const ATermMap & attrs); - -/* Perform a set of substitutions on an expression. */ -Expr substitute(const ATermMap & subs, Expr e); - -/* Create an expression representing a boolean. */ -Expr makeBool(bool b); - - -#endif /* !__FIXEXPR_H */ diff --git a/src/fix-ng/fix.cc b/src/fix-ng/fix.cc index 3b7dae38eb77..e407aaf44346 100644 --- a/src/fix-ng/fix.cc +++ b/src/fix-ng/fix.cc @@ -4,7 +4,6 @@ #include "globals.hh" #include "normalise.hh" #include "shared.hh" -#include "expr.hh" #include "eval.hh" diff --git a/src/fix-ng/fixexpr.cc b/src/fix-ng/fixexpr.cc new file mode 100644 index 000000000000..721fa8afa5f2 --- /dev/null +++ b/src/fix-ng/fixexpr.cc @@ -0,0 +1,215 @@ +#include "fixexpr.hh" +#include "storeexpr.hh" + + +ATermMap::ATermMap(unsigned int initialSize, unsigned int maxLoadPct) +{ + table = ATtableCreate(initialSize, maxLoadPct); + if (!table) throw Error("cannot create ATerm table"); +} + + +ATermMap::ATermMap(const ATermMap & map) + : table(0) +{ + ATermList keys = map.keys(); + + /* !!! adjust allocation for load pct */ + table = ATtableCreate(ATgetLength(keys), map.maxLoadPct); + if (!table) throw Error("cannot create ATerm table"); + + for (ATermIterator i(keys); i; ++i) + set(*i, map.get(*i)); +} + + +ATermMap::~ATermMap() +{ + if (table) ATtableDestroy(table); +} + + +void ATermMap::set(ATerm key, ATerm value) +{ + return ATtablePut(table, key, value); +} + + +void ATermMap::set(const string & key, ATerm value) +{ + set(string2ATerm(key), value); +} + + +ATerm ATermMap::get(ATerm key) const +{ + return ATtableGet(table, key); +} + + +ATerm ATermMap::get(const string & key) const +{ + return get(string2ATerm(key)); +} + + +void ATermMap::remove(ATerm key) +{ + ATtableRemove(table, key); +} + + +void ATermMap::remove(const string & key) +{ + remove(string2ATerm(key)); +} + + +ATermList ATermMap::keys() const +{ + ATermList keys = ATtableKeys(table); + if (!keys) throw Error("cannot query aterm map keys"); + return keys; +} + + +ATerm string2ATerm(const string & s) +{ + return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s.c_str(), 0, ATtrue)); +} + + +string aterm2String(ATerm t) +{ + return ATgetName(ATgetAFun(t)); +} + + +ATerm bottomupRewrite(TermFun & f, ATerm e) +{ + if (ATgetType(e) == AT_APPL) { + AFun fun = ATgetAFun(e); + int arity = ATgetArity(fun); + ATermList args = ATempty; + + for (int i = arity - 1; i >= 0; i--) + args = ATinsert(args, bottomupRewrite(f, ATgetArgument(e, i))); + + e = (ATerm) ATmakeApplList(fun, args); + } + + else if (ATgetType(e) == AT_LIST) { + ATermList in = (ATermList) e; + ATermList out = ATempty; + + for (ATermIterator i(in); i; ++i) + out = ATinsert(out, bottomupRewrite(f, *i)); + + e = (ATerm) ATreverse(out); + } + + return f(e); +} + + +void queryAllAttrs(Expr e, ATermMap & attrs) +{ + ATMatcher m; + ATermList bnds; + if (!(atMatch(m, e) >> "Attrs" >> bnds)) + throw badTerm("expected attribute set", e); + + for (ATermIterator i(bnds); i; ++i) { + string s; + Expr e; + if (!(atMatch(m, *i) >> "Bind" >> s >> e)) + abort(); /* can't happen */ + attrs.set(s, e); + } +} + + +Expr queryAttr(Expr e, const string & name) +{ + ATermMap attrs; + queryAllAttrs(e, attrs); + return attrs.get(name); +} + + +Expr makeAttrs(const ATermMap & attrs) +{ + ATermList bnds = ATempty; + for (ATermIterator i(attrs.keys()); i; ++i) + bnds = ATinsert(bnds, + ATmake("Bind(, )", *i, attrs.get(*i))); + return ATmake("Attrs()", ATreverse(bnds)); +} + + +Expr substitute(const ATermMap & subs, Expr e) +{ + ATMatcher m; + string s; + + if (atMatch(m, e) >> "Var" >> s) { + Expr sub = subs.get(s); + return sub ? sub : e; + } + + /* In case of a function, filter out all variables bound by this + function. */ + ATermList formals; + ATerm body; + if (atMatch(m, e) >> "Function" >> formals >> body) { + ATermMap subs2(subs); + for (ATermIterator i(formals); i; ++i) { + Expr def; + if (!(atMatch(m, *i) >> "NoDefFormal" >> s) && + !(atMatch(m, *i) >> "DefFormal" >> s >> def)) + abort(); + subs2.remove(s); + } + return ATmake("Function(, )", formals, + substitute(subs2, body)); + } + + /* Idem for a mutually recursive attribute set. */ + ATermList bindings; + if (atMatch(m, e) >> "Rec" >> bindings) { + ATermMap subs2(subs); + for (ATermIterator i(bindings); i; ++i) { + Expr e; + if (!(atMatch(m, *i) >> "Bind" >> s >> e)) + abort(); /* can't happen */ + subs2.remove(s); + } + return ATmake("Rec()", substitute(subs2, (ATerm) bindings)); + } + + if (ATgetType(e) == AT_APPL) { + AFun fun = ATgetAFun(e); + int arity = ATgetArity(fun); + ATermList args = ATempty; + + for (int i = arity - 1; i >= 0; i--) + args = ATinsert(args, substitute(subs, ATgetArgument(e, i))); + + return (ATerm) ATmakeApplList(fun, args); + } + + if (ATgetType(e) == AT_LIST) { + ATermList out = ATempty; + for (ATermIterator i((ATermList) e); i; ++i) + out = ATinsert(out, substitute(subs, *i)); + return (ATerm) ATreverse(out); + } + + return e; +} + + +Expr makeBool(bool b) +{ + return b ? ATmake("Bool(True)") : ATmake("Bool(False)"); +} diff --git a/src/fix-ng/fixexpr.hh b/src/fix-ng/fixexpr.hh new file mode 100644 index 000000000000..6c1e51d9ccd6 --- /dev/null +++ b/src/fix-ng/fixexpr.hh @@ -0,0 +1,75 @@ +#ifndef __FIXEXPR_H +#define __FIXEXPR_H + +#include + +#include + +#include "util.hh" + + +/* Fix expressions are represented as ATerms. The maximal sharing + property of the ATerm library allows us to implement caching of + normals forms efficiently. */ +typedef ATerm Expr; + + +/* Mappings from ATerms to ATerms. This is just a wrapper around + ATerm tables. */ +class ATermMap +{ +private: + unsigned int maxLoadPct; + ATermTable table; + +public: + ATermMap(unsigned int initialSize = 16, unsigned int maxLoadPct = 75); + ATermMap(const ATermMap & map); + ~ATermMap(); + + void set(ATerm key, ATerm value); + void set(const string & key, ATerm value); + + ATerm get(ATerm key) const; + ATerm get(const string & key) const; + + void remove(ATerm key); + void remove(const string & key); + + ATermList keys() const; +}; + + +/* Convert a string to an ATerm (i.e., a quoted nullary function + applicaton). */ +ATerm string2ATerm(const string & s); +string aterm2String(ATerm t); + +/* Generic bottomup traversal over ATerms. The traversal first + recursively descends into subterms, and then applies the given term + function to the resulting term. */ +struct TermFun +{ + virtual ATerm operator () (ATerm e) = 0; +}; +ATerm bottomupRewrite(TermFun & f, ATerm e); + +/* Query all attributes in an attribute set expression. The + expression must be in normal form. */ +void queryAllAttrs(Expr e, ATermMap & attrs); + +/* Query a specific attribute from an attribute set expression. The + expression must be in normal form. */ +Expr queryAttr(Expr e, const string & name); + +/* Create an attribute set expression from an Attrs value. */ +Expr makeAttrs(const ATermMap & attrs); + +/* Perform a set of substitutions on an expression. */ +Expr substitute(const ATermMap & subs, Expr e); + +/* Create an expression representing a boolean. */ +Expr makeBool(bool b); + + +#endif /* !__FIXEXPR_H */ diff --git a/src/fix-ng/parser.cc b/src/fix-ng/parser.cc index 710ea6a86de0..eaa41b3963ef 100644 --- a/src/fix-ng/parser.cc +++ b/src/fix-ng/parser.cc @@ -10,10 +10,10 @@ extern "C" { #include } +#include "aterm.hh" #include "parser.hh" #include "shared.hh" -#include "fix-expr.hh" -#include "expr.hh" +#include "fixexpr.hh" #include "parse-table.h" diff --git a/src/fix-ng/parser.hh b/src/fix-ng/parser.hh index c56a339a3f7c..e44987dd014b 100644 --- a/src/fix-ng/parser.hh +++ b/src/fix-ng/parser.hh @@ -1,7 +1,7 @@ #ifndef __PARSER_H #define __PARSER_H -#include "fix-expr.hh" +#include "fixexpr.hh" Expr parseExprFromFile(Path path); diff --git a/src/fix-ng/primops.cc b/src/fix-ng/primops.cc index 86b364c30f53..097933115342 100644 --- a/src/fix-ng/primops.cc +++ b/src/fix-ng/primops.cc @@ -13,22 +13,22 @@ Expr primImport(EvalState & state, Expr arg) } -static PathSet nixExprRootsCached(EvalState & state, const Path & nePath) +static PathSet storeExprRootsCached(EvalState & state, const Path & nePath) { DrvPaths::iterator i = state.drvPaths.find(nePath); if (i != state.drvPaths.end()) return i->second; else { - PathSet paths = nixExprRoots(nePath); + PathSet paths = storeExprRoots(nePath); state.drvPaths[nePath] = paths; return paths; } } -static Hash hashDerivation(EvalState & state, NixExpr ne) +static Hash hashDerivation(EvalState & state, StoreExpr ne) { - if (ne.type == NixExpr::neDerivation) { + if (ne.type == StoreExpr::neDerivation) { PathSet inputs2; for (PathSet::iterator i = ne.derivation.inputs.begin(); i != ne.derivation.inputs.end(); i++) @@ -40,7 +40,7 @@ static Hash hashDerivation(EvalState & state, NixExpr ne) } ne.derivation.inputs = inputs2; } - return hashTerm(unparseNixExpr(ne)); + return hashTerm(unparseStoreExpr(ne)); } @@ -50,13 +50,13 @@ static Path copyAtom(EvalState & state, const Path & srcPath) Path dstPath(addToStore(srcPath)); ClosureElem elem; - NixExpr ne; - ne.type = NixExpr::neClosure; + StoreExpr ne; + ne.type = StoreExpr::neClosure; ne.closure.roots.insert(dstPath); ne.closure.elems[dstPath] = elem; Hash drvHash = hashDerivation(state, ne); - Path drvPath = writeTerm(unparseNixExpr(ne), ""); + Path drvPath = writeTerm(unparseStoreExpr(ne), ""); state.drvHashes[drvPath] = drvHash; printMsg(lvlChatty, format("copied `%1%' -> closure `%2%'") @@ -66,9 +66,9 @@ static Path copyAtom(EvalState & state, const Path & srcPath) static string addInput(EvalState & state, - Path & nePath, NixExpr & ne) + Path & nePath, StoreExpr & ne) { - PathSet paths = nixExprRootsCached(state, nePath); + PathSet paths = storeExprRootsCached(state, nePath); if (paths.size() != 1) abort(); Path path = *(paths.begin()); ne.derivation.inputs.insert(nePath); @@ -76,7 +76,7 @@ static string addInput(EvalState & state, } -static string processBinding(EvalState & state, Expr e, NixExpr & ne) +static string processBinding(EvalState & state, Expr e, StoreExpr & ne) { e = evalExpr(state, e); @@ -131,8 +131,8 @@ Expr primDerivation(EvalState & state, Expr args) queryAllAttrs(args, attrs); /* Build the derivation expression by processing the attributes. */ - NixExpr ne; - ne.type = NixExpr::neDerivation; + StoreExpr ne; + ne.type = StoreExpr::neDerivation; string drvName; Path outPath; @@ -198,7 +198,7 @@ Expr primDerivation(EvalState & state, Expr args) Hash drvHash = outHashGiven ? hashString((string) outHash + outPath) : hashDerivation(state, ne); - Path drvPath = writeTerm(unparseNixExpr(ne), "-d-" + drvName); + Path drvPath = writeTerm(unparseStoreExpr(ne), "-d-" + drvName); state.drvHashes[drvPath] = drvHash; printMsg(lvlChatty, format("instantiated `%1%' -> `%2%'") 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/expr.cc b/src/libstore/expr.cc deleted file mode 100644 index 7bb1f5306129..000000000000 --- a/src/libstore/expr.cc +++ /dev/null @@ -1,210 +0,0 @@ -#include "expr.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)); -} - - -Path writeTerm(ATerm t, const string & suffix) -{ - /* The id of a term is its hash. */ - Hash h = hashTerm(t); - - Path path = canonPath(nixStore + "/" + - (string) h + suffix + ".nix"); - - if (!isValidPath(path)) { - char * s = ATwriteToString(t); - if (!s) throw Error(format("cannot write aterm to `%1%'") % path); - addTextToStore(path, string(s)); - } - - return path; -} - - -static void parsePaths(ATermList paths, PathSet & out) -{ - ATMatcher m; - for (ATermIterator i(paths); i; ++i) { - string s; - if (!(atMatch(m, *i) >> s)) - throw badTerm("not a path", *i); - out.insert(s); - } -} - - -static void checkClosure(const Closure & closure) -{ - if (closure.elems.size() == 0) - throw Error("empty closure"); - - PathSet decl; - for (ClosureElems::const_iterator i = closure.elems.begin(); - i != closure.elems.end(); i++) - decl.insert(i->first); - - for (PathSet::const_iterator i = closure.roots.begin(); - i != closure.roots.end(); i++) - if (decl.find(*i) == decl.end()) - throw Error(format("undefined root path `%1%'") % *i); - - for (ClosureElems::const_iterator i = closure.elems.begin(); - i != closure.elems.end(); i++) - for (PathSet::const_iterator j = i->second.refs.begin(); - j != i->second.refs.end(); j++) - if (decl.find(*j) == decl.end()) - throw Error( - format("undefined path `%1%' referenced by `%2%'") - % *j % i->first); -} - - -/* Parse a closure. */ -static bool parseClosure(ATerm t, Closure & closure) -{ - ATermList roots, elems; - ATMatcher m; - - if (!(atMatch(m, t) >> "Closure" >> roots >> elems)) - return false; - - parsePaths(roots, closure.roots); - - for (ATermIterator i(elems); i; ++i) { - string path; - ATermList refs; - if (!(atMatch(m, *i) >> "" >> path >> refs)) - throw badTerm("not a closure element", *i); - ClosureElem elem; - parsePaths(refs, elem.refs); - closure.elems[path] = elem; - } - - checkClosure(closure); - return true; -} - - -static bool parseDerivation(ATerm t, Derivation & derivation) -{ - ATMatcher m; - ATermList outs, ins, args, bnds; - string builder, platform; - - if (!(atMatch(m, t) >> "Derive" >> outs >> ins >> platform - >> builder >> args >> bnds)) - return false; - - parsePaths(outs, derivation.outputs); - parsePaths(ins, derivation.inputs); - - derivation.builder = builder; - derivation.platform = platform; - - for (ATermIterator i(args); i; ++i) { - string s; - if (!(atMatch(m, *i) >> s)) - throw badTerm("string expected", *i); - derivation.args.push_back(s); - } - - for (ATermIterator i(bnds); i; ++i) { - string s1, s2; - if (!(atMatch(m, *i) >> "" >> s1 >> s2)) - throw badTerm("tuple of strings expected", *i); - derivation.env[s1] = s2; - } - - return true; -} - - -NixExpr parseNixExpr(ATerm t) -{ - NixExpr ne; - if (parseClosure(t, ne.closure)) - ne.type = NixExpr::neClosure; - else if (parseDerivation(t, ne.derivation)) - ne.type = NixExpr::neDerivation; - else throw badTerm("not a Nix expression", t); - return ne; -} - - -static ATermList unparsePaths(const PathSet & paths) -{ - ATermList l = ATempty; - for (PathSet::const_iterator i = paths.begin(); - i != paths.end(); i++) - l = ATinsert(l, ATmake("", i->c_str())); - return ATreverse(l); -} - - -static ATerm unparseClosure(const Closure & closure) -{ - ATermList roots = unparsePaths(closure.roots); - - ATermList elems = ATempty; - for (ClosureElems::const_iterator i = closure.elems.begin(); - i != closure.elems.end(); i++) - elems = ATinsert(elems, - ATmake("(, )", - i->first.c_str(), - unparsePaths(i->second.refs))); - - return ATmake("Closure(, )", roots, elems); -} - - -static ATerm unparseDerivation(const Derivation & derivation) -{ - ATermList args = ATempty; - for (Strings::const_iterator i = derivation.args.begin(); - i != derivation.args.end(); i++) - args = ATinsert(args, ATmake("", i->c_str())); - - ATermList env = ATempty; - for (StringPairs::const_iterator i = derivation.env.begin(); - i != derivation.env.end(); i++) - env = ATinsert(env, - ATmake("(, )", - i->first.c_str(), i->second.c_str())); - - return ATmake("Derive(, , , , , )", - unparsePaths(derivation.outputs), - unparsePaths(derivation.inputs), - derivation.platform.c_str(), - derivation.builder.c_str(), - ATreverse(args), - ATreverse(env)); -} - - -ATerm unparseNixExpr(const NixExpr & ne) -{ - if (ne.type == NixExpr::neClosure) - return unparseClosure(ne.closure); - else if (ne.type == NixExpr::neDerivation) - return unparseDerivation(ne.derivation); - else abort(); -} diff --git a/src/libstore/expr.hh b/src/libstore/expr.hh deleted file mode 100644 index f5abf9af0d3a..000000000000 --- a/src/libstore/expr.hh +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef __FSTATE_H -#define __FSTATE_H - -#include "aterm.hh" -#include "store.hh" - - -/* Abstract syntax of Nix expressions. */ - -struct ClosureElem -{ - PathSet refs; -}; - -typedef map ClosureElems; - -struct Closure -{ - PathSet roots; - ClosureElems elems; -}; - -typedef map StringPairs; - -struct Derivation -{ - PathSet outputs; - PathSet inputs; /* Nix expressions, not actual inputs */ - string platform; - Path builder; - Strings args; - StringPairs env; -}; - -struct NixExpr -{ - enum { neClosure, neDerivation } type; - Closure closure; - Derivation derivation; -}; - - -/* 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 Nix expression. */ -ATerm unparseNixExpr(const NixExpr & ne); - - -#endif /* !__FSTATE_H */ 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/storeexpr.cc b/src/libstore/storeexpr.cc new file mode 100644 index 000000000000..e11cd5bfe55b --- /dev/null +++ b/src/libstore/storeexpr.cc @@ -0,0 +1,197 @@ +#include "storeexpr.hh" +#include "globals.hh" +#include "store.hh" + + +Hash hashTerm(ATerm t) +{ + return hashString(atPrint(t)); +} + + +Path writeTerm(ATerm t, const string & suffix) +{ + /* The id of a term is its hash. */ + Hash h = hashTerm(t); + + Path path = canonPath(nixStore + "/" + + (string) h + suffix + ".nix"); + + if (!isValidPath(path)) { + char * s = ATwriteToString(t); + if (!s) throw Error(format("cannot write aterm to `%1%'") % path); + addTextToStore(path, string(s)); + } + + return path; +} + + +static void parsePaths(ATermList paths, PathSet & out) +{ + ATMatcher m; + for (ATermIterator i(paths); i; ++i) { + string s; + if (!(atMatch(m, *i) >> s)) + throw badTerm("not a path", *i); + out.insert(s); + } +} + + +static void checkClosure(const Closure & closure) +{ + if (closure.elems.size() == 0) + throw Error("empty closure"); + + PathSet decl; + for (ClosureElems::const_iterator i = closure.elems.begin(); + i != closure.elems.end(); i++) + decl.insert(i->first); + + for (PathSet::const_iterator i = closure.roots.begin(); + i != closure.roots.end(); i++) + if (decl.find(*i) == decl.end()) + throw Error(format("undefined root path `%1%'") % *i); + + for (ClosureElems::const_iterator i = closure.elems.begin(); + i != closure.elems.end(); i++) + for (PathSet::const_iterator j = i->second.refs.begin(); + j != i->second.refs.end(); j++) + if (decl.find(*j) == decl.end()) + throw Error( + format("undefined path `%1%' referenced by `%2%'") + % *j % i->first); +} + + +/* Parse a closure. */ +static bool parseClosure(ATerm t, Closure & closure) +{ + ATermList roots, elems; + ATMatcher m; + + if (!(atMatch(m, t) >> "Closure" >> roots >> elems)) + return false; + + parsePaths(roots, closure.roots); + + for (ATermIterator i(elems); i; ++i) { + string path; + ATermList refs; + if (!(atMatch(m, *i) >> "" >> path >> refs)) + throw badTerm("not a closure element", *i); + ClosureElem elem; + parsePaths(refs, elem.refs); + closure.elems[path] = elem; + } + + checkClosure(closure); + return true; +} + + +static bool parseDerivation(ATerm t, Derivation & derivation) +{ + ATMatcher m; + ATermList outs, ins, args, bnds; + string builder, platform; + + if (!(atMatch(m, t) >> "Derive" >> outs >> ins >> platform + >> builder >> args >> bnds)) + return false; + + parsePaths(outs, derivation.outputs); + parsePaths(ins, derivation.inputs); + + derivation.builder = builder; + derivation.platform = platform; + + for (ATermIterator i(args); i; ++i) { + string s; + if (!(atMatch(m, *i) >> s)) + throw badTerm("string expected", *i); + derivation.args.push_back(s); + } + + for (ATermIterator i(bnds); i; ++i) { + string s1, s2; + if (!(atMatch(m, *i) >> "" >> s1 >> s2)) + throw badTerm("tuple of strings expected", *i); + derivation.env[s1] = s2; + } + + return true; +} + + +StoreExpr parseStoreExpr(ATerm t) +{ + StoreExpr ne; + if (parseClosure(t, ne.closure)) + ne.type = StoreExpr::neClosure; + else if (parseDerivation(t, ne.derivation)) + ne.type = StoreExpr::neDerivation; + else throw badTerm("not a store expression", t); + return ne; +} + + +static ATermList unparsePaths(const PathSet & paths) +{ + ATermList l = ATempty; + for (PathSet::const_iterator i = paths.begin(); + i != paths.end(); i++) + l = ATinsert(l, ATmake("", i->c_str())); + return ATreverse(l); +} + + +static ATerm unparseClosure(const Closure & closure) +{ + ATermList roots = unparsePaths(closure.roots); + + ATermList elems = ATempty; + for (ClosureElems::const_iterator i = closure.elems.begin(); + i != closure.elems.end(); i++) + elems = ATinsert(elems, + ATmake("(, )", + i->first.c_str(), + unparsePaths(i->second.refs))); + + return ATmake("Closure(, )", roots, elems); +} + + +static ATerm unparseDerivation(const Derivation & derivation) +{ + ATermList args = ATempty; + for (Strings::const_iterator i = derivation.args.begin(); + i != derivation.args.end(); i++) + args = ATinsert(args, ATmake("", i->c_str())); + + ATermList env = ATempty; + for (StringPairs::const_iterator i = derivation.env.begin(); + i != derivation.env.end(); i++) + env = ATinsert(env, + ATmake("(, )", + i->first.c_str(), i->second.c_str())); + + return ATmake("Derive(, , , , , )", + unparsePaths(derivation.outputs), + unparsePaths(derivation.inputs), + derivation.platform.c_str(), + derivation.builder.c_str(), + ATreverse(args), + ATreverse(env)); +} + + +ATerm unparseStoreExpr(const StoreExpr & ne) +{ + if (ne.type == StoreExpr::neClosure) + return unparseClosure(ne.closure); + else if (ne.type == StoreExpr::neDerivation) + return unparseDerivation(ne.derivation); + else abort(); +} diff --git a/src/libstore/storeexpr.hh b/src/libstore/storeexpr.hh new file mode 100644 index 000000000000..07676c3ccedb --- /dev/null +++ b/src/libstore/storeexpr.hh @@ -0,0 +1,56 @@ +#ifndef __STOREEXPR_H +#define __STOREEXPR_H + +#include "aterm.hh" +#include "store.hh" + + +/* Abstract syntax of store expressions. */ + +struct ClosureElem +{ + PathSet refs; +}; + +typedef map ClosureElems; + +struct Closure +{ + PathSet roots; + ClosureElems elems; +}; + +typedef map StringPairs; + +struct Derivation +{ + PathSet outputs; + PathSet inputs; /* Store expressions, not actual inputs */ + string platform; + Path builder; + Strings args; + StringPairs env; +}; + +struct StoreExpr +{ + enum { neClosure, neDerivation } type; + Closure closure; + Derivation derivation; +}; + + +/* 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 store expression. */ +StoreExpr parseStoreExpr(ATerm t); + +/* Parse a store expression. */ +ATerm unparseStoreExpr(const StoreExpr & ne); + + +#endif /* !__STOREEXPR_H */ diff --git a/src/libutil/aterm.cc b/src/libutil/aterm.cc index de7c359521a7..dc6abf9e70e8 100644 --- a/src/libutil/aterm.cc +++ b/src/libutil/aterm.cc @@ -91,3 +91,16 @@ ATMatcher & operator >> (ATMatcher & pos, ATermList & out) out = (ATermList) t; return pos; } + + +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); +} diff --git a/src/libutil/aterm.hh b/src/libutil/aterm.hh index 16d8d6bb6dfd..d38d8e3f4d7a 100644 --- a/src/libutil/aterm.hh +++ b/src/libutil/aterm.hh @@ -74,4 +74,9 @@ ATMatcher & operator >> (ATMatcher & pos, const string & s); ATMatcher & operator >> (ATMatcher & pos, ATermList & out); +/* Throw an exception with an error message containing the given + aterm. */ +Error badTerm(const format & f, ATerm t); + + #endif /* !__ATERM_H */ diff --git a/src/nix/dotgraph.cc b/src/nix/dotgraph.cc index 36daf7f9966d..c670bf19e4c5 100644 --- a/src/nix/dotgraph.cc +++ b/src/nix/dotgraph.cc @@ -52,7 +52,7 @@ string pathLabel(const Path & nePath, const string & elemPath) } -void printClosure(const Path & nePath, const NixExpr & fs) +void printClosure(const Path & nePath, const StoreExpr & fs) { PathSet workList(fs.closure.roots); PathSet doneSet; @@ -100,11 +100,11 @@ void printDotGraph(const PathSet & roots) if (doneSet.find(nePath) == doneSet.end()) { doneSet.insert(nePath); - NixExpr ne = exprFromPath(nePath); + StoreExpr ne = storeExprFromPath(nePath); string label, colour; - if (ne.type == NixExpr::neDerivation) { + if (ne.type == StoreExpr::neDerivation) { for (PathSet::iterator i = ne.derivation.inputs.begin(); i != ne.derivation.inputs.end(); i++) { @@ -119,7 +119,7 @@ void printDotGraph(const PathSet & roots) if (i->first == "name") label = i->second; } - else if (ne.type == NixExpr::neClosure) { + else if (ne.type == StoreExpr::neClosure) { label = ""; colour = "#00ffff"; printClosure(nePath, ne); diff --git a/src/nix/dotgraph.hh b/src/nix/dotgraph.hh index a5c5248f144e..ef389b30d353 100644 --- a/src/nix/dotgraph.hh +++ b/src/nix/dotgraph.hh @@ -1,7 +1,7 @@ #ifndef __DOTGRAPH_H #define __DOTGRAPH_H -#include "expr.hh" +#include "storeexpr.hh" void printDotGraph(const PathSet & roots); diff --git a/src/nix/nix-help.txt b/src/nix/nix-help.txt index bf2afd061205..a2d9958ffe49 100644 --- a/src/nix/nix-help.txt +++ b/src/nix/nix-help.txt @@ -2,7 +2,7 @@ nix [OPTIONS...] [ARGUMENTS...] Operations: - --install / -i: realise a Nix expression + --realise / -r: realise a Nix expression --delete / -d: delete paths from the Nix store --add / -A: copy a path to the Nix store --query / -q: query information @@ -22,7 +22,7 @@ Operations: Query flags: --list / -l: query the output paths (roots) of a Nix expression (default) - --requisites / -r: print all paths necessary to realise expression + --requisites / -R: print all paths necessary to realise expression --predecessors: print predecessors of a Nix expression --graph: print a dot graph rooted at given ids diff --git a/src/nix/nix.cc b/src/nix/nix.cc index 1875689990a4..d1766de39b7e 100644 --- a/src/nix/nix.cc +++ b/src/nix/nix.cc @@ -27,15 +27,15 @@ static Path checkPath(const Path & arg) } -/* Realise (or install) paths from the given Nix expressions. */ -static void opInstall(Strings opFlags, Strings opArgs) +/* Realise paths from the given store expressions. */ +static void opRealise(Strings opFlags, Strings opArgs) { if (!opFlags.empty()) throw UsageError("unknown flag"); for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); i++) { - Path nfPath = normaliseNixExpr(checkPath(*i)); + Path nfPath = normaliseStoreExpr(checkPath(*i)); realiseClosure(nfPath); cout << format("%1%\n") % (string) nfPath; } @@ -66,7 +66,7 @@ static void opAdd(Strings opFlags, Strings opArgs) Path maybeNormalise(const Path & ne, bool normalise) { - return normalise ? normaliseNixExpr(ne) : ne; + return normalise ? normaliseStoreExpr(ne) : ne; } @@ -82,7 +82,7 @@ static void opQuery(Strings opFlags, Strings opArgs) for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); i++) if (*i == "--list" || *i == "-l") query = qList; - else if (*i == "--requisites" || *i == "-r") query = qRequisites; + else if (*i == "--requisites" || *i == "-R") query = qRequisites; else if (*i == "--predecessors") query = qPredecessors; else if (*i == "--graph") query = qGraph; else if (*i == "--normalise" || *i == "-n") normalise = true; @@ -96,7 +96,7 @@ static void opQuery(Strings opFlags, Strings opArgs) for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); i++) { - StringSet paths = nixExprRoots( + StringSet paths = storeExprRoots( maybeNormalise(checkPath(*i), normalise)); for (StringSet::iterator j = paths.begin(); j != paths.end(); j++) @@ -110,7 +110,7 @@ static void opQuery(Strings opFlags, Strings opArgs) for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); i++) { - StringSet paths2 = nixExprRequisites( + StringSet paths2 = storeExprRequisites( maybeNormalise(checkPath(*i), normalise), includeExprs, includeSuccessors); paths.insert(paths2.begin(), paths2.end()); @@ -258,8 +258,8 @@ void run(Strings args) Operation oldOp = op; - if (arg == "--install" || arg == "-i") - op = opInstall; + if (arg == "--realise" || arg == "-r") + op = opRealise; else if (arg == "--delete" || arg == "-d") op = opDelete; else if (arg == "--add" || arg == "-A") -- cgit 1.4.1