From 03427e76f11fe1d918020d28bdb69b2fb348ee96 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 4 Aug 2008 11:44:50 +0000 Subject: [PATCH] * querySubstitutablePathInfo: work properly when run via the daemon. * --dry-run: print the paths that we don't know how to build/substitute. --- src/libmain/shared.cc | 2 +- src/libstore/misc.cc | 14 ++++++++------ src/libstore/misc.hh | 2 +- src/libstore/remote-store.cc | 11 ++++++++++- src/libstore/worker-protocol.hh | 1 + src/nix-env/nix-env.cc | 17 ++++++++++++----- src/nix-worker/nix-worker.cc | 18 ++++++++++++++++-- 7 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 36b4ebdc9..5a8f600e8 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -217,7 +217,7 @@ static void initAndRun(int argc, char * * argv) /* Automatically clean up the temporary roots file when we exit. */ - RemoveTempRoots removeTempRoots; /* unused variable - don't remove */ + RemoveTempRoots removeTempRoots __attribute__((unused)); /* Make sure that the database gets closed properly, even if terminate() is called (which happens sometimes due to bugs in diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc index acf9346d4..1759f521c 100644 --- a/src/libstore/misc.cc +++ b/src/libstore/misc.cc @@ -46,7 +46,7 @@ Path findOutput(const Derivation & drv, string id) void queryMissing(const PathSet & targets, - PathSet & willBuild, PathSet & willSubstitute) + PathSet & willBuild, PathSet & willSubstitute, PathSet & unknown) { PathSet todo(targets.begin(), targets.end()), done; @@ -57,7 +57,10 @@ void queryMissing(const PathSet & targets, done.insert(p); if (isDerivation(p)) { - if (!store->isValidPath(p)) continue; + if (!store->isValidPath(p)) { + unknown.insert(p); + continue; + } Derivation drv = derivationFromPath(p); bool mustBuild = false; @@ -81,12 +84,11 @@ void queryMissing(const PathSet & targets, else { if (store->isValidPath(p)) continue; SubstitutablePathInfo info; - if (dynamic_cast(store.get())->querySubstitutablePathInfo(p, info)) { + if (store->querySubstitutablePathInfo(p, info)) { willSubstitute.insert(p); todo.insert(info.references.begin(), info.references.end()); - } - /* Not substitutable and not buildable; should we flag - this? */ + } else + unknown.insert(p); } } } diff --git a/src/libstore/misc.hh b/src/libstore/misc.hh index ad1ad80eb..33d81ed4a 100644 --- a/src/libstore/misc.hh +++ b/src/libstore/misc.hh @@ -29,7 +29,7 @@ Path findOutput(const Derivation & drv, string id); derivations that will be built, and the set of output paths that will be substituted. */ void queryMissing(const PathSet & targets, - PathSet & willBuild, PathSet & willSubstitute); + PathSet & willBuild, PathSet & willSubstitute, PathSet & unknown); } diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index b7e60043d..bc04c8adb 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -216,7 +216,16 @@ bool RemoteStore::hasSubstitutes(const Path & path) bool RemoteStore::querySubstitutablePathInfo(const Path & path, SubstitutablePathInfo & info) { - throw Error("not implemented"); + writeInt(wopQuerySubstitutablePathInfo, to); + writeString(path, to); + processStderr(); + unsigned int reply = readInt(from); + if (reply == 0) return false; + info.deriver = readString(from); + if (info.deriver != "") assertStorePath(info.deriver); + info.references = readStorePaths(from); + info.downloadSize = readLongLong(from); + return true; } diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh index d887ee59b..1146f9577 100644 --- a/src/libstore/worker-protocol.hh +++ b/src/libstore/worker-protocol.hh @@ -33,6 +33,7 @@ typedef enum { wopQueryDeriver = 18, wopSetOptions = 19, wopCollectGarbage = 20, + wopQuerySubstitutablePathInfo = 21, } WorkerOp; diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index f561dc2e5..ee870f690 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -531,7 +531,7 @@ static void queryInstSources(EvalState & state, static void printMissing(EvalState & state, const DrvInfos & elems) { - PathSet targets, willBuild, willSubstitute; + PathSet targets, willBuild, willSubstitute, unknown; for (DrvInfos::const_iterator i = elems.begin(); i != elems.end(); ++i) { Path drvPath = i->queryDrvPath(state); if (drvPath != "") @@ -540,17 +540,24 @@ static void printMissing(EvalState & state, const DrvInfos & elems) targets.insert(i->queryOutPath(state)); } - queryMissing(targets, willBuild, willSubstitute); + queryMissing(targets, willBuild, willSubstitute, unknown); if (!willBuild.empty()) { printMsg(lvlInfo, format("the following derivations will be built:")); - for (PathSet::iterator i = willBuild.begin(); i != willBuild.end(); ++i) + foreach (PathSet::iterator, i, willBuild) printMsg(lvlInfo, format(" %1%") % *i); } if (!willSubstitute.empty()) { - printMsg(lvlInfo, format("the following paths will be substituted:")); - for (PathSet::iterator i = willSubstitute.begin(); i != willSubstitute.end(); ++i) + printMsg(lvlInfo, format("the following paths will be downloaded/copied:")); + foreach (PathSet::iterator, i, willSubstitute) + printMsg(lvlInfo, format(" %1%") % *i); + } + + if (!unknown.empty()) { + printMsg(lvlInfo, format("don't know how to build the following paths%1%:") + % (readOnlyMode ? " (may be caused by read-only store access)" : "")); + foreach (PathSet::iterator, i, unknown) printMsg(lvlInfo, format(" %1%") % *i); } } diff --git a/src/nix-worker/nix-worker.cc b/src/nix-worker/nix-worker.cc index d8d86434e..377f2be73 100644 --- a/src/nix-worker/nix-worker.cc +++ b/src/nix-worker/nix-worker.cc @@ -430,7 +430,21 @@ static void performOp(unsigned int clientVersion, stopWork(); break; } - + + case wopQuerySubstitutablePathInfo: { + Path path = absPath(readString(from)); + startWork(); + SubstitutablePathInfo info; + bool res = store->querySubstitutablePathInfo(path, info); + stopWork(); + writeInt(res ? 1 : 0, to); + if (res) { + writeString(info.deriver, to); + writeStringSet(info.references, to); + writeLongLong(info.downloadSize, to); + } + break; + } default: throw Error(format("invalid operation %1%") % op); @@ -440,7 +454,7 @@ static void performOp(unsigned int clientVersion, static void processConnection() { - RemoveTempRoots removeTempRoots; /* unused variable - don't remove */ + RemoveTempRoots removeTempRoots __attribute__((unused)); canSendStderr = false; myPid = getpid();