summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-18 10:47:59 -0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-18 10:47:59 -0400
commitfe241ece2932492866693d268d02a7912e766ac7 (patch)
tree2cb24a4d45f563e32946bf34d878969bd05263ec /src
parenta6f348599c94d8a5f7b41c7d8e43658dc6407be7 (diff)
parentccc52adfb2121ade510d35dc9b91193af9fa731e (diff)
downloadguix-fe241ece2932492866693d268d02a7912e766ac7.tar.gz
Merge branch 'master' into no-manifests
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/eval.cc9
-rw-r--r--src/libexpr/eval.hh4
-rw-r--r--src/libexpr/primops.cc6
-rw-r--r--src/libstore/build.cc41
-rw-r--r--src/libstore/local-store.cc24
-rw-r--r--src/libstore/local-store.hh3
-rw-r--r--src/libstore/remote-store.cc12
-rw-r--r--src/libstore/remote-store.hh2
-rw-r--r--src/libstore/store-api.hh4
-rw-r--r--src/libstore/worker-protocol.hh7
-rw-r--r--src/nix-worker/nix-worker.cc9
11 files changed, 92 insertions, 29 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 6ce65e3e11..cf7c62ad20 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -143,9 +143,7 @@ EvalState::EvalState()
     , staticBaseEnv(false, 0)
 {
     nrEnvs = nrValuesInEnvs = nrValues = nrListElems = 0;
-    nrEvaluated = recursionDepth = maxRecursionDepth = 0;
     nrAttrsets = nrOpUpdates = nrOpUpdateValuesCopied = 0;
-    deepestStack = (char *) -1;
 
 #if HAVE_BOEHMGC
     static bool gcInitialised = true;
@@ -190,7 +188,6 @@ EvalState::EvalState()
 
 EvalState::~EvalState()
 {
-    assert(recursionDepth == 0);
 }
 
 
@@ -1206,12 +1203,6 @@ void EvalState::printStats()
 
     printMsg(v, format("  time elapsed: %1%") % cpuTime);
     printMsg(v, format("  size of a value: %1%") % sizeof(Value));
-    printMsg(v, format("  expressions evaluated: %1%") % nrEvaluated);
-    char x;
-    printMsg(v, format("  stack space used: %1% bytes") % (&x - deepestStack));
-    printMsg(v, format("  max eval() nesting depth: %1%") % maxRecursionDepth);
-    printMsg(v, format("  stack space per eval() level: %1% bytes")
-        % ((&x - deepestStack) / (float) maxRecursionDepth));
     printMsg(v, format("  environments allocated: %1% (%2% bytes)")
         % nrEnvs % (nrEnvs * sizeof(Env) + nrValuesInEnvs * sizeof(Value *)));
     printMsg(v, format("  list elements: %1% (%2% bytes)")
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index c4ba170e8c..bab9303b08 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -242,13 +242,9 @@ private:
     unsigned long nrValuesInEnvs;
     unsigned long nrValues;
     unsigned long nrListElems;
-    unsigned long nrEvaluated;
     unsigned long nrAttrsets;
     unsigned long nrOpUpdates;
     unsigned long nrOpUpdateValuesCopied;
-    unsigned int recursionDepth;
-    unsigned int maxRecursionDepth;
-    char * deepestStack; /* for measuring stack usage */
     
     friend class RecursionCounter;
     friend class ExprOpUpdate;
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 354fc39be0..f20c2f2879 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -508,7 +508,11 @@ static void prim_toPath(EvalState & state, Value * * args, Value & v)
 static void prim_storePath(EvalState & state, Value * * args, Value & v)
 {
     PathSet context;
-    Path path = canonPath(state.coerceToPath(*args[0], context));
+    Path path = state.coerceToPath(*args[0], context);
+    /* Resolve symlinks in ‘path’, unless ‘path’ itself is a symlink
+       directly in the store.  The latter condition is necessary so
+       e.g. nix-push does the right thing. */
+    if (!isStorePath(path)) path = canonPath(path, true);
     if (!isInStore(path))
         throw EvalError(format("path `%1%' is not in the Nix store") % path);
     Path path2 = toStorePath(path);
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 76e77b8f01..4bef6f02dc 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -777,6 +777,7 @@ private:
     /* File descriptor for the log file. */
     FILE * fLogFile;
     BZFILE * bzLogFile;
+    AutoCloseFD fdLogFile;
 
     /* Pipe for the builder's standard output/error. */
     Pipe builderOut;
@@ -1801,6 +1802,9 @@ void DerivationGoal::startBuilder()
          with outside processes using SysV IPC mechanisms (shared
          memory, message queues, semaphores).  It also ensures that
          all IPC objects are destroyed when the builder exits.
+
+       - The UTS namespace ensures that builders see a hostname of
+         localhost rather than the actual hostname.
     */
 #if CHROOT_ENABLED
     if (useChroot) {
@@ -2125,20 +2129,29 @@ Path DerivationGoal::openLogFile()
     Path dir = (format("%1%/%2%") % nixLogDir % drvsLogDir).str();
     createDirs(dir);
 
-    Path logFileName = (format("%1%/%2%.bz2") % dir % baseNameOf(drvPath)).str();
-    AutoCloseFD fd = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666);
-    if (fd == -1)
-        throw SysError(format("creating log file `%1%'") % logFileName);
-    closeOnExec(fd);
+    if (queryBoolSetting("build-compress-log", true)) {
+
+        Path logFileName = (format("%1%/%2%.bz2") % dir % baseNameOf(drvPath)).str();
+        AutoCloseFD fd = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666);
+        if (fd == -1) throw SysError(format("creating log file `%1%'") % logFileName);
+        closeOnExec(fd);
 
-    if (!(fLogFile = fdopen(fd.borrow(), "w")))
-        throw SysError(format("opening file `%1%'") % logFileName);
+        if (!(fLogFile = fdopen(fd.borrow(), "w")))
+            throw SysError(format("opening file `%1%'") % logFileName);
+
+        int err;
+        if (!(bzLogFile = BZ2_bzWriteOpen(&err, fLogFile, 9, 0, 0)))
+            throw Error(format("cannot open compressed log file `%1%'") % logFileName);
 
-    int err;
-    if (!(bzLogFile = BZ2_bzWriteOpen(&err, fLogFile, 9, 0, 0)))
-        throw Error(format("cannot open compressed log file `%1%'") % logFileName);
+        return logFileName;
 
-    return logFileName;
+    } else {
+        Path logFileName = (format("%1%/%2%") % dir % baseNameOf(drvPath)).str();
+        fdLogFile = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0666);
+        if (fdLogFile == -1) throw SysError(format("creating log file `%1%'") % logFileName);
+        closeOnExec(fdLogFile);
+        return logFileName;
+    }
 }
 
 
