diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-11-26T14·39+0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-11-26T14·39+0100 |
commit | 46a369ad9558939bc2c6ee588df483ca503bbb5a (patch) | |
tree | 7a3fc4d49d0a5fb29d1c6e139672d91f86e71f47 /src/nix-instantiate | |
parent | a3d6585c5a1006d4f9ebd2163d06f86ab71a4a3e (diff) |
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.
Diffstat (limited to 'src/nix-instantiate')
-rw-r--r-- | src/nix-instantiate/nix-instantiate.cc | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc index ab0c8cf28bdf..a5053c32376d 100644 --- a/src/nix-instantiate/nix-instantiate.cc +++ b/src/nix-instantiate/nix-instantiate.cc @@ -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 : ""); } } } |