From 6ecb840fd118019f879de60007e13321b7c080d3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 30 Nov 2006 18:02:04 +0000 Subject: * Put building in the store API. --- src/libexpr/primops.cc | 3 +-- src/libstore/Makefile.am | 2 +- src/libstore/build.cc | 5 ++--- src/libstore/build.hh | 30 ------------------------------ src/libstore/globals.hh | 1 - src/libstore/local-store.hh | 7 +++++++ src/libstore/misc.cc | 3 +-- src/libstore/store-api.hh | 13 +++++++++++++ src/nix-env/main.cc | 7 +++---- src/nix-instantiate/main.cc | 1 - src/nix-store/main.cc | 7 +++---- 11 files changed, 31 insertions(+), 48 deletions(-) delete mode 100644 src/libstore/build.hh diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index d4de6027e404..17a04bc83390 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -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(*i)); + store->buildDerivations(singleton(*i)); } return evalFile(state, path); diff --git a/src/libstore/Makefile.am b/src/libstore/Makefile.am index 209a1e69291c..4d25c2d68961 100644 --- a/src/libstore/Makefile.am +++ b/src/libstore/Makefile.am @@ -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 diff --git a/src/libstore/build.cc b/src/libstore/build.cc index a78d5010cb66..54c48cf91fc7 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -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; diff --git a/src/libstore/build.hh b/src/libstore/build.hh deleted file mode 100644 index 71895c0a9c32..000000000000 --- a/src/libstore/build.hh +++ /dev/null @@ -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 */ diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh index 9441dc344a73..b93f5d62c1ef 100644 --- a/src/libstore/globals.hh +++ b/src/libstore/globals.hh @@ -33,7 +33,6 @@ extern string nixConfDir; extern string nixLibexecDir; - /* Misc. global flags. */ /* Whether to keep temporary directories of failed builds. */ diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 2fd45cd7a521..e41e4368397f 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -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); diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc index b442bd4c2157..6849e2c1a64c 100644 --- a/src/libstore/misc.cc +++ b/src/libstore/misc.cc @@ -1,6 +1,5 @@ #include "misc.hh" #include "store-api.hh" -#include "build.hh" #include "db.hh" #include @@ -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); diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 91beba50f7d2..abf27a346f31 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -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; }; diff --git a/src/nix-env/main.cc b/src/nix-env/main.cc index 997c45da3073..ce0bef069708 100644 --- a/src/nix-env/main.cc +++ b/src/nix-env/main.cc @@ -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(topLevelDrv.queryDrvPath(state))); + store->buildDerivations(singleton(topLevelDrv.queryDrvPath(state))); /* Switch the current user environment to the output path. */ debug(format("switching to new user environment")); diff --git a/src/nix-instantiate/main.cc b/src/nix-instantiate/main.cc index 144b13d2bca6..71f0a44e2791 100644 --- a/src/nix-instantiate/main.cc +++ b/src/nix-instantiate/main.cc @@ -2,7 +2,6 @@ #include #include "globals.hh" -#include "build.hh" #include "gc.hh" #include "shared.hh" #include "eval.hh" diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc index 273fa3e7457e..f31814881f71 100644 --- a/src/nix-store/main.cc +++ b/src/nix-store/main.cc @@ -2,7 +2,6 @@ #include #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(); -- cgit 1.4.1