* Use a proper namespace.

* Optimise header file usage a bit.
* Compile the parser as C++.
This commit is contained in:
Eelco Dolstra 2006-09-04 21:06:23 +00:00
parent aab8812732
commit 75068e7d75
61 changed files with 650 additions and 268 deletions

View file

@ -1,3 +1,13 @@
#include "build.hh"
#include "references.hh"
#include "pathlocks.hh"
#include "misc.hh"
#include "globals.hh"
#include "gc.hh"
#include "store.hh"
#include "db.hh"
#include "util.hh"
#include <map>
#include <iostream>
#include <sstream>
@ -15,13 +25,11 @@
#include <pwd.h>
#include <grp.h>
#include "build.hh"
#include "references.hh"
#include "pathlocks.hh"
#include "misc.hh"
#include "globals.hh"
#include "gc.hh"
namespace nix {
using std::map;
/* !!! TODO derivationFromPath shouldn't be used here */
@ -38,8 +46,8 @@ class Worker;
/* A pointer to a goal. */
class Goal;
typedef shared_ptr<Goal> GoalPtr;
typedef weak_ptr<Goal> WeakGoalPtr;
typedef boost::shared_ptr<Goal> GoalPtr;
typedef boost::weak_ptr<Goal> WeakGoalPtr;
/* Set of goals. */
typedef set<GoalPtr> Goals;
@ -50,7 +58,7 @@ typedef map<Path, WeakGoalPtr> WeakGoalMap;
class Goal : public enable_shared_from_this<Goal>
class Goal : public boost::enable_shared_from_this<Goal>
{
public:
typedef enum {ecBusy, ecSuccess, ecFailed} ExitCode;
@ -447,8 +455,8 @@ static void killUser(uid_t uid)
if (kill(-1, SIGKILL) == -1)
throw SysError(format("cannot kill processes for UID `%1%'") % uid);
} catch (exception & e) {
cerr << format("build error: %1%\n") % e.what();
} catch (std::exception & e) {
std::cerr << format("build error: %1%\n") % e.what();
quickExit(1);
}
quickExit(0);
@ -930,8 +938,8 @@ DerivationGoal::HookReply DerivationGoal::tryBuildHook()
throw SysError(format("executing `%1%'") % buildHook);
} catch (exception & e) {
cerr << format("build error: %1%\n") % e.what();
} catch (std::exception & e) {
std::cerr << format("build error: %1%\n") % e.what();
}
quickExit(1);
}
@ -1326,8 +1334,8 @@ void DerivationGoal::startBuilder()
throw SysError(format("executing `%1%'")
% drv.builder);
} catch (exception & e) {
cerr << format("build error: %1%\n") % e.what();
} catch (std::exception & e) {
std::cerr << format("build error: %1%\n") % e.what();
}
quickExit(1);
}
@ -1593,7 +1601,7 @@ private:
Pid pid;
/* Lock on the store path. */
shared_ptr<PathLocks> outputLock;
boost::shared_ptr<PathLocks> outputLock;
typedef void (SubstitutionGoal::*GoalState)();
GoalState state;
@ -1719,7 +1727,7 @@ void SubstitutionGoal::tryToRun()
}
/* Acquire a lock on the output path. */
outputLock = shared_ptr<PathLocks>(new PathLocks);
outputLock = boost::shared_ptr<PathLocks>(new PathLocks);
outputLock->lockPaths(singleton<PathSet>(storePath),
(format("waiting for lock on `%1%'") % storePath).str());
@ -1767,8 +1775,8 @@ void SubstitutionGoal::tryToRun()
throw SysError(format("executing `%1%'") % sub.program);
} catch (exception & e) {
cerr << format("substitute error: %1%\n") % e.what();
} catch (std::exception & e) {
std::cerr << format("substitute error: %1%\n") % e.what();
}
quickExit(1);
}
@ -1930,8 +1938,8 @@ static void removeGoal(GoalPtr goal, WeakGoalMap & goalMap)
void Worker::removeGoal(GoalPtr goal)
{
::removeGoal(goal, derivationGoals);
::removeGoal(goal, substitutionGoals);
nix::removeGoal(goal, derivationGoals);
nix::removeGoal(goal, substitutionGoals);
if (topGoals.find(goal) != topGoals.end()) {
topGoals.erase(goal);
/* If a top-level goal failed, then kill all other goals
@ -2160,3 +2168,6 @@ void ensurePath(const Path & path)
if (goal->getExitCode() != Goal::ecSuccess)
throw Error(format("path `%1%' does not exist and cannot be created") % path);
}
}

View file

@ -1,8 +1,13 @@
#ifndef __BUILD_H
#define __BUILD_H
#include "derivations.hh"
#include "types.hh"
namespace nix {
/* 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
@ -16,5 +21,7 @@ void buildDerivations(const PathSet & drvPaths);
void ensurePath(const Path & storePath);
}
#endif /* !__BUILD_H */

View file

@ -1,3 +1,7 @@
#include "db.hh"
#include "util.hh"
#include "pathlocks.hh"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@ -7,9 +11,8 @@
#include <db_cxx.h>
#include "db.hh"
#include "util.hh"
#include "pathlocks.hh"
namespace nix {
/* Wrapper class to ensure proper destruction. */
@ -112,7 +115,7 @@ Db * Database::getDb(TableId table)
if (table == 0)
throw Error("database table is not open "
"(maybe you don't have sufficient permission?)");
map<TableId, Db *>::iterator i = tables.find(table);
std::map<TableId, Db *>::iterator i = tables.find(table);
if (i == tables.end())
throw Error("unknown table id");
return i->second;
@ -263,10 +266,10 @@ void Database::close()
try {
for (map<TableId, Db *>::iterator i = tables.begin();
for (std::map<TableId, Db *>::iterator i = tables.begin();
i != tables.end(); )
{
map<TableId, Db *>::iterator j = i;
std::map<TableId, Db *>::iterator j = i;
++j;
closeTable(i->first);
i = j;
@ -433,3 +436,6 @@ void Database::enumTable(const Transaction & txn, TableId table,
} catch (DbException e) { rethrow(e); }
}
}

View file

@ -1,14 +1,10 @@
#ifndef __DB_H
#define __DB_H
#include <string>
#include <list>
#include "types.hh"
#include <map>
#include "util.hh"
using namespace std;
/* Defined externally. */
class DbTxn;
@ -16,6 +12,9 @@ class DbEnv;
class Db;
namespace nix {
class Database;
@ -53,7 +52,7 @@ private:
DbEnv * env;
TableId nextId;
map<TableId, Db *> tables;
std::map<TableId, Db *> tables;
void requireEnv();
@ -99,5 +98,8 @@ public:
DbNoPermission(const format & f) : Error(f) { };
};
}
#endif /* !__DB_H */

View file

@ -1,11 +1,13 @@
#include "derivations.hh"
#include "globals.hh"
#include "store.hh"
#include "derivations-ast.hh"
#include "derivations-ast.cc"
namespace nix {
Hash hashTerm(ATerm t)
{
return hashString(htSHA256, atPrint(t));
@ -170,3 +172,6 @@ bool isDerivation(const string & fileName)
fileName.size() >= drvExtension.size() &&
string(fileName, fileName.size() - drvExtension.size()) == drvExtension;
}
}

View file

@ -2,7 +2,12 @@
#define __DERIVATIONS_H
#include "aterm.hh"
#include "store.hh"
#include "hash.hh"
#include <map>
namespace nix {
/* Extension of derivations in the Nix store. */
@ -27,13 +32,13 @@ struct DerivationOutput
}
};
typedef map<string, DerivationOutput> DerivationOutputs;
typedef std::map<string, DerivationOutput> DerivationOutputs;
/* For inputs that are sub-derivations, we specify exactly which
output IDs we are interested in. */
typedef map<Path, StringSet> DerivationInputs;
typedef std::map<Path, StringSet> DerivationInputs;
typedef map<string, string> StringPairs;
typedef std::map<string, string> StringPairs;
struct Derivation
{
@ -63,5 +68,8 @@ ATerm unparseDerivation(const Derivation & drv);
derivations. */
bool isDerivation(const string & fileName);
}
#endif /* !__DERIVATIONS_H */

View file

@ -1,7 +1,10 @@
#include "globals.hh"
#include "gc.hh"
#include "globals.hh"
#include "misc.hh"
#include "pathlocks.hh"
#include "store.hh"
#include "db.hh"
#include "util.hh"
#include <boost/shared_ptr.hpp>
@ -17,6 +20,9 @@
#endif
namespace nix {
static string gcLockName = "gc.lock";
static string tempRootsDir = "temproots";
static string gcRootsDir = "gcroots";
@ -192,7 +198,7 @@ void removeTempRoots()
}
typedef shared_ptr<AutoCloseFD> FDPtr;
typedef boost::shared_ptr<AutoCloseFD> FDPtr;
typedef list<FDPtr> FDs;
@ -558,3 +564,6 @@ void collectGarbage(GCAction action, const PathSet & pathsToDelete,
}
}
}
}