@@ -2155,6 +2168,8 @@ void DerivationGoal::closeLogFile()
         fclose(fLogFile);
         fLogFile = 0;
     }
+
+    fdLogFile.close();
 }
 
 
@@ -2186,7 +2201,8 @@ void DerivationGoal::handleChildOutput(int fd, const string & data)
             int err;
             BZ2_bzWrite(&err, bzLogFile, (unsigned char *) data.data(), data.size());
             if (err != BZ_OK) throw Error(format("cannot write to compressed log file (BZip2 error = %1%)") % err);
-        }
+        } else if (fdLogFile != -1)
+            writeFull(fdLogFile, (unsigned char *) data.data(), data.size());
     }
 
     if (hook && fd == hook->fromHook.readSide)
@@ -2224,6 +2240,7 @@ bool DerivationGoal::pathFailed(const Path & path)
     if (printBuildTrace)
         printMsg(lvlError, format("@ build-failed %1% %2% cached") % drvPath % path);
     
+    worker.permanentFailure = true;
     amDone(ecFailed);
 
     return true;
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 6e4cd053c8..aa21774df4 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -405,6 +405,10 @@ void LocalStore::openDB(bool create)
         "select v.id, v.path from DerivationOutputs d join ValidPaths v on d.drv = v.id where d.path = ?;");
     stmtQueryDerivationOutputs.create(db,
         "select id, path from DerivationOutputs where drv = ?;");
+    // Use "path >= ?" with limit 1 rather than "path like '?%'" to
+    // ensure efficient lookup.
+    stmtQueryPathFromHashPart.create(db,
+        "select path from ValidPaths where path >= ? limit 1;");
 }
 
 
@@ -874,6 +878,26 @@ StringSet LocalStore::queryDerivationOutputNames(const Path & path)
 }
 
 
