Process Nix API changes

This commit is contained in:
Eelco Dolstra 2016-02-11 15:59:47 +01:00
parent 993647d1e3
commit 92d8b59361
8 changed files with 22 additions and 27 deletions

View file

@ -153,7 +153,7 @@ static void findJobsWrapped(EvalState & state, JSONObject & top,
done. */ done. */
if (gcRootsDir != "") { if (gcRootsDir != "") {
Path root = gcRootsDir + "/" + baseNameOf(drvPath); Path root = gcRootsDir + "/" + baseNameOf(drvPath);
if (!pathExists(root)) addPermRoot(*store, drvPath, root, false); if (!pathExists(root)) state.store->addPermRoot(drvPath, root, false);
} }
res.attr("outputs"); res.attr("outputs");
@ -253,7 +253,7 @@ int main(int argc, char * * argv)
if (gcRootsDir == "") printMsg(lvlError, "warning: `--gc-roots-dir' not specified"); if (gcRootsDir == "") printMsg(lvlError, "warning: `--gc-roots-dir' not specified");
EvalState state(searchPath); EvalState state(searchPath, openStore());
AutoArgs autoArgs; AutoArgs autoArgs;
Value * inputsSet = state.allocValue(); Value * inputsSet = state.allocValue();
@ -280,8 +280,6 @@ int main(int argc, char * * argv)
autoArgs[sInputs].push_back(inputsSet); autoArgs[sInputs].push_back(inputsSet);
} }
store = openStore();
Value v; Value v;
state.evalFile(releaseExpr, v); state.evalFile(releaseExpr, v);

View file

