1#include <stdint.h> /* for uint64_t */
2
3/* set in the tv_nsec field of a node's mtime */
4enum {
5 /* we haven't stat the file yet */
6 MTIME_UNKNOWN = -1,
7 /* the file does not exist */
8 MTIME_MISSING = -2,
9};
10
11struct node {
12 /* shellpath is the escaped shell path, and is populated as needed by nodepath */
13 struct string *path, *shellpath;
14
15 /* modification time of file (in nanoseconds) and build log entry (in seconds) */
16 int64_t mtime, logmtime;
17
18 /* generating edge and dependent edges */
19 struct edge *gen, **use;
20 size_t nuse;
21
22 /* command hash used to build this output, read from build log */
23 uint64_t hash;
24
25 /* ID for .ninja_deps. -1 if not present in log. */
26 int32_t id;
27
28 /* does the node need to be rebuilt */
29 _Bool dirty;
30};
31
32/* build rule, i.e., edge between inputs and outputs */
33struct edge {
34 struct rule *rule;
35 struct pool *pool;
36 struct environment *env;
37
38 /* input and output nodes */
39 struct node **out, **in;
40 size_t nout, nin;
41
42 /* index of first implicit output */
43 size_t outimpidx;
44 /* index of first implicit and order-only input */
45 size_t inimpidx, inorderidx;
46
47 /* command hash */
48 uint64_t hash;
49
50 /* how many inputs need to be rebuilt or pruned before this edge is ready */
51 size_t nblock;
52 /* how many inputs need to be pruned before all outputs can be pruned */
53 size_t nprune;
54
55 enum {
56 FLAG_WORK = 1 << 0, /* scheduled for build */
57 FLAG_HASH = 1 << 1, /* calculated the command hash */
58 FLAG_DIRTY_IN = 1 << 3, /* dirty input */
59 FLAG_DIRTY_OUT = 1 << 4, /* missing or outdated output */
60 FLAG_DIRTY = FLAG_DIRTY_IN | FLAG_DIRTY_OUT,
61 FLAG_CYCLE = 1 << 5, /* used for cycle detection */
62 FLAG_DEPS = 1 << 6, /* dependencies loaded */
63 } flags;
64
65 /* used to coordinate ready work in build() */
66 struct edge *worknext;
67 /* used for alledges linked list */
68 struct edge *allnext;
69};
70
71void graphinit(void);
72
73/* create a new node or return existing node */
74struct node *mknode(struct string *);
75/* lookup a node by name; returns NULL if it does not exist */
76struct node *nodeget(const char *, size_t);
77/* update the mtime field of a node */
78void nodestat(struct node *);
79/* get a node's path, possibly escaped for the shell */
80struct string *nodepath(struct node *, _Bool);
81/* record the usage of a node by an edge */
82void nodeuse(struct node *, struct edge *);
83
84/* create a new edge with the given parent environment */
85struct edge *mkedge(struct environment *parent);
86/* compute the rapidhashv1 of an edge command and store it in the hash field */
87void edgehash(struct edge *);
88/* add dependencies from $depfile or .ninja_deps as implicit inputs */
89void edgeadddeps(struct edge *e, struct node **deps, size_t ndeps);
90
91/* a single linked list of all edges, valid up until build() */
92extern struct edge *alledges;