+Path LocalStore::queryPathFromHashPart(const string & hashPart)
+{
+    if (hashPart.size() != 32) throw Error("invalid hash part");
+    
+    SQLiteTxn txn(db);
+
+    Path prefix = nixStore + "/" + hashPart;
+    
+    SQLiteStmtUse use(stmtQueryPathFromHashPart);
+    stmtQueryPathFromHashPart.bind(prefix);
+
+    int res = sqlite3_step(stmtQueryPathFromHashPart);
+    if (res == SQLITE_DONE) return "";
+    if (res != SQLITE_ROW) throwSQLiteError(db, "finding path in database");
+
+    const char * s = (const char *) sqlite3_column_text(stmtQueryPathFromHashPart, 0);
+    return s && prefix.compare(0, prefix.size(), s, prefix.size()) == 0 ? s : "";
+}
+
+
 void LocalStore::startSubstituter(const Path & substituter, RunningSubstituter & run)
 {
     if (run.pid != -1) return;
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index 3281a9106e..07d8198eca 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -123,6 +123,8 @@ public:
 
     StringSet queryDerivationOutputNames(const Path & path);
     
+    Path queryPathFromHashPart(const string & hashPart);
+    
     PathSet querySubstitutablePaths(const PathSet & paths);
 
     void querySubstitutablePathInfos(const Path & substituter,
@@ -217,6 +219,7 @@ private:
     SQLiteStmt stmtAddDerivationOutput;
     SQLiteStmt stmtQueryValidDerivers;
     SQLiteStmt stmtQueryDerivationOutputs;
+    SQLiteStmt stmtQueryPathFromHashPart;
 
     int getSchema();
 
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 2232720c2b..35530acab1 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -395,6 +395,18 @@ PathSet RemoteStore::queryDerivationOutputNames(const Path & path)
 }
 
 
+Path RemoteStore::queryPathFromHashPart(const string & hashPart)
+{
+    openConnection();
+    writeInt(wopQueryPathFromHashPart, to);
+    writeString(hashPart, to);
+    processStderr();
+    Path path = readString(from);
+    if (!path.empty()) assertStorePath(path);
+    return path;
+}
+
+
 Path RemoteStore::addToStore(const Path & _srcPath,
     bool recursive, HashType hashAlgo, PathFilter & filter)
 {
diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh
index 5b007be483..68db0640ae 100644
--- a/src/libstore/remote-store.hh
+++ b/src/libstore/remote-store.hh
@@ -45,6 +45,8 @@ public:
     
     StringSet queryDerivationOutputNames(const Path & path);
 
+    Path queryPathFromHashPart(const string & hashPart);
+    
     PathSet querySubstitutablePaths(const PathSet & paths);
     
     void querySubstitutablePathInfos(const PathSet & paths,
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index e7963d053f..5d8c09f5a5 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -144,6 +144,10 @@ public:
 
     /* Query the output names of the derivation denoted by `path'. */
     virtual StringSet queryDerivationOutputNames(const Path & path) = 0;
+
+    /* Query the full store path given the hash part of a valid store
+       path, or "" if the path doesn't exist. */
+    virtual Path queryPathFromHashPart(const string & hashPart) = 0;
     
     /* Query which of the given paths have substitutes. */
     virtual PathSet querySubstitutablePaths(const PathSet & paths) = 0;
diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh
index 6011ec211d..d4ac0ea16f 100644
--- a/src/libstore/worker-protocol.hh
+++ b/src/libstore/worker-protocol.hh
@@ -40,9 +40,10 @@ typedef enum {
     wopQueryPathInfo = 26,
     wopImportPaths = 27,
     wopQueryDerivationOutputNames = 28,
-    wopQuerySubstitutablePathInfos = 29,
-    wopQueryValidPaths = 30,
-    wopQuerySubstitutablePaths = 31,
+    wopQueryPathFromHashPart = 29,
+    wopQuerySubstitutablePathInfos = 30,
+    wopQueryValidPaths = 31,
+    wopQuerySubstitutablePaths = 32,
 } WorkerOp;
 
 
diff --git a/src/nix-worker/nix-worker.cc b/src/nix-worker/nix-worker.cc
index d3907fa8f1..f2ca0a8923 100644
--- a/src/nix-worker/nix-worker.cc
+++ b/src/nix-worker/nix-worker.cc
@@ -368,6 +368,15 @@ static void performOp(unsigned int clientVersion,
         break;
     }
 
+    case wopQueryPathFromHashPart: {
+        string hashPart = readString(from);
+        startWork();
+        Path path = store->queryPathFromHashPart(hashPart);
+        stopWork();
+        writeString(path, to);
+        break;
+    }
+
     case wopAddToStore: {
         string baseName = readString(from);
         bool fixed = readInt(from) == 1; /* obsolete */