1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-05 20:41:47 +02:00

Make "nix-build -A <derivation>.<output>" do the right thing

For example, given a derivation with outputs "out", "man" and "bin":

  $ nix-build -A pkg

produces ./result pointing to the "out" output;

  $ nix-build -A pkg.man

produces ./result-man pointing to the "man" output;

  $ nix-build -A pkg.all

produces ./result, ./result-man and ./result-bin;

  $ nix-build -A pkg.all -A pkg2

produces ./result, ./result-man, ./result-bin and ./result-2.
This commit is contained in:
Eelco Dolstra 2012-11-26 15:39:10 +01:00
parent a3d6585c5a
commit 46a369ad95
10 changed files with 106 additions and 20 deletions

View file

@ -8,6 +8,7 @@
#include "util.hh"
#include "store-api.hh"
#include "common-opts.hh"
#include "misc.hh"
#include <map>
#include <iostream>
@ -59,6 +60,19 @@ void processExpr(EvalState & state, const Strings & attrPaths,
getDerivations(state, v, "", autoArgs, drvs, false);
foreach (DrvInfos::iterator, i, drvs) {
Path drvPath = i->queryDrvPath(state);
/* What output do we want? */
Path outPath = i->queryOutPath(state);
Derivation drv = derivationFromPath(*store, drvPath);
string outputName;
foreach (DerivationOutputs::iterator, i, drv.outputs)
if (i->second.path == outPath) {
outputName = i->first;
break;
}
if (outputName == "")
throw Error(format("derivation `%1%' does not have an output `%2%'") % drvPath % outPath);
if (gcRoot == "")
printGCWarning();
else {
@ -66,7 +80,7 @@ void processExpr(EvalState & state, const Strings & attrPaths,
if (++rootNr > 1) rootName += "-" + int2String(rootNr);
drvPath = addPermRoot(*store, drvPath, rootName, indirectRoot);
}
std::cout << format("%1%\n") % drvPath;
std::cout << format("%1%%2%\n") % drvPath % (outputName != "out" ? "!" + outputName : "");
}
}
}