* Put building in the store API.

This commit is contained in:
Eelco Dolstra 2006-11-30 18:02:04 +00:00
parent e2ef5e07fd
commit 6ecb840fd1
11 changed files with 31 additions and 48 deletions

View file

@ -1,4 +1,3 @@
#include "build.hh"
#include "misc.hh"
#include "eval.hh"
#include "globals.hh"
@ -50,7 +49,7 @@ static Expr primImport(EvalState & state, const ATermVector & args)
throw EvalError(format("cannot import `%1%', since path `%2%' is not valid")
% path % *i);
if (isDerivation(*i))
buildDerivations(singleton<PathSet>(*i));
store->buildDerivations(singleton<PathSet>(*i));
}
return evalFile(state, path);

View file

@ -5,7 +5,7 @@ libstore_la_SOURCES = \
db.cc references.cc pathlocks.cc gc.cc
pkginclude_HEADERS = \
store-api.hh local-store.cc derivations.hh build.hh misc.hh globals.hh \
store-api.hh local-store.cc derivations.hh misc.hh globals.hh \
db.hh references.hh pathlocks.hh gc.hh
libstore_la_LIBADD = ../libutil/libutil.la ../boost/format/libformat.la

View file

@ -1,4 +1,3 @@
#include "build.hh"
#include "references.hh"
#include "pathlocks.hh"
#include "misc.hh"
@ -2195,7 +2194,7 @@ void Worker::waitForInput()
//////////////////////////////////////////////////////////////////////
void buildDerivations(const PathSet & drvPaths)
void LocalStore::buildDerivations(const PathSet & drvPaths)
{
startNest(nest, lvlDebug,
format("building %1%") % showPaths(drvPaths));
@ -2222,7 +2221,7 @@ void buildDerivations(const PathSet & drvPaths)
}
void ensurePath(const Path & path)
void LocalStore::ensurePath(const Path & path)
{
/* If the path is already valid, we're done. */
if (store->isValidPath(path)) return;

View file

@ -1,30 +0,0 @@
#ifndef __BUILD_H
#define __BUILD_H
#include "types.hh"
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
substitutes, then those can be used. Second, the output paths can
be created by running the builder, after recursively building any
sub-derivations. */
void buildDerivations(const PathSet & drvPaths);
/* Ensure that a path is valid. If it is not currently valid, it may
be made valid by running a substitute (if defined for the path). */
void ensurePath(const Path & storePath);
}
#endif /* !__BUILD_H */

View file

@ -33,7 +33,6 @@ extern string nixConfDir;
extern string nixLibexecDir;
/* Misc. global flags. */
/* Whether to keep temporary directories of failed builds. */

View file

@ -18,6 +18,9 @@ class Transaction;
const int nixSchemaVersion = 3;
extern string drvsLogDir;
class LocalStore : public StoreAPI
{
public:
@ -56,6 +59,10 @@ public:
Path addTextToStore(const string & suffix, const string & s,
const PathSet & references);
void buildDerivations(const PathSet & drvPaths);
void ensurePath(const Path & storePath);
private:
Path _addToStore(bool fixed, bool recursive,
string hashAlgo, const Path & _srcPath);

View file

@ -1,6 +1,5 @@
#include "misc.hh"
#include "store-api.hh"
#include "build.hh"
#include "db.hh"
#include <aterm2.h>
@ -12,7 +11,7 @@ namespace nix {
Derivation derivationFromPath(const Path & drvPath)
{
assertStorePath(drvPath);
ensurePath(drvPath);
store->ensurePath(drvPath);
ATerm t = ATreadFromNamedFile(drvPath.c_str());
if (!t) throw Error(format("cannot read aterm from `%1%'") % drvPath);
return parseDerivation(t);

View file

@ -72,6 +72,19 @@ public:
a regular file containing the given string. */
virtual Path addTextToStore(const string & suffix, const string & s,
const PathSet & references) = 0;
/* 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
substitutes, then those can be used. Second, the output paths
can be created by running the builder, after recursively
building any sub-derivations. */
virtual void buildDerivations(const PathSet & drvPaths) = 0;
/* Ensure that a path is valid. If it is not currently valid, it
may be made valid by running a substitute (if defined for the
path). */
virtual void ensurePath(const Path & storePath) = 0;
};

View file

@ -1,7 +1,6 @@
#include "profiles.hh"
#include "names.hh"
#include "globals.hh"
#include "build.hh"
#include "misc.hh"
#include "gc.hh"
#include "shared.hh"
@ -152,7 +151,7 @@ static void createUserEnv(EvalState & state, const DrvInfos & elems,
drvsToBuild.insert(i->queryDrvPath(state));
debug(format("building user environment dependencies"));
buildDerivations(drvsToBuild);
store->buildDerivations(drvsToBuild);
/* Get the environment builder expression. */
Expr envBuilder = parseExprFromFile(state,
@ -184,7 +183,7 @@ static void createUserEnv(EvalState & state, const DrvInfos & elems,
/* This is only necessary when installing store paths, e.g.,
`nix-env -i /nix/store/abcd...-foo'. */
addTempRoot(i->queryOutPath(state));
ensurePath(i->queryOutPath(state));
store->ensurePath(i->queryOutPath(state));
references.insert(i->queryOutPath(state));
if (drvPath != "") references.insert(drvPath);
@ -212,7 +211,7 @@ static void createUserEnv(EvalState & state, const DrvInfos & elems,
/* Realise the resulting store expression. */
debug(format("building user environment"));
buildDerivations(singleton<PathSet>(topLevelDrv.queryDrvPath(state)));
store->buildDerivations(singleton<PathSet>(topLevelDrv.queryDrvPath(state)));
/* Switch the current user environment to the output path. */
debug(format("switching to new user environment"));

View file

@ -2,7 +2,6 @@
#include <iostream>
#include "globals.hh"
#include "build.hh"
#include "gc.hh"
#include "shared.hh"
#include "eval.hh"

View file

@ -2,7 +2,6 @@
#include <algorithm>
#include "globals.hh"
#include "build.hh"
#include "misc.hh"
#include "gc.hh"
#include "archive.hh"
@ -64,7 +63,7 @@ static Path realisePath(const Path & path)
if (isDerivation(path)) {
PathSet paths;
paths.insert(path);
buildDerivations(paths);
store->buildDerivations(paths);
Path outPath = findOutput(derivationFromPath(path), "out");
if (gcRoot == "")
@ -76,7 +75,7 @@ static Path realisePath(const Path & path)
return outPath;
} else {
ensurePath(path);
store->ensurePath(path);
return path;
}
}
@ -97,7 +96,7 @@ static void opRealise(Strings opFlags, Strings opArgs)
i != opArgs.end(); ++i)
if (isDerivation(*i))
drvPaths.insert(*i);
buildDerivations(drvPaths);
store->buildDerivations(drvPaths);
}
for (Strings::iterator i = opArgs.begin();