View file

@ -1,7 +1,10 @@
#ifndef __GC_H
#define __GC_H
#include "util.hh"
#include "types.hh"
namespace nix {
/* Garbage collector operation. */
@ -39,4 +42,7 @@ Path addPermRoot(const Path & storePath, const Path & gcRoot,
bool indirect);
}
#endif /* !__GC_H */

View file

@ -1,9 +1,13 @@
#include "globals.hh"
#include "util.hh"
#include <map>
#include <algorithm>
namespace nix {
string nixStore = "/UNINIT";
string nixDataDir = "/UNINIT";
string nixLogDir = "/UNINIT";
@ -23,7 +27,7 @@ string thisSystem = "unset";
static bool settingsRead = false;
static map<string, Strings> settings;
static std::map<string, Strings> settings;
string & at(Strings & ss, unsigned int n)
@ -72,7 +76,7 @@ static void readSettings()
Strings querySetting(const string & name, const Strings & def)
{
if (!settingsRead) readSettings();
map<string, Strings>::iterator i = settings.find(name);
std::map<string, Strings>::iterator i = settings.find(name);
return i == settings.end() ? def : i->second;
}
@ -98,3 +102,6 @@ bool queryBoolSetting(const string & name, bool def)
else throw Error(format("configuration option `%1%' should be either `true' or `false', not `%2%'")
% name % v);
}
}

