about summary refs log tree commit diff
path: root/src/nix-store
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-01-19T14·36+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-01-19T14·36+0000
commit06c77bf7a861221d41b5db9fad3002f13a14ed0e (patch)
tree8ddd8857f0364297bb8ffce1cf6a89b7cf0d396e /src/nix-store
parent863dcff6c5ffc163010ec1f9e6819bb9aaaadc29 (diff)
* Change extension `.store' to `.drv'.
* Re-enable `nix-store --query --requisites'.

Diffstat (limited to 'src/nix-store')
-rw-r--r--src/nix-store/help.txt13
-rw-r--r--src/nix-store/main.cc70
2 files changed, 42 insertions, 41 deletions
diff --git a/src/nix-store/help.txt b/src/nix-store/help.txt
index cbded730e8..1bd752fc11 100644
--- a/src/nix-store/help.txt
+++ b/src/nix-store/help.txt
@@ -4,14 +4,12 @@ nix-store [OPTIONS...] [ARGUMENTS...]
 
 Operations:
 
-  --realise / -r: realise a Nix expression
-  --delete / -d: delete paths from the Nix store
+  --build / -b: build a Nix derivation
   --add / -A: copy a path to the Nix store
   --query / -q: query information
 
-  --successor: register a successor expression (dangerous!)
   --substitute: register a substitute expression (dangerous!)
-  --clear-substitute: clear all substitutes
+  --clear-substitutes: clear all substitutes
   --validpath: register path validity (dangerous!)
   --isvalid: check path validity
 
@@ -26,9 +24,10 @@ Operations:
 
 Query flags:
 
-  --list / -l: query the output paths (roots) of a Nix expression (default)
-  --requisites / -R: print all paths necessary to realise expression
-  --predecessors: print predecessors of a Nix expression
+  --outputs: query the output paths of a Nix derivation (default)
+  --requisites / -R: print all paths necessary to realise a path
+  --references: print all paths referenced by the given path
+  --referers: print all paths refering to the given path
   --graph: print a dot graph rooted at given ids
 
 Options:
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc
index 5a67a6af64..12b61c76f7 100644
--- a/src/nix-store/main.cc
+++ b/src/nix-store/main.cc
@@ -18,6 +18,15 @@ void printHelp()
 }
 
 
+static Path findOutput(const Derivation & drv, string id)
+{
+    for (DerivationOutputs::const_iterator i = drv.outputs.begin();
+         i != drv.outputs.end(); ++i)
+        if (i->first == id) return i->second.path;
+    throw Error(format("derivation has no output `%1%'") % id);
+}
+
+
 /* Build the given derivations. */
 static void opBuild(Strings opFlags, Strings opArgs)
 {
@@ -25,7 +34,11 @@ static void opBuild(Strings opFlags, Strings opArgs)
 
     for (Strings::iterator i = opArgs.begin();
          i != opArgs.end(); i++)
+    {
         buildDerivation(*i);
+        Derivation drv = derivationFromPath(*i);
+        cout << format("%1%\n") % findOutput(drv, "out");
+    }
 }
 
 
@@ -40,70 +53,59 @@ static void opAdd(Strings opFlags, Strings opArgs)
 }
 
 
-#if 0
-Path maybeNormalise(const Path & ne, bool normalise, bool realise)
+static Path maybeUseOutput(const Path & storePath, bool useOutput)
 {
-    if (realise) {
-        Path ne2 = realiseStoreExpr(ne);
-        return normalise ? ne2 : ne;
-    } else
-        return normalise ? normaliseStoreExpr(ne) : ne;
+    if (useOutput && isDerivation(storePath)) {
+        Derivation drv = derivationFromPath(storePath);
+        return findOutput(drv, "out");
+    }
+    else return storePath;
 }
 
 
 /* Perform various sorts of queries. */
 static void opQuery(Strings opFlags, Strings opArgs)
 {
-    enum { qList, qRequisites, qPredecessors, qGraph 
-    } query = qList;
-    bool normalise = false;
-    bool realise = false;
-    bool includeExprs = true;
-    bool includeSuccessors = false;
+    enum { qOutputs, qRequisites, qPredecessors, qGraph } query = qOutputs;
+    bool useOutput = false;
+    bool includeOutputs = false;
 
     for (Strings::iterator i = opFlags.begin();
          i != opFlags.end(); i++)
-        if (*i == "--list" || *i == "-l") query = qList;
+        if (*i == "--outputs") query = qOutputs;
         else if (*i == "--requisites" || *i == "-R") query = qRequisites;
-        else if (*i == "--predecessors") query = qPredecessors;
         else if (*i == "--graph") query = qGraph;
-        else if (*i == "--normalise" || *i == "-n") normalise = true;
-        else if (*i == "--force-realise" || *i == "-f") realise = true;
-        else if (*i == "--exclude-exprs") includeExprs = false;
-        else if (*i == "--include-successors") includeSuccessors = true;
+        else if (*i == "--use-output" || *i == "-u") useOutput = true;
+        else if (*i == "--include-outputs") includeOutputs = true;
         else throw UsageError(format("unknown flag `%1%'") % *i);
 
     switch (query) {
         
-        case qList: {
+        case qOutputs: {
             for (Strings::iterator i = opArgs.begin();
                  i != opArgs.end(); i++)
             {
-                StringSet paths = storeExprRoots(
-                    maybeNormalise(*i, normalise, realise));
-                for (StringSet::iterator j = paths.begin(); 
-                     j != paths.end(); j++)
-                    cout << format("%s\n") % *j;
+                Derivation drv = derivationFromPath(*i);
+                cout << format("%1%\n") % findOutput(drv, "out");
             }
             break;
         }
 
         case qRequisites: {
-            StringSet paths;
+            PathSet paths;
             for (Strings::iterator i = opArgs.begin();
                  i != opArgs.end(); i++)
             {
-                StringSet paths2 = storeExprRequisites(
-                    maybeNormalise(*i, normalise, realise),
-                    includeExprs, includeSuccessors);
-                paths.insert(paths2.begin(), paths2.end());
+                Path path = maybeUseOutput(*i, useOutput);
+                storePathRequisites(path, includeOutputs, paths);
             }
-            for (StringSet::iterator i = paths.begin(); 
+            for (PathSet::iterator i = paths.begin(); 
                  i != paths.end(); i++)
                 cout << format("%s\n") % *i;
             break;
         }
 
+#if 0            
         case qPredecessors: {
             for (Strings::iterator i = opArgs.begin();
                  i != opArgs.end(); i++)
@@ -124,12 +126,12 @@ static void opQuery(Strings opFlags, Strings opArgs)
 	    printDotGraph(roots);
             break;
         }
+#endif
 
         default:
             abort();
     }
 }
-#endif
 
 
 static void opSubstitute(Strings opFlags, Strings opArgs)
@@ -340,8 +342,8 @@ void run(Strings args)
             op = opBuild;
         else if (arg == "--add" || arg == "-A")
             op = opAdd;
-        //        else if (arg == "--query" || arg == "-q")
-        //            op = opQuery;
+        else if (arg == "--query" || arg == "-q")
+            op = opQuery;
         else if (arg == "--substitute")
             op = opSubstitute;
         else if (arg == "--clear-substitutes")