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-store/nix-store.cc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/nix-store/nix-store.cc') diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index e973beda9f0f..c0da37d251da 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -60,13 +60,21 @@ static Path useDeriver(Path path) other paths it means ensure their validity. */ static PathSet realisePath(const Path & path, bool build = true) { - if (isDerivation(path)) { + DrvPathWithOutputs p = parseDrvPathWithOutputs(path); + + if (isDerivation(p.first)) { if (build) store->buildPaths(singleton(path)); - Derivation drv = derivationFromPath(*store, path); + Derivation drv = derivationFromPath(*store, p.first); rootNr++; + if (p.second.empty()) + foreach (DerivationOutputs::iterator, i, drv.outputs) p.second.insert(i->first); + PathSet outputs; - foreach (DerivationOutputs::iterator, i, drv.outputs) { + foreach (StringSet::iterator, j, p.second) { + DerivationOutputs::iterator i = drv.outputs.find(*j); + if (i == drv.outputs.end()) + throw Error(format("derivation `%1%' does not have an output named `%2%'") % p.first % *j); Path outPath = i->second.path; if (gcRoot == "") printGCWarning(); @@ -103,8 +111,10 @@ static void opRealise(Strings opFlags, Strings opArgs) else throw UsageError(format("unknown flag `%1%'") % *i); Paths paths; - foreach (Strings::iterator, i, opArgs) - paths.push_back(followLinksToStorePath(*i)); + foreach (Strings::iterator, i, opArgs) { + DrvPathWithOutputs p = parseDrvPathWithOutputs(*i); + paths.push_back(makeDrvPathWithOutputs(followLinksToStorePath(p.first), p.second)); + } unsigned long long downloadSize, narSize; PathSet willBuild, willSubstitute, unknown; -- cgit 1.4.1