about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-11-26T14·39+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-11-26T14·39+0100
commit46a369ad9558939bc2c6ee588df483ca503bbb5a (patch)
tree7a3fc4d49d0a5fb29d1c6e139672d91f86e71f47 /src/libstore
parenta3d6585c5a1006d4f9ebd2163d06f86ab71a4a3e (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/libstore')
-rw-r--r--src/libstore/build.cc8
-rw-r--r--src/libstore/derivations.cc17
-rw-r--r--src/libstore/derivations.hh9
-rw-r--r--src/libstore/misc.cc11
4 files changed, 38 insertions, 7 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 9e0db9ee7f0a..5e5cd6b23bb9 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -3197,11 +3197,13 @@ void LocalStore::buildPaths(const PathSet & drvPaths, bool repair)
     Worker worker(*this);
 
     Goals goals;
-    foreach (PathSet::const_iterator, i, drvPaths)
-        if (isDerivation(*i))
-            goals.insert(worker.makeDerivationGoal(*i, repair));
+    foreach (PathSet::const_iterator, i, drvPaths) {
+        DrvPathWithOutputs i2 = parseDrvPathWithOutputs(*i);
+        if (isDerivation(i2.first))
+            goals.insert(worker.makeDerivationGoal(i2.first, repair));
         else
             goals.insert(worker.makeSubstitutionGoal(*i, repair));
+    }
 
     worker.run(goals);
 
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index e0a4f43c0bb8..1551ae28a81a 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -252,4 +252,21 @@ Hash hashDerivationModulo(StoreAPI & store, Derivation drv)
 }
 
 
+DrvPathWithOutputs parseDrvPathWithOutputs(const string & s)
+{
+    size_t n = s.find("!");
+    return n == s.npos
+        ? DrvPathWithOutputs(s, std::set<string>())
+        : DrvPathWithOutputs(string(s, 0, n), tokenizeString<std::set<string> >(string(s, n + 1), ","));
+}
+
+
+Path makeDrvPathWithOutputs(const Path & drvPath, std::set<string> outputs)
+{
+    return outputs.empty()
+        ? drvPath
+        : drvPath + "!" + concatStringsSep(",", outputs);
+}
+
+
 }
diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh
index 7d38e60c0fe6..6b7c3e6ab189 100644
--- a/src/libstore/derivations.hh
+++ b/src/libstore/derivations.hh
@@ -79,4 +79,13 @@ typedef std::map<Path, Hash> DrvHashes;
 
 extern DrvHashes drvHashes;
 
+/* Split a string specifying a derivation and a set of outputs
+   (/nix/store/hash-foo!out1,out2,...) into the derivation path and
+   the outputs. */
+typedef std::pair<string, std::set<string> > DrvPathWithOutputs;
+DrvPathWithOutputs parseDrvPathWithOutputs(const string & s);
+
+Path makeDrvPathWithOutputs(const Path & drvPath, std::set<string> outputs);
+
+
 }
diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc
index 3ce300e30678..dacd1d3d7474 100644
--- a/src/libstore/misc.cc
+++ b/src/libstore/misc.cc
@@ -82,20 +82,23 @@ void queryMissing(StoreAPI & store, const PathSet & targets,
             if (done.find(*i) != done.end()) continue;
             done.insert(*i);
 
-            if (isDerivation(*i)) {
-                if (!store.isValidPath(*i)) {
+            DrvPathWithOutputs i2 = parseDrvPathWithOutputs(*i);
+
+            if (isDerivation(i2.first)) {
+                if (!store.isValidPath(i2.first)) {
                     // FIXME: we could try to substitute p.
                     unknown.insert(*i);
                     continue;
                 }
-                Derivation drv = derivationFromPath(store, *i);
+                Derivation drv = derivationFromPath(store, i2.first);
 
                 PathSet invalid;
+                // FIXME: only fetch the desired outputs
                 foreach (DerivationOutputs::iterator, j, drv.outputs)
                     if (!store.isValidPath(j->second.path)) invalid.insert(j->second.path);
                 if (invalid.empty()) continue;
 
-                todoDrv.insert(*i);
+                todoDrv.insert(i2.first);
                 if (settings.useSubstitutes) query.insert(invalid.begin(), invalid.end());
             }