about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-10-28T16·33+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-10-28T16·33+0000
commitae6fb27f18fff6639f3b51ace4789537255a43a4 (patch)
treeac364f8dd4c745c6b6c2980449df0369a7906ec5
parent99b0ea7c67e9e545bdf8b8bb050ce63dc9440e95 (diff)
* `nix-store --read-log / -l PATH' shows the build log of PATH, if
  available.  For instance,

    $ nix-store -l $(which svn) | less

  lets you read the build log of the Subversion instance in your
  profile.

* `nix-store -qb': if applied to a non-derivation, take the deriver.

-rw-r--r--doc/manual/release-notes.xml17
-rw-r--r--src/libstore/build.cc2
-rw-r--r--src/libstore/build.hh3
-rw-r--r--src/nix-store/help.txt1
-rw-r--r--src/nix-store/main.cc41
5 files changed, 60 insertions, 4 deletions
diff --git a/doc/manual/release-notes.xml b/doc/manual/release-notes.xml
index 28ce94661c8f..2f2b1a040fe0 100644
--- a/doc/manual/release-notes.xml
+++ b/doc/manual/release-notes.xml
@@ -7,6 +7,23 @@
 
 <!--==================================================================-->
 
+<section><title>Release 0.11 (TBA)</title>
+
+<itemizedlist>
+
+  <listitem><para><command>nix-store</command> has a new operation
+  <option>--read-log</option> (<option>-l</option>)
+  <parameter>paths</parameter> that shows the build log of the given
+  paths.</para></listitem>
+
+</itemizedlist>
+
+</section>
+
+
+
+<!--==================================================================-->
+
 <section><title>Release 0.10.1 (October 11, 2006)</title>
 
 <para>This release fixes two somewhat obscure bugs that occur when
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 2388d008f4cf..43ac5cf53f84 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -1511,7 +1511,7 @@ void DerivationGoal::computeClosure()
 }
 
 
-static string drvsLogDir = "drvs";
+string drvsLogDir = "drvs";
 
 
 void DerivationGoal::openLogFile()
diff --git a/src/libstore/build.hh b/src/libstore/build.hh
index c90c126769ef..71895c0a9c32 100644
--- a/src/libstore/build.hh
+++ b/src/libstore/build.hh
@@ -8,6 +8,9 @@
 namespace nix {
 
     
+extern string drvsLogDir;
+
+
 /* Ensure that the output paths of the derivation are valid.  If they
    are already valid, this is a no-op.  Otherwise, validity can
    be reached in two ways.  First, if the output paths have
diff --git a/src/nix-store/help.txt b/src/nix-store/help.txt
index 388a7521fb5b..df84a2a763bc 100644
--- a/src/nix-store/help.txt
+++ b/src/nix-store/help.txt
@@ -9,6 +9,7 @@ Operations:
   --add / -A: copy a path to the Nix store
   --delete: safely delete paths from the Nix store
   --query / -q: query information
+  --read-log / -l: print build log of given store paths
 
   --register-substitutes: register a substitute expression (dangerous!)
   --clear-substitutes: clear all substitutes
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc
index b83eb883702a..ec35d430da9e 100644
--- a/src/nix-store/main.cc
+++ b/src/nix-store/main.cc
@@ -46,6 +46,17 @@ static Path fixPath(Path path)
 }
 
 
+static Path useDeriver(Path path)
+{       
+    if (!isDerivation(path)) {
+        path = queryDeriver(noTxn, path);
+        if (path == "")
+            throw Error(format("deriver of path `%1%' is not known") % path);
+    }
+    return path;
+}
+
+
 /* Realisation the given path.  For a derivation that means build it;
    for other paths it means ensure their validity. */
 static Path realisePath(const Path & path)
@@ -360,12 +371,12 @@ static void opQuery(Strings opFlags, Strings opArgs)
             for (Strings::iterator i = opArgs.begin();
                  i != opArgs.end(); ++i)
             {
-                *i = fixPath(*i);
-                Derivation drv = derivationFromPath(*i);
+                Path path = useDeriver(fixPath(*i));
+                Derivation drv = derivationFromPath(path);
                 StringPairs::iterator j = drv.env.find(bindingName);
                 if (j == drv.env.end())
                     throw Error(format("derivation `%1%' has no environment binding named `%2%'")
-                        % *i % bindingName);
+                        % path % bindingName);
                 cout << format("%1%\n") % j->second;
             }
             break;
@@ -404,6 +415,28 @@ static void opQuery(Strings opFlags, Strings opArgs)
 }
 
 
+static void opReadLog(Strings opFlags, Strings opArgs)
+{
+    if (!opFlags.empty()) throw UsageError("unknown flag");
+
+    for (Strings::iterator i = opArgs.begin();
+         i != opArgs.end(); ++i)
+    {
+        Path path = useDeriver(fixPath(*i));
+        
+        Path logPath = (format("%1%/%2%/%3%") %
+            nixLogDir % drvsLogDir % baseNameOf(path)).str();
+
+        if (!pathExists(logPath))
+            throw Error(format("build log of derivation `%1%' is not available") % path);
+
+        /* !!! Make this run in O(1) memory. */
+        string log = readFile(logPath);
+        writeFull(STDOUT_FILENO, (const unsigned char *) log.c_str(), log.size());
+    }
+}
+
+
 static void opRegisterSubstitutes(Strings opFlags, Strings opArgs)
 {
     if (!opFlags.empty()) throw UsageError("unknown flag");
@@ -663,6 +696,8 @@ void run(Strings args)
             op = opDelete;
         else if (arg == "--query" || arg == "-q")
             op = opQuery;
+        else if (arg == "--read-log" || arg == "-l")
+            op = opReadLog;
         else if (arg == "--register-substitutes")
             op = opRegisterSubstitutes;
         else if (arg == "--clear-substitutes")