* `fstateRefs' now works on derive expressions as well. TODO: make

this more efficient.
* A flag `-n' in 'nix --query' to normalise the argument.  Default is
  not to normalise.
This commit is contained in:
Eelco Dolstra 2003-07-29 10:43:12 +00:00
parent 5acb45446e
commit 79ba0431db
4 changed files with 40 additions and 14 deletions

View File

@ -213,7 +213,7 @@ static Expr evalExpr2(EvalState & state, Expr e)
if (ATmatch(value, "FSId(<str>)", &s1)) {
FSId id = parseHash(s1);
Strings paths = fstatePaths(id, false);
Strings paths = fstatePaths(id);
if (paths.size() != 1) abort();
string path = *(paths.begin());
fs.derive.inputs.push_back(id);

View File

@ -80,17 +80,24 @@ static void opAdd(Strings opFlags, Strings opArgs)
}
string dotQuote(const string & s)
static string dotQuote(const string & s)
{
return "\"" + s + "\"";
}
FSId maybeNormalise(const FSId & id, bool normalise)
{
return normalise ? normaliseFState(id) : id;
}
/* Perform various sorts of queries. */
static void opQuery(Strings opFlags, Strings opArgs)
{
enum { qList, qRefs, qGenerators, qExpansion, qGraph
} query = qList;
bool normalise = false;
for (Strings::iterator i = opFlags.begin();
i != opFlags.end(); i++)
@ -99,6 +106,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
else if (*i == "--generators" || *i == "-g") query = qGenerators;
else if (*i == "--expansion" || *i == "-e") query = qExpansion;
else if (*i == "--graph") query = qGraph;
else if (*i == "--normalise" || *i == "-n") normalise = true;
else throw UsageError(format("unknown flag `%1%'") % *i);
switch (query) {
@ -108,7 +116,8 @@ static void opQuery(Strings opFlags, Strings opArgs)
for (Strings::iterator i = opArgs.begin();
i != opArgs.end(); i++)
{
Strings paths2 = fstatePaths(argToId(*i), true);
Strings paths2 = fstatePaths(
maybeNormalise(argToId(*i), normalise));
paths.insert(paths2.begin(), paths2.end());
}
for (StringSet::iterator i = paths.begin();
@ -122,7 +131,8 @@ static void opQuery(Strings opFlags, Strings opArgs)
for (Strings::iterator i = opArgs.begin();
i != opArgs.end(); i++)
{
Strings paths2 = fstateRefs(argToId(*i));
Strings paths2 = fstateRefs(
maybeNormalise(argToId(*i), normalise));
paths.insert(paths2.begin(), paths2.end());
}
for (StringSet::iterator i = paths.begin();

View File

@ -217,12 +217,11 @@ void realiseSlice(const FSId & id, FSIdSet pending)
}
Strings fstatePaths(const FSId & id, bool normalise)
Strings fstatePaths(const FSId & id)
{
Strings paths;
FState fs = parseFState(termFromId(
normalise ? normaliseFState(id) : id));
FState fs = parseFState(termFromId(id));
if (fs.type == FState::fsSlice) {
/* !!! fix complexity */
@ -245,14 +244,31 @@ Strings fstatePaths(const FSId & id, bool normalise)
}
static void fstateRefsSet(const FSId & id, StringSet & paths)
{
FState fs = parseFState(termFromId(id));
if (fs.type == FState::fsSlice) {
for (SliceElems::iterator i = fs.slice.elems.begin();
i != fs.slice.elems.end(); i++)
paths.insert(i->path);
}
else if (fs.type == FState::fsDerive) {
for (FSIds::iterator i = fs.derive.inputs.begin();
i != fs.derive.inputs.end(); i++)
fstateRefsSet(*i, paths);
}
else abort();
}
Strings fstateRefs(const FSId & id)
{
Strings paths;
FState fs = parseFState(termFromId(normaliseFState(id)));
for (SliceElems::const_iterator i = fs.slice.elems.begin();
i != fs.slice.elems.end(); i++)
paths.push_back(i->path);
return paths;
StringSet paths;
fstateRefsSet(id, paths);
return Strings(paths.begin(), paths.end());
}

View File

@ -13,7 +13,7 @@ void realiseSlice(const FSId & id, FSIdSet pending = FSIdSet());
/* Get the list of root (output) paths of the given
fstate-expression. */
Strings fstatePaths(const FSId & id, bool normalise);
Strings fstatePaths(const FSId & id);
/* Get the list of paths referenced by the given fstate-expression. */
Strings fstateRefs(const FSId & id);