* Fix self-referential outputs.

* Fix -qp query.
This commit is contained in:
Eelco Dolstra 2003-07-16 08:30:26 +00:00
parent d41d085b77
commit c11bbcfd26
5 changed files with 28 additions and 30 deletions

View File

@ -164,7 +164,7 @@ static Expr evalExpr(Expr e)
char * id; char * id;
if (ATmatch(value, "FSId(<str>)", &id)) { if (ATmatch(value, "FSId(<str>)", &id)) {
Strings paths = fstatePaths(parseHash(id)); Strings paths = fstatePaths(parseHash(id), false);
if (paths.size() != 1) abort(); if (paths.size() != 1) abort();
string path = *(paths.begin()); string path = *(paths.begin());
ins = ATinsert(ins, ATmake("<str>", id)); ins = ATinsert(ins, ATmake("<str>", id));

View File

@ -332,19 +332,19 @@ Slice normaliseFState(FSId id)
} }
/* Check that none of the output paths exist. */ /* Check that none of the output paths exist. */
typedef pair<string, FSId> OutPath; typedef map<string, FSId> OutPaths;
list<OutPath> outPaths; OutPaths outPaths;
while (!ATisEmpty(outs)) { while (!ATisEmpty(outs)) {
ATerm t = ATgetFirst(outs); ATerm t = ATgetFirst(outs);
char * s1, * s2; char * s1, * s2;
if (!ATmatch(t, "(<str>, <str>)", &s1, &s2)) if (!ATmatch(t, "(<str>, <str>)", &s1, &s2))
throw badTerm("string expected", t); throw badTerm("string expected", t);
outPaths.push_back(OutPath(s1, parseHash(s2))); outPaths[s1] = parseHash(s2);
inPaths.push_back(s1); inPaths.push_back(s1);
outs = ATgetNext(outs); outs = ATgetNext(outs);
} }
for (list<OutPath>::iterator i = outPaths.begin(); for (OutPaths::iterator i = outPaths.begin();
i != outPaths.end(); i++) i != outPaths.end(); i++)
if (pathExists(i->first)) if (pathExists(i->first))
throw Error(format("path `%1%' exists") % i->first); throw Error(format("path `%1%' exists") % i->first);
@ -357,7 +357,7 @@ Slice normaliseFState(FSId id)
/* Check whether the output paths were created, and register each /* Check whether the output paths were created, and register each
one. */ one. */
FSIdSet used; FSIdSet used;
for (list<OutPath>::iterator i = outPaths.begin(); for (OutPaths::iterator i = outPaths.begin();
i != outPaths.end(); i++) i != outPaths.end(); i++)
{ {
string path = i->first; string path = i->first;
@ -374,10 +374,15 @@ Slice normaliseFState(FSId id)
for (Strings::iterator j = refs.begin(); j != refs.end(); j++) { for (Strings::iterator j = refs.begin(); j != refs.end(); j++) {
ElemMap::iterator k; ElemMap::iterator k;
OutPaths::iterator l;
if ((k = inMap.find(*j)) != inMap.end()) { if ((k = inMap.find(*j)) != inMap.end()) {
elem.refs.push_back(k->second.id); elem.refs.push_back(k->second.id);
used.insert(k->second.id); used.insert(k->second.id);
} else abort(); /* fix! check in created paths */ } else if ((l = outPaths.find(*j)) != outPaths.end()) {
elem.refs.push_back(l->second);
used.insert(l->second);
} else
throw Error(format("unknown referenced path `%1%'") % *j);
} }
slice.elems.push_back(elem); slice.elems.push_back(elem);
@ -470,7 +475,7 @@ void realiseSlice(const Slice & slice)
} }
Strings fstatePaths(FSId id) Strings fstatePaths(FSId id, bool normalise)
{ {
Strings paths; Strings paths;
@ -480,10 +485,15 @@ Strings fstatePaths(FSId id)
char * builder; char * builder;
char * platform; char * platform;
if (ATgetType(fs) == AT_APPL && if (normalise ||
(string) ATgetName(ATgetAFun(fs)) == "Slice") (ATgetType(fs) == AT_APPL &&
(string) ATgetName(ATgetAFun(fs)) == "Slice"))
{ {
Slice slice = parseSlice(fs); Slice slice;
if (normalise)
slice = normaliseFState(id);
else
slice = parseSlice(fs);
/* !!! fix complexity */ /* !!! fix complexity */
for (FSIds::const_iterator i = slice.roots.begin(); for (FSIds::const_iterator i = slice.roots.begin();

View File

@ -74,20 +74,6 @@ struct Slice
}; };
#if 0
/* Realise an fstate expression in the file system. This requires
execution of all Derive() nodes. */
FState realiseFState(FState fs, StringSet & paths);
/* Return the path of an fstate expression. An empty string is
returned if the term is not a valid fstate expression. (!!!) */
string fstatePath(FState fs);
/* Return the paths referenced by fstate expression. */
void fstateRefs(FState fs, StringSet & paths);
#endif
/* Return a canonical textual representation of an expression. */ /* Return a canonical textual representation of an expression. */
string printTerm(ATerm t); string printTerm(ATerm t);
@ -115,7 +101,7 @@ Slice normaliseFState(FSId id);
/* Realise a Slice in the file system. */ /* Realise a Slice in the file system. */
void realiseSlice(const Slice & slice); void realiseSlice(const Slice & slice);
Strings fstatePaths(FSId id); Strings fstatePaths(FSId id, bool normalise);
#endif /* !__FSTATE_H */ #endif /* !__FSTATE_H */

View File

@ -157,14 +157,15 @@ static void opQuery(Strings opFlags, Strings opArgs)
switch (query) { switch (query) {
#if 0
case qPath: { case qPath: {
StringSet refs; Strings paths = fstatePaths(id, true);
cout << format("%s\n") % for (Strings::iterator i = paths.begin();
(string) fstatePath(realiseFState(termFromHash(hash), refs)); i != paths.end(); i++)
cout << format("%s\n") % *i;
break; break;
} }
#if 0
case qRefs: { case qRefs: {
StringSet refs; StringSet refs;
FState fs = hash2fstate(hash); FState fs = hash2fstate(hash);

View File

@ -6,3 +6,4 @@ mkdir $out || exit 1
cd $out || exit 1 cd $out || exit 1
echo "Hallo Wereld" > bla echo "Hallo Wereld" > bla
echo $builder >> bla echo $builder >> bla
echo $out >> bla