* `nix-env -q' now accepts arguments that allow specific derivations

to be queried, e.g., `nix-env -qa firefox'.  This does require the
  argument '*' to be passed if one wants information about all
  derivations, so the old `nix-env -qa' now is `nix-env -qa "*"'.
This commit is contained in:
Eelco Dolstra 2006-03-10 10:24:46 +00:00
parent 9811815429
commit 4ada6db1fc
2 changed files with 49 additions and 45 deletions

View file

@ -217,19 +217,21 @@ static DrvInfos filterBySelector(EvalState & state,
DrvNames selectors = drvNamesFromArgs(args);
DrvInfos elems;
PathSet done;
set<unsigned int> done;
for (DrvNames::iterator i = selectors.begin();
i != selectors.end(); ++i)
{
DrvInfos matches;
typedef list<pair<DrvInfo, unsigned int> > Matches;
Matches matches;
unsigned int n = 0;
for (DrvInfos::const_iterator j = allElems.begin();
j != allElems.end(); ++j)
j != allElems.end(); ++j, ++n)
{
DrvName drvName(j->name);
if (i->matches(drvName)) {
i->hits++;
matches.push_back(*j);
matches.push_back(pair<DrvInfo, unsigned int>(*j, n));
}
}
@ -240,40 +242,37 @@ static DrvInfos filterBySelector(EvalState & state,
if (newestOnly) {
/* Map from package names to derivations. */
map<string, DrvInfo> newest;
typedef map<string, pair<DrvInfo, unsigned int> > Newest;
Newest newest;
StringSet multiple;
for (DrvInfos::const_iterator j = matches.begin();
j != matches.end(); ++j)
{
DrvName drvName(j->name);
map<string, DrvInfo>::iterator k = newest.find(drvName.name);
for (Matches::iterator j = matches.begin(); j != matches.end(); ++j) {
DrvName drvName(j->first.name);
Newest::iterator k = newest.find(drvName.name);
if (k != newest.end()) {
int d = compareVersions(drvName.version, DrvName(k->second.name).version);
int d = compareVersions(drvName.version, DrvName(k->second.first.name).version);
if (d > 0) newest[drvName.name] = *j;
else if (d == 0) multiple.insert(j->name);
else if (d == 0) multiple.insert(j->first.name);
} else
newest[drvName.name] = *j;
}
matches.clear();
for (map<string, DrvInfo>::iterator j = newest.begin();
j != newest.end(); ++j) {
if (multiple.find(j->second.name) != multiple.end())
for (Newest::iterator j = newest.begin(); j != newest.end(); ++j) {
if (multiple.find(j->second.first.name) != multiple.end())
printMsg(lvlInfo,
format("warning: there are multiple derivations named `%1%'; using the first one")
% j->second.name);
% j->second.first.name);
matches.push_back(j->second);
}
}
/* Insert only those elements in the final list that we
haven't inserted before. */
for (DrvInfos::const_iterator j = matches.begin();
j != matches.end(); ++j)
if (done.find(j->queryOutPath(state)) == done.end()) {
done.insert(j->queryOutPath(state));
elems.push_back(*j);
for (Matches::iterator j = matches.begin(); j != matches.end(); ++j)
if (done.find(j->second) == done.end()) {
done.insert(j->second);
elems.push_back(j->first);
}
}
@ -718,7 +717,9 @@ static void opQuery(Globals & globals,
else if (*i == "--available" || *i == "-a") source = sAvailable;
else throw UsageError(format("unknown flag `%1%'") % *i);
if (opArgs.size() != 0) throw UsageError("no arguments expected");
if (opArgs.size() == 0) {
printMsg(lvlInfo, "warning: you probably meant to specify the argument '*' to show all packages");
}
/* Obtain derivation information from the specified source. */
@ -733,7 +734,10 @@ static void opQuery(Globals & globals,
globals.instSource.systemFilter, availElems);
}
DrvInfos & elems(source == sInstalled ? installedElems : availElems);
DrvInfos elems = filterBySelector(globals.state,
source == sInstalled ? installedElems : availElems,
opArgs, false);
DrvInfos & otherElems(source == sInstalled ? availElems : installedElems);

View file

@ -6,19 +6,19 @@ profiles="$NIX_STATE_DIR"/profiles
test "$($nixenv -p $profiles/test -q | wc -l)" -eq 0
# Query available: should contain several.
test "$($nixenv -p $profiles/test -f ./user-envs.nix -qa | wc -l)" -eq 5
test "$($nixenv -p $profiles/test -f ./user-envs.nix -qa '*' | wc -l)" -eq 5
# Install "foo-1.0".
$nixenv -p $profiles/test -f ./user-envs.nix -i foo-1.0
# Query installed: should contain foo-1.0 now (which should be
# executable).
test "$($nixenv -p $profiles/test -q | wc -l)" -eq 1
$nixenv -p $profiles/test -q | grep -q foo-1.0
test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 1
$nixenv -p $profiles/test -q '*' | grep -q foo-1.0
test "$($profiles/test/bin/foo)" = "foo-1.0"
# Store the path of foo-1.0.
outPath10=$($nixenv -p $profiles/test -q --out-path --no-name | grep foo-1.0)
outPath10=$($nixenv -p $profiles/test -q --out-path --no-name '*' | grep foo-1.0)
echo "foo-1.0 = $outPath10"
test -n "$outPath10"
@ -26,20 +26,20 @@ test -n "$outPath10"
$nixenv -p $profiles/test -f ./user-envs.nix -i foo-2.0pre1
# Query installed: should contain foo-2.0pre1 now.
test "$($nixenv -p $profiles/test -q | wc -l)" -eq 1
$nixenv -p $profiles/test -q | grep -q foo-2.0pre1
test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 1
$nixenv -p $profiles/test -q '*' | grep -q foo-2.0pre1
test "$($profiles/test/bin/foo)" = "foo-2.0pre1"
# Upgrade "foo": should install foo-2.0.
$nixenv -p $profiles/test -f ./user-envs.nix -u foo
# Query installed: should contain foo-2.0 now.
test "$($nixenv -p $profiles/test -q | wc -l)" -eq 1
$nixenv -p $profiles/test -q | grep -q foo-2.0
test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 1
$nixenv -p $profiles/test -q '*' | grep -q foo-2.0
test "$($profiles/test/bin/foo)" = "foo-2.0"
# Store the path of foo-2.0.
outPath20=$($nixenv -p $profiles/test -q --out-path --no-name | grep foo-2.0)
outPath20=$($nixenv -p $profiles/test -q --out-path --no-name '*' | grep foo-2.0)
test -n "$outPath20"
# Install bar-0.1, uninstall foo.
@ -47,18 +47,18 @@ $nixenv -p $profiles/test -f ./user-envs.nix -i bar-0.1
$nixenv -p $profiles/test -f ./user-envs.nix -e foo
# Query installed: should only contain bar-0.1 now.
if $nixenv -p $profiles/test -q | grep -q foo; then false; fi
$nixenv -p $profiles/test -q | grep -q bar
if $nixenv -p $profiles/test -q '*' | grep -q foo; then false; fi
$nixenv -p $profiles/test -q '*' | grep -q bar
# Rollback: should bring "foo" back.
$nixenv -p $profiles/test --rollback
$nixenv -p $profiles/test -q | grep -q foo-2.0
$nixenv -p $profiles/test -q | grep -q bar
$nixenv -p $profiles/test -q '*' | grep -q foo-2.0
$nixenv -p $profiles/test -q '*' | grep -q bar
# Rollback again: should remove "bar".
$nixenv -p $profiles/test --rollback
$nixenv -p $profiles/test -q | grep -q foo-2.0
if $nixenv -p $profiles/test -q | grep -q bar; then false; fi
$nixenv -p $profiles/test -q '*' | grep -q foo-2.0
if $nixenv -p $profiles/test -q '*' | grep -q bar; then false; fi
# Count generations.
test "$($nixenv -p $profiles/test --list-generations | wc -l)" -eq 5
@ -66,7 +66,7 @@ test "$($nixenv -p $profiles/test --list-generations | wc -l)" -eq 5
# Install foo-1.0, now using its store path.
echo $outPath10
$nixenv -p $profiles/test -i "$outPath10"
$nixenv -p $profiles/test -q | grep -q foo-1.0
$nixenv -p $profiles/test -q '*' | grep -q foo-1.0
# Delete all old generations.
$nixenv -p $profiles/test --delete-generations old
@ -79,12 +79,12 @@ if test -e "$outPath20"; then false; fi
# Uninstall everything
$nixenv -p $profiles/test -f ./user-envs.nix -e '*'
test "$($nixenv -p $profiles/test -q | wc -l)" -eq 0
test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 0
# Installing "foo" should only install the newest foo.
$nixenv -p $profiles/test -f ./user-envs.nix -i foo
test "$($nixenv -p $profiles/test -q | grep foo- | wc -l)" -eq 1
$nixenv -p $profiles/test -q | grep -q foo-2.0
test "$($nixenv -p $profiles/test -q '*' | grep foo- | wc -l)" -eq 1
$nixenv -p $profiles/test -q '*' | grep -q foo-2.0
# On the other hand, this should install both (and should fail due to
# a collision).
@ -94,6 +94,6 @@ if $nixenv -p $profiles/test -f ./user-envs.nix -i foo-1.0 foo-2.0; then false;
# Installing "*" should install one foo and one bar.
$nixenv -p $profiles/test -f ./user-envs.nix -e '*'
$nixenv -p $profiles/test -f ./user-envs.nix -i '*'
test "$($nixenv -p $profiles/test -q | wc -l)" -eq 2
$nixenv -p $profiles/test -q | grep -q foo-2.0
$nixenv -p $profiles/test -q | grep -q bar-0.1.1
test "$($nixenv -p $profiles/test -q '*' | wc -l)" -eq 2
$nixenv -p $profiles/test -q '*' | grep -q foo-2.0
$nixenv -p $profiles/test -q '*' | grep -q bar-0.1.1