* Let `nix --install' print out the id of the normal form.

* Some minor refactoring.
This commit is contained in:
Eelco Dolstra 2003-07-29 09:45:03 +00:00
parent ce5fd1cc12
commit 5acb45446e
5 changed files with 35 additions and 34 deletions

View file

@ -44,7 +44,11 @@ static void opInstall(Strings opFlags, Strings opArgs)
for (Strings::iterator it = opArgs.begin(); for (Strings::iterator it = opArgs.begin();
it != opArgs.end(); it++) it != opArgs.end(); it++)
realiseSlice(normaliseFState(argToId(*it))); {
FSId id = normaliseFState(argToId(*it));
realiseSlice(id);
cout << format("%1%\n") % (string) id;
}
} }

View file

@ -24,7 +24,7 @@ static FSId storeSuccessor(const FSId & id1, ATerm sc)
typedef set<FSId> FSIdSet; typedef set<FSId> FSIdSet;
Slice normaliseFState(FSId id, FSIdSet pending) FSId normaliseFState(FSId id, FSIdSet pending)
{ {
Nest nest(lvlTalkative, format("normalising fstate %1%") % (string) id); Nest nest(lvlTalkative, format("normalising fstate %1%") % (string) id);
@ -40,7 +40,7 @@ Slice normaliseFState(FSId id, FSIdSet pending)
FState fs = parseFState(termFromId(id)); FState fs = parseFState(termFromId(id));
/* It this is a normal form (i.e., a slice) we are done. */ /* It this is a normal form (i.e., a slice) we are done. */
if (fs.type == FState::fsSlice) return fs.slice; if (fs.type == FState::fsSlice) return id;
/* Otherwise, it's a derivation. */ /* Otherwise, it's a derivation. */
@ -56,11 +56,12 @@ Slice normaliseFState(FSId id, FSIdSet pending)
for (FSIds::iterator i = fs.derive.inputs.begin(); for (FSIds::iterator i = fs.derive.inputs.begin();
i != fs.derive.inputs.end(); i++) { i != fs.derive.inputs.end(); i++) {
Slice slice = normaliseFState(*i, pending); FSId nf = normaliseFState(*i, pending);
realiseSlice(slice, pending); realiseSlice(nf, pending);
FState fs = parseFState(termFromId(nf));
for (SliceElems::iterator j = slice.elems.begin(); if (fs.type != FState::fsSlice) abort();
j != slice.elems.end(); j++) for (SliceElems::iterator j = fs.slice.elems.begin();
j != fs.slice.elems.end(); j++)
inMap[j->path] = *j; inMap[j->path] = *j;
} }
@ -169,21 +170,24 @@ Slice normaliseFState(FSId id, FSIdSet pending)
fs.type = FState::fsSlice; fs.type = FState::fsSlice;
ATerm nf = unparseFState(fs); ATerm nf = unparseFState(fs);
msg(lvlVomit, format("normal form: %1%") % printTerm(nf)); msg(lvlVomit, format("normal form: %1%") % printTerm(nf));
storeSuccessor(id, nf); return storeSuccessor(id, nf);
return fs.slice;
} }
void realiseSlice(const Slice & slice, FSIdSet pending) void realiseSlice(const FSId & id, FSIdSet pending)
{ {
Nest nest(lvlDebug, format("realising slice")); Nest nest(lvlDebug,
format("realising slice %1%") % (string) id);
FState fs = parseFState(termFromId(id));
if (fs.type != FState::fsSlice)
throw Error(format("expected slice in %1%") % (string) id);
/* Perhaps all paths already contain the right id? */ /* Perhaps all paths already contain the right id? */
bool missing = false; bool missing = false;
for (SliceElems::const_iterator i = slice.elems.begin(); for (SliceElems::const_iterator i = fs.slice.elems.begin();
i != slice.elems.end(); i++) i != fs.slice.elems.end(); i++)
{ {
SliceElem elem = *i; SliceElem elem = *i;
string id; string id;
@ -203,8 +207,8 @@ void realiseSlice(const Slice & slice, FSIdSet pending)
} }
/* For each element, expand its id at its path. */ /* For each element, expand its id at its path. */
for (SliceElems::const_iterator i = slice.elems.begin(); for (SliceElems::const_iterator i = fs.slice.elems.begin();
i != slice.elems.end(); i++) i != fs.slice.elems.end(); i++)
{ {
SliceElem elem = *i; SliceElem elem = *i;
debug(format("expanding %1% in `%2%'") % (string) elem.id % elem.path); debug(format("expanding %1% in `%2%'") % (string) elem.id % elem.path);
@ -217,13 +221,8 @@ Strings fstatePaths(const FSId & id, bool normalise)
{ {
Strings paths; Strings paths;
FState fs; FState fs = parseFState(termFromId(
normalise ? normaliseFState(id) : id));
if (normalise) {
fs.slice = normaliseFState(id);
fs.type = FState::fsSlice;
} else
fs = parseFState(termFromId(id));
if (fs.type == FState::fsSlice) { if (fs.type == FState::fsSlice) {
/* !!! fix complexity */ /* !!! fix complexity */
@ -249,9 +248,9 @@ Strings fstatePaths(const FSId & id, bool normalise)
Strings fstateRefs(const FSId & id) Strings fstateRefs(const FSId & id)
{ {
Strings paths; Strings paths;
Slice slice = normaliseFState(id); FState fs = parseFState(termFromId(normaliseFState(id)));
for (SliceElems::const_iterator i = slice.elems.begin(); for (SliceElems::const_iterator i = fs.slice.elems.begin();
i != slice.elems.end(); i++) i != fs.slice.elems.end(); i++)
paths.push_back(i->path); paths.push_back(i->path);
return paths; return paths;
} }

View file

@ -5,11 +5,11 @@
/* Normalise an fstate-expression, that is, return an equivalent /* Normalise an fstate-expression, that is, return an equivalent
Slice. (For the meaning of `pending', see expandId()). */ slice. (For the meaning of `pending', see expandId()). */
Slice normaliseFState(FSId id, FSIdSet pending = FSIdSet()); FSId normaliseFState(FSId id, FSIdSet pending = FSIdSet());
/* Realise a Slice in the file system. */ /* Realise a Slice in the file system. */
void realiseSlice(const Slice & slice, FSIdSet pending = FSIdSet()); void realiseSlice(const FSId & id, FSIdSet pending = FSIdSet());
/* Get the list of root (output) paths of the given /* Get the list of root (output) paths of the given
fstate-expression. */ fstate-expression. */

View file

@ -219,8 +219,7 @@ string expandId(const FSId & id, const string & target,
debug(format("trying substitute %1%") % (string) subId); debug(format("trying substitute %1%") % (string) subId);
Slice slice = normaliseFState(subId, pending); realiseSlice(normaliseFState(subId, pending), pending);
realiseSlice(slice, pending);
return expandId(id, target, prefix, pending); return expandId(id, target, prefix, pending);
} }

View file

@ -13,8 +13,7 @@
void realise(FSId id) void realise(FSId id)
{ {
Nest nest(lvlDebug, format("TEST: realising %1%") % (string) id); Nest nest(lvlDebug, format("TEST: realising %1%") % (string) id);
Slice slice = normaliseFState(id); realiseSlice(normaliseFState(id));
realiseSlice(slice);
} }