From 90948a4e3a64492b7d117d93657221fa7b598e6e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 24 Nov 2017 18:07:29 +0100 Subject: nix-shell/nix-build: Support .drv files again Fixes #1663. Also handle '!' (#1694). --- src/libexpr/get-drvs.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/libexpr/get-drvs.cc') diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc index d5bc42352a26..d38ed2df3b18 100644 --- a/src/libexpr/get-drvs.cc +++ b/src/libexpr/get-drvs.cc @@ -1,6 +1,7 @@ #include "get-drvs.hh" #include "util.hh" #include "eval-inline.hh" +#include "derivations.hh" #include #include @@ -15,6 +16,33 @@ DrvInfo::DrvInfo(EvalState & state, const string & attrPath, Bindings * attrs) } +DrvInfo::DrvInfo(EvalState & state, ref store, const std::string & drvPathWithOutputs) + : state(&state), attrs(nullptr), attrPath("") +{ + auto spec = parseDrvPathWithOutputs(drvPathWithOutputs); + + drvPath = spec.first; + + auto drv = store->derivationFromPath(drvPath); + + name = storePathToName(drvPath); + + if (spec.second.size() > 1) + throw Error("building more than one derivation output is not supported, in '%s'", drvPathWithOutputs); + + outputName = + spec.second.empty() + ? get(drv.env, "outputName", "out") + : *spec.second.begin(); + + auto i = drv.outputs.find(outputName); + if (i == drv.outputs.end()) + throw Error("derivation '%s' does not have output '%s'", drvPath, outputName); + + outPath = i->second.path; +} + + string DrvInfo::queryName() const { if (name == "" && attrs) { -- cgit 1.4.1