mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-23 06:26:15 +02:00
* "Nix expression" -> "store expression".
* More refactoring.
This commit is contained in:
parent
9f0f020929
commit
ce92d1bf14
20 changed files with 121 additions and 119 deletions
|
@ -1,6 +1,6 @@
|
||||||
bin_PROGRAMS = fix-ng
|
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 \
|
fix_ng_LDADD = ../libmain/libmain.a ../libstore/libstore.a ../libutil/libutil.a \
|
||||||
../boost/format/libformat.a -L../../externals/inst/lib -ldb_cxx \
|
../boost/format/libformat.a -L../../externals/inst/lib -ldb_cxx \
|
||||||
-lsglr -lATB -lconversion -lasfix2 -lmept -lATerm
|
-lsglr -lATB -lconversion -lasfix2 -lmept -lATerm
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "eval.hh"
|
#include "eval.hh"
|
||||||
#include "expr.hh"
|
|
||||||
#include "parser.hh"
|
#include "parser.hh"
|
||||||
#include "primops.hh"
|
#include "primops.hh"
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "fix-expr.hh"
|
#include "aterm.hh"
|
||||||
#include "expr.hh"
|
#include "hash.hh"
|
||||||
|
#include "fixexpr.hh"
|
||||||
|
|
||||||
|
|
||||||
typedef map<Path, PathSet> DrvPaths;
|
typedef map<Path, PathSet> DrvPaths;
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
#include "normalise.hh"
|
#include "normalise.hh"
|
||||||
#include "shared.hh"
|
#include "shared.hh"
|
||||||
#include "expr.hh"
|
|
||||||
#include "eval.hh"
|
#include "eval.hh"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "fix-expr.hh"
|
#include "fixexpr.hh"
|
||||||
#include "expr.hh"
|
#include "storeexpr.hh"
|
||||||
|
|
||||||
|
|
||||||
ATermMap::ATermMap(unsigned int initialSize, unsigned int maxLoadPct)
|
ATermMap::ATermMap(unsigned int initialSize, unsigned int maxLoadPct)
|
|
@ -10,10 +10,10 @@ extern "C" {
|
||||||
#include <asfix2.h>
|
#include <asfix2.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "aterm.hh"
|
||||||
#include "parser.hh"
|
#include "parser.hh"
|
||||||
#include "shared.hh"
|
#include "shared.hh"
|
||||||
#include "fix-expr.hh"
|
#include "fixexpr.hh"
|
||||||
#include "expr.hh"
|
|
||||||
#include "parse-table.h"
|
#include "parse-table.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef __PARSER_H
|
#ifndef __PARSER_H
|
||||||
#define __PARSER_H
|
#define __PARSER_H
|
||||||
|
|
||||||
#include "fix-expr.hh"
|
#include "fixexpr.hh"
|
||||||
|
|
||||||
|
|
||||||
Expr parseExprFromFile(Path path);
|
Expr parseExprFromFile(Path path);
|
||||||
|
|
|
@ -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);
|
DrvPaths::iterator i = state.drvPaths.find(nePath);
|
||||||
if (i != state.drvPaths.end())
|
if (i != state.drvPaths.end())
|
||||||
return i->second;
|
return i->second;
|
||||||
else {
|
else {
|
||||||
PathSet paths = nixExprRoots(nePath);
|
PathSet paths = storeExprRoots(nePath);
|
||||||
state.drvPaths[nePath] = paths;
|
state.drvPaths[nePath] = paths;
|
||||||
return 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;
|
PathSet inputs2;
|
||||||
for (PathSet::iterator i = ne.derivation.inputs.begin();
|
for (PathSet::iterator i = ne.derivation.inputs.begin();
|
||||||
i != ne.derivation.inputs.end(); i++)
|
i != ne.derivation.inputs.end(); i++)
|
||||||
|
@ -40,7 +40,7 @@ static Hash hashDerivation(EvalState & state, NixExpr ne)
|
||||||
}
|
}
|
||||||
ne.derivation.inputs = inputs2;
|
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));
|
Path dstPath(addToStore(srcPath));
|
||||||
|
|
||||||
ClosureElem elem;
|
ClosureElem elem;
|
||||||
NixExpr ne;
|
StoreExpr ne;
|
||||||
ne.type = NixExpr::neClosure;
|
ne.type = StoreExpr::neClosure;
|
||||||
ne.closure.roots.insert(dstPath);
|
ne.closure.roots.insert(dstPath);
|
||||||
ne.closure.elems[dstPath] = elem;
|
ne.closure.elems[dstPath] = elem;
|
||||||
|
|
||||||
Hash drvHash = hashDerivation(state, ne);
|
Hash drvHash = hashDerivation(state, ne);
|
||||||
Path drvPath = writeTerm(unparseNixExpr(ne), "");
|
Path drvPath = writeTerm(unparseStoreExpr(ne), "");
|
||||||
state.drvHashes[drvPath] = drvHash;
|
state.drvHashes[drvPath] = drvHash;
|
||||||
|
|
||||||
printMsg(lvlChatty, format("copied `%1%' -> closure `%2%'")
|
printMsg(lvlChatty, format("copied `%1%' -> closure `%2%'")
|
||||||
|
@ -66,9 +66,9 @@ static Path copyAtom(EvalState & state, const Path & srcPath)
|
||||||
|
|
||||||
|
|
||||||
static string addInput(EvalState & state,
|
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();
|
if (paths.size() != 1) abort();
|
||||||
Path path = *(paths.begin());
|
Path path = *(paths.begin());
|
||||||
ne.derivation.inputs.insert(nePath);
|
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);
|
e = evalExpr(state, e);
|
||||||
|
|
||||||
|
@ -131,8 +131,8 @@ Expr primDerivation(EvalState & state, Expr args)
|
||||||
queryAllAttrs(args, attrs);
|
queryAllAttrs(args, attrs);
|
||||||
|
|
||||||
/* Build the derivation expression by processing the attributes. */
|
/* Build the derivation expression by processing the attributes. */
|
||||||
NixExpr ne;
|
StoreExpr ne;
|
||||||
ne.type = NixExpr::neDerivation;
|
ne.type = StoreExpr::neDerivation;
|
||||||
|
|
||||||
string drvName;
|
string drvName;
|
||||||
Path outPath;
|
Path outPath;
|
||||||
|
@ -198,7 +198,7 @@ Expr primDerivation(EvalState & state, Expr args)
|
||||||
Hash drvHash = outHashGiven
|
Hash drvHash = outHashGiven
|
||||||
? hashString((string) outHash + outPath)
|
? hashString((string) outHash + outPath)
|
||||||
: hashDerivation(state, ne);
|
: hashDerivation(state, ne);
|
||||||
Path drvPath = writeTerm(unparseNixExpr(ne), "-d-" + drvName);
|
Path drvPath = writeTerm(unparseStoreExpr(ne), "-d-" + drvName);
|
||||||
state.drvHashes[drvPath] = drvHash;
|
state.drvHashes[drvPath] = drvHash;
|
||||||
|
|
||||||
printMsg(lvlChatty, format("instantiated `%1%' -> `%2%'")
|
printMsg(lvlChatty, format("instantiated `%1%' -> `%2%'")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
noinst_LIBRARIES = libstore.a
|
noinst_LIBRARIES = libstore.a
|
||||||
|
|
||||||
libstore_a_SOURCES = \
|
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
|
globals.cc db.cc references.cc pathlocks.cc
|
||||||
|
|
||||||
AM_CXXFLAGS = -DSYSTEM=\"@host@\" -Wall \
|
AM_CXXFLAGS = -DSYSTEM=\"@host@\" -Wall \
|
||||||
|
|
|
@ -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,
|
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
|
/* Try to substitute the expression by any known successors in
|
||||||
order to speed up the rewrite process. */
|
order to speed up the rewrite process. */
|
||||||
Path nePath = useSuccessor(_nePath);
|
Path nePath = useSuccessor(_nePath);
|
||||||
|
|
||||||
/* Get the Nix expression. */
|
/* Get the store expression. */
|
||||||
NixExpr ne = exprFromPath(nePath, pending);
|
StoreExpr ne = storeExprFromPath(nePath, pending);
|
||||||
|
|
||||||
/* If this is a normal form (i.e., a closure) we are done. */
|
/* If this is a normal form (i.e., a closure) we are done. */
|
||||||
if (ne.type == NixExpr::neClosure) return nePath;
|
if (ne.type == StoreExpr::neClosure) return nePath;
|
||||||
if (ne.type != NixExpr::neDerivation) abort();
|
if (ne.type != StoreExpr::neDerivation) abort();
|
||||||
|
|
||||||
|
|
||||||
/* Otherwise, it's a derivation expression, and we have to build it to
|
/* 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;
|
Environment env;
|
||||||
|
|
||||||
/* The result. */
|
/* The result. */
|
||||||
NixExpr nf;
|
StoreExpr nf;
|
||||||
nf.type = NixExpr::neClosure;
|
nf.type = StoreExpr::neClosure;
|
||||||
|
|
||||||
|
|
||||||
/* The outputs are referenceable paths. */
|
/* The outputs are referenceable paths. */
|
||||||
|
@ -78,10 +78,10 @@ Path normaliseNixExpr(const Path & _nePath, PathSet pending)
|
||||||
{
|
{
|
||||||
Path nePath2 = useSuccessor(nePath);
|
Path nePath2 = useSuccessor(nePath);
|
||||||
if (nePath != nePath2) {
|
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")
|
debug(format("skipping build of expression `%1%', someone beat us to it")
|
||||||
% (string) nePath);
|
% (string) nePath);
|
||||||
if (ne.type != NixExpr::neClosure) abort();
|
if (ne.type != StoreExpr::neClosure) abort();
|
||||||
return nePath2;
|
return nePath2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,12 +95,12 @@ Path normaliseNixExpr(const Path & _nePath, PathSet pending)
|
||||||
for (PathSet::iterator i = ne.derivation.inputs.begin();
|
for (PathSet::iterator i = ne.derivation.inputs.begin();
|
||||||
i != ne.derivation.inputs.end(); i++)
|
i != ne.derivation.inputs.end(); i++)
|
||||||
{
|
{
|
||||||
Path nfPath = normaliseNixExpr(*i, pending);
|
Path nfPath = normaliseStoreExpr(*i, pending);
|
||||||
realiseClosure(nfPath, pending);
|
realiseClosure(nfPath, pending);
|
||||||
/* !!! nfPath should be a root of the garbage collector while
|
/* !!! nfPath should be a root of the garbage collector while
|
||||||
we are building */
|
we are building */
|
||||||
NixExpr ne = exprFromPath(nfPath, pending);
|
StoreExpr ne = storeExprFromPath(nfPath, pending);
|
||||||
if (ne.type != NixExpr::neClosure) abort();
|
if (ne.type != StoreExpr::neClosure) abort();
|
||||||
for (ClosureElems::iterator j = ne.closure.elems.begin();
|
for (ClosureElems::iterator j = ne.closure.elems.begin();
|
||||||
j != ne.closure.elems.end(); j++)
|
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
|
/* Write the normal form. This does not have to occur in the
|
||||||
transaction below because writing terms is idem-potent. */
|
transaction below because writing terms is idem-potent. */
|
||||||
ATerm nfTerm = unparseNixExpr(nf);
|
ATerm nfTerm = unparseStoreExpr(nf);
|
||||||
printMsg(lvlVomit, format("normal form: %1%") % atPrint(nfTerm));
|
printMsg(lvlVomit, format("normal form: %1%") % atPrint(nfTerm));
|
||||||
Path nfPath = writeTerm(nfTerm, "-s");
|
Path nfPath = writeTerm(nfTerm, "-s");
|
||||||
|
|
||||||
|
@ -264,8 +264,8 @@ void realiseClosure(const Path & nePath, PathSet pending)
|
||||||
{
|
{
|
||||||
startNest(nest, lvlDebug, format("realising closure `%1%'") % nePath);
|
startNest(nest, lvlDebug, format("realising closure `%1%'") % nePath);
|
||||||
|
|
||||||
NixExpr ne = exprFromPath(nePath, pending);
|
StoreExpr ne = storeExprFromPath(nePath, pending);
|
||||||
if (ne.type != NixExpr::neClosure)
|
if (ne.type != StoreExpr::neClosure)
|
||||||
throw Error(format("expected closure in `%1%'") % nePath);
|
throw Error(format("expected closure in `%1%'") % nePath);
|
||||||
|
|
||||||
for (ClosureElems::const_iterator i = ne.closure.elems.begin();
|
for (ClosureElems::const_iterator i = ne.closure.elems.begin();
|
||||||
|
@ -286,7 +286,7 @@ void ensurePath(const Path & path, PathSet pending)
|
||||||
i != subPaths.end(); i++)
|
i != subPaths.end(); i++)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
normaliseNixExpr(*i, pending);
|
normaliseStoreExpr(*i, pending);
|
||||||
if (isValidPath(path)) return;
|
if (isValidPath(path)) return;
|
||||||
throw Error(format("substitute failed to produce expected output path"));
|
throw Error(format("substitute failed to produce expected output path"));
|
||||||
} catch (Error & e) {
|
} 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);
|
ensurePath(path, pending);
|
||||||
ATerm t = ATreadFromNamedFile(path.c_str());
|
ATerm t = ATreadFromNamedFile(path.c_str());
|
||||||
if (!t) throw Error(format("cannot read aterm from `%1%'") % path);
|
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;
|
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());
|
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(),
|
paths.insert(ne.derivation.outputs.begin(),
|
||||||
ne.derivation.outputs.end());
|
ne.derivation.outputs.end());
|
||||||
else abort();
|
else abort();
|
||||||
|
@ -334,14 +334,14 @@ static void requisitesWorker(const Path & nePath,
|
||||||
if (doneSet.find(nePath) != doneSet.end()) return;
|
if (doneSet.find(nePath) != doneSet.end()) return;
|
||||||
doneSet.insert(nePath);
|
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();
|
for (ClosureElems::iterator i = ne.closure.elems.begin();
|
||||||
i != ne.closure.elems.end(); i++)
|
i != ne.closure.elems.end(); i++)
|
||||||
paths.insert(i->first);
|
paths.insert(i->first);
|
||||||
|
|
||||||
else if (ne.type == NixExpr::neDerivation)
|
else if (ne.type == StoreExpr::neDerivation)
|
||||||
for (PathSet::iterator i = ne.derivation.inputs.begin();
|
for (PathSet::iterator i = ne.derivation.inputs.begin();
|
||||||
i != ne.derivation.inputs.end(); i++)
|
i != ne.derivation.inputs.end(); i++)
|
||||||
requisitesWorker(*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)
|
bool includeExprs, bool includeSuccessors)
|
||||||
{
|
{
|
||||||
PathSet paths;
|
PathSet paths;
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
#ifndef __NORMALISE_H
|
#ifndef __NORMALISE_H
|
||||||
#define __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
|
derivation, a path containing an equivalent closure expression is
|
||||||
returned. This requires that the derivation is performed, unless a
|
returned. This requires that the derivation is performed, unless a
|
||||||
successor is known. */
|
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
|
The pending paths are those that are already being realised. This
|
||||||
prevents infinite recursion for paths realised through a substitute
|
prevents infinite recursion for paths realised through a substitute
|
||||||
|
@ -22,23 +22,25 @@ void realiseClosure(const Path & nePath, PathSet pending = PathSet());
|
||||||
realising a substitute. */
|
realising a substitute. */
|
||||||
void ensurePath(const Path & path, PathSet pending = PathSet());
|
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(). */
|
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. */
|
/* Get the list of root (output) paths of the given store
|
||||||
PathSet nixExprRoots(const Path & nePath);
|
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
|
expression. For a derive expression, this is the union of
|
||||||
requisites of the inputs; for a closure expression, it is the path of
|
requisites of the inputs; for a closure expression, it is the path
|
||||||
each element in the closure. If `includeExprs' is true, include the
|
of each element in the closure. If `includeExprs' is true, include
|
||||||
paths of the Nix expressions themselves. If `includeSuccessors' is
|
the paths of the store expressions themselves. If
|
||||||
true, include the requisites of successors. */
|
`includeSuccessors' is true, include the requisites of
|
||||||
PathSet nixExprRequisites(const Path & nePath,
|
successors. */
|
||||||
|
PathSet storeExprRequisites(const Path & nePath,
|
||||||
bool includeExprs, bool includeSuccessors);
|
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'. */
|
output paths are completely contained in the set `outputs'. */
|
||||||
PathSet findGenerators(const PathSet & outputs);
|
PathSet findGenerators(const PathSet & outputs);
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,8 @@
|
||||||
#include "expr.hh"
|
#include "storeexpr.hh"
|
||||||
#include "globals.hh"
|
#include "globals.hh"
|
||||||
#include "store.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)
|
Hash hashTerm(ATerm t)
|
||||||
{
|
{
|
||||||
return hashString(atPrint(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))
|
if (parseClosure(t, ne.closure))
|
||||||
ne.type = NixExpr::neClosure;
|
ne.type = StoreExpr::neClosure;
|
||||||
else if (parseDerivation(t, ne.derivation))
|
else if (parseDerivation(t, ne.derivation))
|
||||||
ne.type = NixExpr::neDerivation;
|
ne.type = StoreExpr::neDerivation;
|
||||||
else throw badTerm("not a Nix expression", t);
|
else throw badTerm("not a store expression", t);
|
||||||
return ne;
|
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);
|
return unparseClosure(ne.closure);
|
||||||
else if (ne.type == NixExpr::neDerivation)
|
else if (ne.type == StoreExpr::neDerivation)
|
||||||
return unparseDerivation(ne.derivation);
|
return unparseDerivation(ne.derivation);
|
||||||
else abort();
|
else abort();
|
||||||
}
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
#ifndef __FSTATE_H
|
#ifndef __STOREEXPR_H
|
||||||
#define __FSTATE_H
|
#define __STOREEXPR_H
|
||||||
|
|
||||||
#include "aterm.hh"
|
#include "aterm.hh"
|
||||||
#include "store.hh"
|
#include "store.hh"
|
||||||
|
|
||||||
|
|
||||||
/* Abstract syntax of Nix expressions. */
|
/* Abstract syntax of store expressions. */
|
||||||
|
|
||||||
struct ClosureElem
|
struct ClosureElem
|
||||||
{
|
{
|
||||||
|
@ -25,14 +25,14 @@ typedef map<string, string> StringPairs;
|
||||||
struct Derivation
|
struct Derivation
|
||||||
{
|
{
|
||||||
PathSet outputs;
|
PathSet outputs;
|
||||||
PathSet inputs; /* Nix expressions, not actual inputs */
|
PathSet inputs; /* Store expressions, not actual inputs */
|
||||||
string platform;
|
string platform;
|
||||||
Path builder;
|
Path builder;
|
||||||
Strings args;
|
Strings args;
|
||||||
StringPairs env;
|
StringPairs env;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NixExpr
|
struct StoreExpr
|
||||||
{
|
{
|
||||||
enum { neClosure, neDerivation } type;
|
enum { neClosure, neDerivation } type;
|
||||||
Closure closure;
|
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 an aterm. */
|
||||||
Hash hashTerm(ATerm t);
|
Hash hashTerm(ATerm t);
|
||||||
|
|
||||||
/* Write an aterm to the Nix store directory, and return its path. */
|
/* Write an aterm to the Nix store directory, and return its path. */
|
||||||
Path writeTerm(ATerm t, const string & suffix);
|
Path writeTerm(ATerm t, const string & suffix);
|
||||||
|
|
||||||
/* Parse a Nix expression. */
|
/* Parse a store expression. */
|
||||||
NixExpr parseNixExpr(ATerm t);
|
StoreExpr parseStoreExpr(ATerm t);
|
||||||
|
|
||||||
/* Parse a Nix expression. */
|
/* Parse a store expression. */
|
||||||
ATerm unparseNixExpr(const NixExpr & ne);
|
ATerm unparseStoreExpr(const StoreExpr & ne);
|
||||||
|
|
||||||
|
|
||||||
#endif /* !__FSTATE_H */
|
#endif /* !__STOREEXPR_H */
|
|
@ -91,3 +91,16 @@ ATMatcher & operator >> (ATMatcher & pos, ATermList & out)
|
||||||
out = (ATermList) t;
|
out = (ATermList) t;
|
||||||
return pos;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -74,4 +74,9 @@ ATMatcher & operator >> (ATMatcher & pos, const string & s);
|
||||||
ATMatcher & operator >> (ATMatcher & pos, ATermList & out);
|
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 */
|
#endif /* !__ATERM_H */
|
||||||
|
|
|
@ -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 workList(fs.closure.roots);
|
||||||
PathSet doneSet;
|
PathSet doneSet;
|
||||||
|
@ -100,11 +100,11 @@ void printDotGraph(const PathSet & roots)
|
||||||
if (doneSet.find(nePath) == doneSet.end()) {
|
if (doneSet.find(nePath) == doneSet.end()) {
|
||||||
doneSet.insert(nePath);
|
doneSet.insert(nePath);
|
||||||
|
|
||||||
NixExpr ne = exprFromPath(nePath);
|
StoreExpr ne = storeExprFromPath(nePath);
|
||||||
|
|
||||||
string label, colour;
|
string label, colour;
|
||||||
|
|
||||||
if (ne.type == NixExpr::neDerivation) {
|
if (ne.type == StoreExpr::neDerivation) {
|
||||||
for (PathSet::iterator i = ne.derivation.inputs.begin();
|
for (PathSet::iterator i = ne.derivation.inputs.begin();
|
||||||
i != ne.derivation.inputs.end(); i++)
|
i != ne.derivation.inputs.end(); i++)
|
||||||
{
|
{
|
||||||
|
@ -119,7 +119,7 @@ void printDotGraph(const PathSet & roots)
|
||||||
if (i->first == "name") label = i->second;
|
if (i->first == "name") label = i->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (ne.type == NixExpr::neClosure) {
|
else if (ne.type == StoreExpr::neClosure) {
|
||||||
label = "<closure>";
|
label = "<closure>";
|
||||||
colour = "#00ffff";
|
colour = "#00ffff";
|
||||||
printClosure(nePath, ne);
|
printClosure(nePath, ne);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef __DOTGRAPH_H
|
#ifndef __DOTGRAPH_H
|
||||||
#define __DOTGRAPH_H
|
#define __DOTGRAPH_H
|
||||||
|
|
||||||
#include "expr.hh"
|
#include "storeexpr.hh"
|
||||||
|
|
||||||
void printDotGraph(const PathSet & roots);
|
void printDotGraph(const PathSet & roots);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ nix [OPTIONS...] [ARGUMENTS...]
|
||||||
|
|
||||||
Operations:
|
Operations:
|
||||||
|
|
||||||
--install / -i: realise a Nix expression
|
--realise / -r: realise a Nix expression
|
||||||
--delete / -d: delete paths from the Nix store
|
--delete / -d: delete paths from the Nix store
|
||||||
--add / -A: copy a path to the Nix store
|
--add / -A: copy a path to the Nix store
|
||||||
--query / -q: query information
|
--query / -q: query information
|
||||||
|
@ -22,7 +22,7 @@ Operations:
|
||||||
Query flags:
|
Query flags:
|
||||||
|
|
||||||
--list / -l: query the output paths (roots) of a Nix expression (default)
|
--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
|
--predecessors: print predecessors of a Nix expression
|
||||||
--graph: print a dot graph rooted at given ids
|
--graph: print a dot graph rooted at given ids
|
||||||
|
|
||||||
|
|
|
@ -27,15 +27,15 @@ static Path checkPath(const Path & arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Realise (or install) paths from the given Nix expressions. */
|
/* Realise paths from the given store expressions. */
|
||||||
static void opInstall(Strings opFlags, Strings opArgs)
|
static void opRealise(Strings opFlags, Strings opArgs)
|
||||||
{
|
{
|
||||||
if (!opFlags.empty()) throw UsageError("unknown flag");
|
if (!opFlags.empty()) throw UsageError("unknown flag");
|
||||||
|
|
||||||
for (Strings::iterator i = opArgs.begin();
|
for (Strings::iterator i = opArgs.begin();
|
||||||
i != opArgs.end(); i++)
|
i != opArgs.end(); i++)
|
||||||
{
|
{
|
||||||
Path nfPath = normaliseNixExpr(checkPath(*i));
|
Path nfPath = normaliseStoreExpr(checkPath(*i));
|
||||||
realiseClosure(nfPath);
|
realiseClosure(nfPath);
|
||||||
cout << format("%1%\n") % (string) 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)
|
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();
|
for (Strings::iterator i = opFlags.begin();
|
||||||
i != opFlags.end(); i++)
|
i != opFlags.end(); i++)
|
||||||
if (*i == "--list" || *i == "-l") query = qList;
|
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 == "--predecessors") query = qPredecessors;
|
||||||
else if (*i == "--graph") query = qGraph;
|
else if (*i == "--graph") query = qGraph;
|
||||||
else if (*i == "--normalise" || *i == "-n") normalise = true;
|
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();
|
for (Strings::iterator i = opArgs.begin();
|
||||||
i != opArgs.end(); i++)
|
i != opArgs.end(); i++)
|
||||||
{
|
{
|
||||||
StringSet paths = nixExprRoots(
|
StringSet paths = storeExprRoots(
|
||||||
maybeNormalise(checkPath(*i), normalise));
|
maybeNormalise(checkPath(*i), normalise));
|
||||||
for (StringSet::iterator j = paths.begin();
|
for (StringSet::iterator j = paths.begin();
|
||||||
j != paths.end(); j++)
|
j != paths.end(); j++)
|
||||||
|
@ -110,7 +110,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
for (Strings::iterator i = opArgs.begin();
|
for (Strings::iterator i = opArgs.begin();
|
||||||
i != opArgs.end(); i++)
|
i != opArgs.end(); i++)
|
||||||
{
|
{
|
||||||
StringSet paths2 = nixExprRequisites(
|
StringSet paths2 = storeExprRequisites(
|
||||||
maybeNormalise(checkPath(*i), normalise),
|
maybeNormalise(checkPath(*i), normalise),
|
||||||
includeExprs, includeSuccessors);
|
includeExprs, includeSuccessors);
|
||||||
paths.insert(paths2.begin(), paths2.end());
|
paths.insert(paths2.begin(), paths2.end());
|
||||||
|
@ -258,8 +258,8 @@ void run(Strings args)
|
||||||
|
|
||||||
Operation oldOp = op;
|
Operation oldOp = op;
|
||||||
|
|
||||||
if (arg == "--install" || arg == "-i")
|
if (arg == "--realise" || arg == "-r")
|
||||||
op = opInstall;
|
op = opRealise;
|
||||||
else if (arg == "--delete" || arg == "-d")
|
else if (arg == "--delete" || arg == "-d")
|
||||||
op = opDelete;
|
op = opDelete;
|
||||||
else if (arg == "--add" || arg == "-A")
|
else if (arg == "--add" || arg == "-A")
|
||||||
|
|
Loading…
Reference in a new issue