Skip to content

Commit e8d4fe8

Browse files
committed
graph: add dyndep support
1 parent c85b980 commit e8d4fe8

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

graph.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ mknode(struct string *path)
5858
n = xmalloc(sizeof(*n));
5959
n->path = path;
6060
n->shellpath = NULL;
61+
n->dyndep = NULL;
6162
n->gen = NULL;
6263
n->use = NULL;
6364
n->nuse = 0;
@@ -152,6 +153,7 @@ mkedge(struct environment *parent)
152153

153154
e = xmalloc(sizeof(*e));
154155
e->env = mkenv(parent);
156+
e->dyndep = NULL;
155157
e->pool = NULL;
156158
e->out = NULL;
157159
e->nout = 0;
@@ -227,3 +229,43 @@ edgeadddeps(struct edge *e, struct node **deps, size_t ndeps)
227229
e->inorderidx += ndeps;
228230
e->nin += ndeps;
229231
}
232+
233+
void
234+
edgeadddyndeps(struct edge *e, struct node **deps, size_t ndeps)
235+
{
236+
struct node **order, *n;
237+
size_t norder, i;
238+
239+
for (i = 0; i < ndeps; ++i) {
240+
n = deps[i];
241+
if (!n->gen)
242+
n->gen = mkphony(n);
243+
nodeuse(n, e);
244+
}
245+
e->indynidx = e->inorderidx;
246+
e->in = xreallocarray(e->in, e->nin + ndeps, sizeof(e->in[0]));
247+
order = e->in + e->inorderidx;
248+
norder = e->nin - e->inorderidx;
249+
memmove(order + ndeps, order, norder * sizeof(e->in[0]));
250+
memcpy(order, deps, ndeps * sizeof(e->in[0]));
251+
e->inorderidx += ndeps;
252+
e->nin += ndeps;
253+
}
254+
255+
void
256+
edgeadddynouts(struct edge *e, struct node **outs, size_t nouts)
257+
{
258+
struct node *n;
259+
size_t i;
260+
261+
for (i = 0; i < nouts; ++i) {
262+
n = outs[i];
263+
if (n->gen && n->gen->rule != &phonyrule)
264+
fatal("multiple rules generate '%s'", n->path->s);
265+
n->gen = e;
266+
}
267+
e->outdynidx = e->nout;
268+
e->out = xreallocarray(e->out, e->nout + nouts, sizeof(e->out[0]));
269+
memcpy(e->out + e->nout, outs, nouts * sizeof(e->out[0]));
270+
e->nout += nouts;
271+
}

graph.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ struct node {
1919
struct edge *gen, **use;
2020
size_t nuse;
2121

22+
/* dyndep or NULL if the node is not a dyndep */
23+
struct dyndep *dyndep;
24+
2225
/* command hash used to build this output, read from build log */
2326
uint64_t hash;
2427

@@ -39,10 +42,13 @@ struct edge {
3942
struct node **out, **in;
4043
size_t nout, nin;
4144

42-
/* index of first implicit output */
43-
size_t outimpidx;
44-
/* index of first implicit and order-only input */
45-
size_t inimpidx, inorderidx;
45+
/* dyndep or NULL if the edge has no dyndep */
46+
struct dyndep *dyndep;
47+
48+
/* index of first implicit adn dyndep output */
49+
size_t outimpidx, outdynidx;
50+
/* index of first implicit, dyndep and order-only input */
51+
size_t inimpidx, indynidx, inorderidx;
4652

4753
/* command hash */
4854
uint64_t hash;
@@ -60,6 +66,7 @@ struct edge {
6066
FLAG_DIRTY = FLAG_DIRTY_IN | FLAG_DIRTY_OUT,
6167
FLAG_CYCLE = 1 << 5, /* used for cycle detection */
6268
FLAG_DEPS = 1 << 6, /* dependencies loaded */
69+
FLAG_DYNDEP = 1 << 7, /* dyndep loaded */
6370
} flags;
6471

6572
/* used to coordinate ready work in build() */
@@ -87,6 +94,10 @@ struct edge *mkedge(struct environment *parent);
8794
void edgehash(struct edge *);
8895
/* add dependencies from $depfile or .ninja_deps as implicit inputs */
8996
void edgeadddeps(struct edge *e, struct node **deps, size_t ndeps);
97+
/* add dependencies from dyndep files as implicit inputs */
98+
void edgeadddyndeps(struct edge *e, struct node **deps, size_t ndeps);
99+
/* add outputs from dyndep as implicit outputs */
100+
void edgeadddynouts(struct edge *e, struct node **outs, size_t nouts);
90101

91102
/* a single linked list of all edges, valid up until build() */
92103
extern struct edge *alledges;

0 commit comments

Comments
 (0)