2003-07-14 10:23:11 +00:00
|
|
|
#ifndef __FSTATE_H
|
|
|
|
#define __FSTATE_H
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2003-07-09 15:02:03 +00:00
|
|
|
#include <set>
|
|
|
|
|
2003-06-16 13:33:38 +00:00
|
|
|
extern "C" {
|
|
|
|
#include <aterm2.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "hash.hh"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
2003-06-27 13:55:12 +00:00
|
|
|
/* \section{Abstract syntax of Nix file system state expressions}
|
2003-06-25 15:50:37 +00:00
|
|
|
|
2003-06-27 13:55:12 +00:00
|
|
|
A Nix file system state expression, or FState, describes a
|
|
|
|
(partial) state of the file system.
|
2003-06-25 15:50:37 +00:00
|
|
|
|
2003-07-06 14:20:47 +00:00
|
|
|
Path : Path * Content * [FState] -> FState
|
2003-06-25 15:50:37 +00:00
|
|
|
|
2003-07-06 14:20:47 +00:00
|
|
|
Path(path, content, refs) specifies a file object (its full path
|
2003-06-25 15:50:37 +00:00
|
|
|
and contents), along with all file objects referenced by it (that
|
|
|
|
is, that it has pointers to). We assume that all files are
|
|
|
|
self-referential. This prevents us from having to deal with
|
|
|
|
cycles.
|
|
|
|
|
2003-06-27 14:56:12 +00:00
|
|
|
Derive : String * Path * [FState] * Path * [(String, String)] -> FState
|
2003-06-25 15:50:37 +00:00
|
|
|
|
2003-06-27 09:55:31 +00:00
|
|
|
Derive(platform, builder, ins, outs, env) specifies the creation of
|
|
|
|
new file objects (in paths declared by `outs') by the execution of
|
|
|
|
a program `builder' on a platform `platform'. This execution takes
|
|
|
|
place in a file system state given by `ins'. `env' specifies a
|
|
|
|
mapping of strings to strings.
|
2003-06-25 15:50:37 +00:00
|
|
|
|
2003-06-27 09:55:31 +00:00
|
|
|
[ !!! NOT IMPLEMENTED
|
|
|
|
Regular : String -> Content
|
|
|
|
Directory : [(String, Content)] -> Content
|
|
|
|
(this complicates unambiguous normalisation)
|
|
|
|
]
|
|
|
|
CHash : Hash -> Content
|
2003-06-25 15:50:37 +00:00
|
|
|
|
2003-06-27 09:55:31 +00:00
|
|
|
File content, given either in situ, or through an external reference
|
2003-06-27 13:55:12 +00:00
|
|
|
to the file system or url-space decorated with a hash to preserve
|
|
|
|
purity.
|
|
|
|
|
|
|
|
A FState expression is in {\em $f$-normal form} if all Derive nodes
|
|
|
|
have been reduced to File nodes.
|
2003-06-25 15:50:37 +00:00
|
|
|
|
2003-06-27 09:55:31 +00:00
|
|
|
DISCUSSION: the idea is that a Regular/Directory is interchangeable
|
|
|
|
with its CHash. This would appear to break referential
|
|
|
|
transparency, e.g., Derive(..., ..., [...CHash(h)...], ...) can
|
|
|
|
only be reduced in a context were the Regular/Directory equivalent
|
|
|
|
of Hash(h) is known. However, CHash should be viewed strictly as a
|
|
|
|
shorthand; that is, when we export an expression containing a
|
|
|
|
CHash, we should also export the file object referenced by that
|
|
|
|
CHash.
|
2003-06-25 15:50:37 +00:00
|
|
|
|
2003-06-16 13:33:38 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-27 13:55:12 +00:00
|
|
|
typedef ATerm FState;
|
2003-06-27 09:55:31 +00:00
|
|
|
typedef ATerm Content;
|
|
|
|
|
2003-07-09 15:02:03 +00:00
|
|
|
typedef set<string> StringSet;
|
|
|
|
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2003-07-08 13:22:08 +00:00
|
|
|
/* Realise an fstate expression in the file system. This requires
|
|
|
|
execution of all Derive() nodes. */
|
2003-07-09 15:02:03 +00:00
|
|
|
FState realiseFState(FState fs, StringSet & paths);
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2003-07-08 13:22:08 +00:00
|
|
|
/* Return the path of an fstate expression. An empty string is
|
|
|
|
returned if the term is not a valid fstate expression. (!!!) */
|
|
|
|
string fstatePath(FState fs);
|
|
|
|
|
|
|
|
/* Return the paths referenced by fstate expression. */
|
2003-07-09 15:02:03 +00:00
|
|
|
void fstateRefs(FState fs, StringSet & paths);
|
2003-07-08 13:22:08 +00:00
|
|
|
|
2003-06-17 13:37:44 +00:00
|
|
|
/* Return a canonical textual representation of an expression. */
|
2003-06-27 13:55:12 +00:00
|
|
|
string printTerm(ATerm t);
|
2003-06-18 12:36:12 +00:00
|
|
|
|
2003-07-06 14:20:47 +00:00
|
|
|
/* Throw an exception with an error message containing the given
|
|
|
|
aterm. */
|
|
|
|
Error badTerm(const format & f, ATerm t);
|
|
|
|
|
2003-06-27 13:55:12 +00:00
|
|
|
/* Hash an aterm. */
|
|
|
|
Hash hashTerm(ATerm t);
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2003-07-10 15:11:48 +00:00
|
|
|
FState hash2fstate(Hash hash);
|
|
|
|
|
2003-07-08 13:22:08 +00:00
|
|
|
/* Read an aterm from disk, given its hash. */
|
2003-07-09 15:02:03 +00:00
|
|
|
ATerm termFromHash(const Hash & hash, string * p = 0);
|
2003-07-08 13:22:08 +00:00
|
|
|
|
2003-07-06 14:20:47 +00:00
|
|
|
/* Write an aterm to the Nix store directory, and return its hash. */
|
2003-07-09 15:02:03 +00:00
|
|
|
Hash writeTerm(ATerm t, const string & suffix, string * p = 0);
|
2003-07-06 14:20:47 +00:00
|
|
|
|
2003-07-10 18:48:11 +00:00
|
|
|
/* Register a successor. */
|
|
|
|
void registerSuccessor(const Hash & fsHash, const Hash & scHash);
|
|
|
|
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2003-07-14 10:23:11 +00:00
|
|
|
#endif /* !__FSTATE_H */
|