mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-13 01:36:15 +02:00
* `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:
parent
5acb45446e
commit
79ba0431db
4 changed files with 40 additions and 14 deletions
|
@ -213,7 +213,7 @@ static Expr evalExpr2(EvalState & state, Expr e)
|
||||||
|
|
||||||
if (ATmatch(value, "FSId(<str>)", &s1)) {
|
if (ATmatch(value, "FSId(<str>)", &s1)) {
|
||||||
FSId id = parseHash(s1);
|
FSId id = parseHash(s1);
|
||||||
Strings paths = fstatePaths(id, false);
|
Strings paths = fstatePaths(id);
|
||||||
if (paths.size() != 1) abort();
|
if (paths.size() != 1) abort();
|
||||||
string path = *(paths.begin());
|
string path = *(paths.begin());
|
||||||
fs.derive.inputs.push_back(id);
|
fs.derive.inputs.push_back(id);
|
||||||
|
|
16
src/nix.cc
16
src/nix.cc
|
@ -80,17 +80,24 @@ static void opAdd(Strings opFlags, Strings opArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string dotQuote(const string & s)
|
static string dotQuote(const string & s)
|
||||||
{
|
{
|
||||||
return "\"" + s + "\"";
|
return "\"" + s + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FSId maybeNormalise(const FSId & id, bool normalise)
|
||||||
|
{
|
||||||
|
return normalise ? normaliseFState(id) : id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Perform various sorts of queries. */
|
/* Perform various sorts of queries. */
|
||||||
static void opQuery(Strings opFlags, Strings opArgs)
|
static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
{
|
{
|
||||||
enum { qList, qRefs, qGenerators, qExpansion, qGraph
|
enum { qList, qRefs, qGenerators, qExpansion, qGraph
|
||||||
} query = qList;
|
} query = qList;
|
||||||
|
bool normalise = false;
|
||||||
|
|
||||||
for (Strings::iterator i = opFlags.begin();
|
for (Strings::iterator i = opFlags.begin();
|
||||||
i != opFlags.end(); i++)
|
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 == "--generators" || *i == "-g") query = qGenerators;
|
||||||
else if (*i == "--expansion" || *i == "-e") query = qExpansion;
|
else if (*i == "--expansion" || *i == "-e") query = qExpansion;
|
||||||
else if (*i == "--graph") query = qGraph;
|
else if (*i == "--graph") query = qGraph;
|
||||||
|
else if (*i == "--normalise" || *i == "-n") normalise = true;
|
||||||
else throw UsageError(format("unknown flag `%1%'") % *i);
|
else throw UsageError(format("unknown flag `%1%'") % *i);
|
||||||
|
|
||||||
switch (query) {
|
switch (query) {
|
||||||
|
@ -108,7 +116,8 @@ 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++)
|
||||||
{
|
{
|
||||||
Strings paths2 = fstatePaths(argToId(*i), true);
|
Strings paths2 = fstatePaths(
|
||||||
|
maybeNormalise(argToId(*i), normalise));
|
||||||
paths.insert(paths2.begin(), paths2.end());
|
paths.insert(paths2.begin(), paths2.end());
|
||||||
}
|
}
|
||||||
for (StringSet::iterator i = paths.begin();
|
for (StringSet::iterator i = paths.begin();
|
||||||
|
@ -122,7 +131,8 @@ 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++)
|
||||||
{
|
{
|
||||||
Strings paths2 = fstateRefs(argToId(*i));
|
Strings paths2 = fstateRefs(
|
||||||
|
maybeNormalise(argToId(*i), normalise));
|
||||||
paths.insert(paths2.begin(), paths2.end());
|
paths.insert(paths2.begin(), paths2.end());
|
||||||
}
|
}
|
||||||
for (StringSet::iterator i = paths.begin();
|
for (StringSet::iterator i = paths.begin();
|
||||||
|
|
|
@ -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;
|
Strings paths;
|
||||||
|
|
||||||
FState fs = parseFState(termFromId(
|
FState fs = parseFState(termFromId(id));
|
||||||
normalise ? normaliseFState(id) : id));
|
|
||||||
|
|
||||||
if (fs.type == FState::fsSlice) {
|
if (fs.type == FState::fsSlice) {
|
||||||
/* !!! fix complexity */
|
/* !!! 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 fstateRefs(const FSId & id)
|
||||||
{
|
{
|
||||||
Strings paths;
|
StringSet paths;
|
||||||
FState fs = parseFState(termFromId(normaliseFState(id)));
|
fstateRefsSet(id, paths);
|
||||||
for (SliceElems::const_iterator i = fs.slice.elems.begin();
|
return Strings(paths.begin(), paths.end());
|
||||||
i != fs.slice.elems.end(); i++)
|
|
||||||
paths.push_back(i->path);
|
|
||||||
return paths;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ 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. */
|
||||||
Strings fstatePaths(const FSId & id, bool normalise);
|
Strings fstatePaths(const FSId & id);
|
||||||
|
|
||||||
/* Get the list of paths referenced by the given fstate-expression. */
|
/* Get the list of paths referenced by the given fstate-expression. */
|
||||||
Strings fstateRefs(const FSId & id);
|
Strings fstateRefs(const FSId & id);
|
||||||
|
|
Loading…
Reference in a new issue