@ -4,7 +4,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "misc.hh"
#include "serve-protocol.hh" #include "serve-protocol.hh"
#include "state.hh" #include "state.hh"
#include "util.hh" #include "util.hh"
@ -74,14 +73,14 @@ static void openConnection(Machine::ptr machine, Path tmpDir, int stderrFD, Chil
} }
static void copyClosureTo(std::shared_ptr<StoreAPI> store, static void copyClosureTo(ref<Store> store,
FdSource & from, FdSink & to, const PathSet & paths, FdSource & from, FdSink & to, const PathSet & paths,
counter & bytesSent, counter & bytesSent,
bool useSubstitutes = false) bool useSubstitutes = false)
{ {
PathSet closure; PathSet closure;
for (auto & path : paths) for (auto & path : paths)
computeFSClosure(*store, path, closure); store->computeFSClosure(path, closure);
/* Send the "query valid paths" command with the "lock" option /* Send the "query valid paths" command with the "lock" option
enabled. This prevents a race where the remote host enabled. This prevents a race where the remote host
@ -96,7 +95,7 @@ static void copyClosureTo(std::shared_ptr<StoreAPI> store,
if (present.size() == closure.size()) return; if (present.size() == closure.size()) return;
Paths sorted = topoSortPaths(*store, closure); Paths sorted = store->topoSortPaths(closure);
Paths missing; Paths missing;
for (auto i = sorted.rbegin(); i != sorted.rend(); ++i) for (auto i = sorted.rbegin(); i != sorted.rend(); ++i)
@ -108,7 +107,7 @@ static void copyClosureTo(std::shared_ptr<StoreAPI> store,
bytesSent += store->queryPathInfo(p).narSize; bytesSent += store->queryPathInfo(p).narSize;
to << cmdImportPaths; to << cmdImportPaths;
exportPaths(*store, missing, false, to); store->exportPaths(missing, false, to);
to.flush(); to.flush();
if (readInt(from) != 1) if (readInt(from) != 1)
@ -116,7 +115,7 @@ static void copyClosureTo(std::shared_ptr<StoreAPI> store,
} }
static void copyClosureFrom(std::shared_ptr<StoreAPI> store, static void copyClosureFrom(ref<Store> store,
FdSource & from, FdSink & to, const PathSet & paths, counter & bytesReceived) FdSource & from, FdSink & to, const PathSet & paths, counter & bytesReceived)
{ {
to << cmdExportPaths << 0 << paths; to << cmdExportPaths << 0 << paths;
@ -128,7 +127,7 @@ static void copyClosureFrom(std::shared_ptr<StoreAPI> store,
} }
void State::buildRemote(std::shared_ptr<StoreAPI> store, void State::buildRemote(ref<Store> store,
Machine::ptr machine, Step::ptr step, Machine::ptr machine, Step::ptr step,
unsigned int maxSilentTime, unsigned int buildTimeout, unsigned int maxSilentTime, unsigned int buildTimeout,
RemoteResult & result) RemoteResult & result)

View file

@ -1,6 +1,5 @@
#include "build-result.hh" #include "build-result.hh"
#include "store-api.hh" #include "store-api.hh"
#include "misc.hh"
#include "util.hh" #include "util.hh"
#include "regex.hh" #include "regex.hh"
@ -22,7 +21,7 @@ static std::tuple<bool, string> secureRead(Path fileName)
} }
BuildOutput getBuildOutput(std::shared_ptr<StoreAPI> store, const Derivation & drv) BuildOutput getBuildOutput(nix::ref<Store> store, const Derivation & drv)
{ {
BuildOutput res; BuildOutput res;
@ -32,7 +31,7 @@ BuildOutput getBuildOutput(std::shared_ptr<StoreAPI> store, const Derivation & d
outputs.insert(output.second.path); outputs.insert(output.second.path);
PathSet closure; PathSet closure;
for (auto & output : outputs) for (auto & output : outputs)
computeFSClosure(*store, output, closure); store->computeFSClosure(output, closure);
for (auto & path : closure) { for (auto & path : closure) {
auto info = store->queryPathInfo(path); auto info = store->queryPathInfo(path);
res.closureSize += info.narSize; res.closureSize += info.narSize;

View file

@ -37,4 +37,4 @@ struct BuildOutput
std::map<std::string, BuildMetric> metrics; std::map<std::string, BuildMetric> metrics;
}; };
BuildOutput getBuildOutput(std::shared_ptr<nix::StoreAPI> store, const nix::Derivation & drv); BuildOutput getBuildOutput(nix::ref<nix::Store> store, const nix::Derivation & drv);

View file

@ -45,7 +45,7 @@ void State::builder(MachineReservation::ptr reservation)
} }
bool State::doBuildStep(std::shared_ptr<StoreAPI> store, Step::ptr step, bool State::doBuildStep(nix::ref<Store> store, Step::ptr step,
Machine::ptr machine) Machine::ptr machine)
{ {
{ {
@ -354,7 +354,7 @@ bool State::doBuildStep(std::shared_ptr<StoreAPI> store, Step::ptr step,
/* Remember failed paths in the database so that they /* Remember failed paths in the database so that they
won't be built again. */ won't be built again. */
if (!cachedFailure && result.status == BuildResult::PermanentFailure) if (!cachedFailure && result.status == BuildResult::PermanentFailure)
for (auto & path : outputPaths(step->drv)) for (auto & path : step->drv.outputPaths())
txn.parameterized("insert into FailedPaths values ($1)")(path).exec(); txn.parameterized("insert into FailedPaths values ($1)")(path).exec();
txn.commit(); txn.commit();

View file

@ -359,7 +359,7 @@ void State::markSucceededBuild(pqxx::work & txn, Build::ptr build,
bool State::checkCachedFailure(Step::ptr step, Connection & conn) bool State::checkCachedFailure(Step::ptr step, Connection & conn)
{ {
pqxx::work txn(conn); pqxx::work txn(conn);
for (auto & path : outputPaths(step->drv)) for (auto & path : step->drv.outputPaths())
if (!txn.parameterized("select 1 from FailedPaths where path = $1")(path).exec().empty()) if (!txn.parameterized("select 1 from FailedPaths where path = $1")(path).exec().empty())
return true; return true;
return false; return false;

View file

@ -1,7 +1,6 @@
#include "state.hh" #include "state.hh"
#include "build-result.hh" #include "build-result.hh"
#include "globals.hh" #include "globals.hh"
#include "misc.hh"
using namespace nix; using namespace nix;
@ -64,7 +63,7 @@ void State::queueMonitorLoop()
} }
bool State::getQueuedBuilds(Connection & conn, std::shared_ptr<StoreAPI> store, unsigned int & lastBuildId) bool State::getQueuedBuilds(Connection & conn, ref<Store> store, unsigned int & lastBuildId)
{ {
printMsg(lvlInfo, format("checking the queue for builds > %1%...") % lastBuildId); printMsg(lvlInfo, format("checking the queue for builds > %1%...") % lastBuildId);
@ -315,7 +314,7 @@ void State::processQueueChange(Connection & conn)
} }
Step::ptr State::createStep(std::shared_ptr<StoreAPI> store, Step::ptr State::createStep(ref<Store> store,
Connection & conn, Build::ptr build, const Path & drvPath, Connection & conn, Build::ptr build, const Path & drvPath,
Build::ptr referringBuild, Step::ptr referringStep, std::set<Path> & finishedDrvs, Build::ptr referringBuild, Step::ptr referringStep, std::set<Path> & finishedDrvs,
std::set<Step::ptr> & newSteps, std::set<Step::ptr> & newRunnable) std::set<Step::ptr> & newSteps, std::set<Step::ptr> & newRunnable)
@ -373,7 +372,7 @@ Step::ptr State::createStep(std::shared_ptr<StoreAPI> store,
runnable while step->created == false. */ runnable while step->created == false. */
step->drv = readDerivation(drvPath); step->drv = readDerivation(drvPath);
step->preferLocalBuild = willBuildLocally(step->drv); step->preferLocalBuild = step->drv.willBuildLocally();
step->systemType = step->drv.platform; step->systemType = step->drv.platform;
{ {
@ -391,7 +390,7 @@ Step::ptr State::createStep(std::shared_ptr<StoreAPI> store,
/* Are all outputs valid? */ /* Are all outputs valid? */
bool valid = true; bool valid = true;
PathSet outputs = outputPaths(step->drv); PathSet outputs = step->drv.outputPaths();
DerivationOutputs missing; DerivationOutputs missing;
PathSet missingPaths; PathSet missingPaths;
for (auto & i : step->drv.outputs) for (auto & i : step->drv.outputs)

View file

@ -377,12 +377,12 @@ private:
void queueMonitorLoop(); void queueMonitorLoop();
/* Check the queue for new builds. */ /* Check the queue for new builds. */
bool getQueuedBuilds(Connection & conn, std::shared_ptr<nix::StoreAPI> store, unsigned int & lastBuildId); bool getQueuedBuilds(Connection & conn, nix::ref<nix::Store> store, unsigned int & lastBuildId);
/* Handle cancellation, deletion and priority bumps. */ /* Handle cancellation, deletion and priority bumps. */
void processQueueChange(Connection & conn); void processQueueChange(Connection & conn);
Step::ptr createStep(std::shared_ptr<nix::StoreAPI> store, Step::ptr createStep(nix::ref<nix::Store> store,
Connection & conn, Build::ptr build, const nix::Path & drvPath, Connection & conn, Build::ptr build, const nix::Path & drvPath,
Build::ptr referringBuild, Step::ptr referringStep, std::set<nix::Path> & finishedDrvs, Build::ptr referringBuild, Step::ptr referringStep, std::set<nix::Path> & finishedDrvs,
std::set<Step::ptr> & newSteps, std::set<Step::ptr> & newRunnable); std::set<Step::ptr> & newSteps, std::set<Step::ptr> & newRunnable);
@ -405,10 +405,10 @@ private:
/* Perform the given build step. Return true if the step is to be /* Perform the given build step. Return true if the step is to be
retried. */ retried. */
bool doBuildStep(std::shared_ptr<nix::StoreAPI> store, Step::ptr step, bool doBuildStep(nix::ref<nix::Store> store, Step::ptr step,
Machine::ptr machine); Machine::ptr machine);
void buildRemote(std::shared_ptr<nix::StoreAPI> store, void buildRemote(nix::ref<nix::Store> store,
Machine::ptr machine, Step::ptr step, Machine::ptr machine, Step::ptr step,
unsigned int maxSilentTime, unsigned int buildTimeout, unsigned int maxSilentTime, unsigned int buildTimeout,
RemoteResult & result); RemoteResult & result);