From 46a369ad9558939bc2c6ee588df483ca503bbb5a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 26 Nov 2012 15:39:10 +0100 Subject: Make "nix-build -A ." 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. --- src/nix-instantiate/nix-instantiate.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/nix-instantiate') 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 #include @@ -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 : ""); } } } -- cgit 1.4.1