commit d953691
shrub
·
2026-05-18 20:26:31 +0000 UTC
parent 9d065ad
small improvements to graphviz
1 files changed,
+45,
-8
+45,
-8
1@@ -27,18 +27,53 @@ emitownerlabel(FILE *fp, const char *owner)
2 emitstr(fp, label);
3 }
4
5+static int
6+hasdependents(const struct Graph *graph, size_t idx)
7+{
8+ size_t i, j;
9+ const char *name;
10+
11+ name = graph->v[idx].name;
12+ for (i = 0; i < graph->n; i++) {
13+ if (i == idx)
14+ continue;
15+ for (j = 0; j < graph->v[i].prereqs.n; j++) {
16+ if (strcmp(graph->v[i].prereqs.v[j], name) == 0)
17+ return 1;
18+ }
19+ for (j = 0; j < graph->v[i].impprereqs.n; j++) {
20+ if (strcmp(graph->v[i].impprereqs.v[j], name) == 0)
21+ return 1;
22+ }
23+ for (j = 0; j < graph->v[i].order_only.n; j++) {
24+ if (strcmp(graph->v[i].order_only.v[j], name) == 0)
25+ return 1;
26+ }
27+ }
28+ return 0;
29+}
30+
31 static void
32-emitnode(FILE *fp, size_t i, const struct Target *t)
33+emitnode(FILE *fp, const struct Graph *graph, size_t i, const struct Target *t, int is_default)
34 {
35+ int dashed;
36+
37+ dashed = t->phony ||
38+ (t->recipes.n == 0 &&
39+ (t->prereqs.n > 0 || t->impprereqs.n > 0 || t->order_only.n > 0)) ||
40+ !hasdependents(graph, i);
41 fprintf(fp, " n%zu [label=\"", i);
42 emitstr(fp, t->name);
43 fprintf(fp, "\"");
44- if (t->recipes.n > 0) {
45- fprintf(fp, ", shape=box");
46- } else if (t->prereqs.n > 0 || t->impprereqs.n > 0 || t->order_only.n > 0) {
47- fprintf(fp, ", shape=box, style=dashed");
48- } else {
49- fprintf(fp, ", shape=box");
50+ fprintf(fp, ", shape=box");
51+ if (dashed || is_default) {
52+ fprintf(fp, ", style=");
53+ if (dashed && is_default)
54+ fprintf(fp, "\"dashed,bold\"");
55+ else if (dashed)
56+ fprintf(fp, "dashed");
57+ else
58+ fprintf(fp, "bold");
59 }
60 fprintf(fp, "];\n");
61 }
62@@ -47,11 +82,13 @@ static void
63 emitowners(FILE *fp, const struct Graph *graph, const char *owner)
64 {
65 size_t i;
66+ const struct Target *def;
67
68+ def = defaulttarget(graph, owner);
69 for (i = 0; i < graph->n; i++) {
70 if (!targetownedby(&graph->v[i], owner))
71 continue;
72- emitnode(fp, i, &graph->v[i]);
73+ emitnode(fp, graph, i, &graph->v[i], def == &graph->v[i]);
74 }
75 }
76