View file

@ -1,11 +1,11 @@
#ifndef __GLOBALS_H
#define __GLOBALS_H
#include <string>
#include <set>
#include "util.hh"
#include "types.hh"
namespace nix {
using namespace std;
/* Path names. */
@ -67,5 +67,8 @@ string querySetting(const string & name, const string & def);
bool queryBoolSetting(const string & name, bool def);
}
#endif /* !__GLOBALS_H */

View file

@ -1,4 +1,10 @@
#include "misc.hh"
#include "store.hh"
#include "build.hh"
#include "db.hh"
namespace nix {
Derivation derivationFromPath(const Path & drvPath)
@ -81,3 +87,6 @@ void queryMissing(const PathSet & targets,
}
}
}
}

View file

@ -4,6 +4,9 @@
#include "derivations.hh"
namespace nix {
/* Read a derivation, after ensuring its existence through
ensurePath(). */
Derivation derivationFromPath(const Path & drvPath);
@ -29,4 +32,7 @@ void queryMissing(const PathSet & targets,
PathSet & willBuild, PathSet & willSubstitute);
}
#endif /* !__MISC_H */

View file

@ -1,17 +1,21 @@
#include "pathlocks.hh"
#include "util.hh"
#include <cerrno>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "pathlocks.hh"
#ifdef __CYGWIN__
#include <windows.h>
#include <sys/cygwin.h>
#endif
namespace nix {
int openLockFile(const Path & path, bool create)
{
AutoCloseFD fd;
@ -220,3 +224,6 @@ void PathLocks::setDeletion(bool deletePaths)
{
this->deletePaths = deletePaths;
}
}

View file

@ -1,7 +1,10 @@
#ifndef __PATHLOCKS_H
#define __PATHLOCKS_H
#include "util.hh"
#include "types.hh"
namespace nix {
/* Open (possibly create) a lock file and return the file descriptor.
@ -22,7 +25,7 @@ bool lockFile(int fd, LockType lockType, bool wait);
class PathLocks
{
private:
typedef pair<int, Path> FDPair;
typedef std::pair<int, Path> FDPair;
list<FDPair> fds;
bool deletePaths;
@ -37,4 +40,7 @@ public:
};
}
#endif /* !__PATHLOCKS_H */

View file

@ -1,3 +1,7 @@
#include "references.hh"
#include "hash.hh"
#include "util.hh"
#include <cerrno>
#include <map>
@ -7,8 +11,8 @@
#include <dirent.h>
#include <fcntl.h>
#include "references.hh"
#include "hash.hh"
namespace nix {
static unsigned int refLength = 32; /* characters */
@ -90,7 +94,7 @@ void checkPath(const string & path,
PathSet scanForReferences(const string & path, const PathSet & paths)
{
map<string, Path> backMap;
std::map<string, Path> backMap;
StringSet ids;
StringSet seen;
@ -114,10 +118,13 @@ PathSet scanForReferences(const string & path, const PathSet & paths)
PathSet found;
for (StringSet::iterator i = seen.begin(); i != seen.end(); i++) {
map<string, Path>::iterator j;
std::map<string, Path>::iterator j;
if ((j = backMap.find(*i)) == backMap.end()) abort();
found.insert(j->second);
}
return found;
}
}

View file

@ -1,10 +1,12 @@
#ifndef __REFERENCES_H
#define __REFERENCES_H
#include "util.hh"
#include "types.hh"
namespace nix {
PathSet scanForReferences(const Path & path, const PathSet & refs);
}
#endif /* !__REFERENCES_H */

View file

@ -1,3 +1,13 @@
#include "store.hh"
#include "util.hh"
#include "globals.hh"
#include "db.hh"
#include "archive.hh"
#include "pathlocks.hh"
#include "gc.hh"
#include "aterm.hh"
#include "derivations-ast.hh"
#include <iostream>
#include <algorithm>
@ -6,14 +16,9 @@
#include <unistd.h>
#include <utime.h>
#include "store.hh"
#include "globals.hh"
#include "db.hh"
#include "archive.hh"
#include "pathlocks.hh"
#include "gc.hh"
namespace nix {
/* Nix database. */
static Database nixDB;
@ -956,10 +961,6 @@ void verifyStore(bool checkContents)
}
#include "aterm.hh"
#include "derivations-ast.hh"
/* Upgrade from schema 1 (Nix <= 0.7) to schema 2 (Nix >= 0.8). */
static void upgradeStore07()
{
@ -971,7 +972,7 @@ static void upgradeStore07()
nixDB.enumTable(txn, dbValidPaths, validPaths2);
PathSet validPaths(validPaths2.begin(), validPaths2.end());
cerr << "hashing paths...";
std::cerr << "hashing paths...";
int n = 0;
for (PathSet::iterator i = validPaths.begin(); i != validPaths.end(); ++i) {
checkInterrupt();
@ -980,20 +981,20 @@ static void upgradeStore07()
if (s == "") {
Hash hash = hashPath(htSHA256, *i);
setHash(txn, *i, hash);
cerr << ".";
std::cerr << ".";
if (++n % 1000 == 0) {
txn.commit();
txn.begin(nixDB);
}
}
}
cerr << "\n";
std::cerr << std::endl;
txn.commit();
txn.begin(nixDB);
cerr << "processing closures...";
std::cerr << "processing closures...";
for (PathSet::iterator i = validPaths.begin(); i != validPaths.end(); ++i) {
checkInterrupt();
if (i->size() > 6 && string(*i, i->size() - 6) == ".store") {
@ -1037,10 +1038,10 @@ static void upgradeStore07()
setReferences(txn, path, references);
}
cerr << ".";
std::cerr << ".";
}
}
cerr << "\n";
std::cerr << std::endl;
/* !!! maybe this transaction is way too big */
txn.commit();
@ -1061,7 +1062,7 @@ static void upgradeStore09()
Transaction txn(nixDB);
cerr << "converting referers to referrers...";
std::cerr << "converting referers to referrers...";
TableId dbReferers = nixDB.openTable("referers"); /* sic! */
@ -1080,16 +1081,19 @@ static void upgradeStore09()
if (++n % 1000 == 0) {
txn.commit();
txn.begin(nixDB);
cerr << "|";
std::cerr << "|";
}
cerr << ".";
std::cerr << ".";
}
txn.commit();
cerr << "\n";
std::cerr << std::endl;
nixDB.closeTable(dbReferers);
nixDB.deleteTable("referers");
}
}

View file

@ -4,9 +4,12 @@
#include <string>
#include "hash.hh"
#include "db.hh"
using namespace std;
namespace nix {
class Transaction;
/* Nix store and database schema version. Version 1 (or 0) was Nix <=
@ -168,5 +171,8 @@ void deleteFromStore(const Path & path, unsigned long long & bytesFreed);
void verifyStore(bool checkContents);
}
#endif /* !__STORE_H */