commit 2589e57

shrub  ·  2026-05-11 18:38:22 +0000 UTC
parent 6a164df
dont add .suffixes to graph and make graphviz output match ninja -t graph which i think looks nicer
2 files changed,  +15, -67
+13, -67
  1@@ -2,58 +2,10 @@
  2 #include "internal.h"
  3 
  4 #include <stdio.h>
  5-#include <stdlib.h>
  6 #include <string.h>
  7-#include <time.h>
  8 
  9 /* graphviz backend */
 10 
 11-struct Style {
 12-	const char *stroke;
 13-	const char *fill;
 14-	const char *cluster;
 15-};
 16-
 17-static const struct Style styles[] = {
 18-    {"#0F766E", "#CCFBF1", "#F0FDFA"},
 19-    {"#2563EB", "#DBEAFE", "#EFF6FF"},
 20-    {"#CA8A04", "#FEF3C7", "#FFFBEB"},
 21-    {"#C2410C", "#FED7AA", "#FFF7ED"},
 22-    {"#9333EA", "#E9D5FF", "#FAF5FF"},
 23-    {"#BE185D", "#FBCFE8", "#FDF2F8"},
 24-    {"#4F46E5", "#C7D2FE", "#EEF2FF"},
 25-    {"#059669", "#D1FAE5", "#ECFDF5"},
 26-};
 27-
 28-static size_t styleorder[sizeof(styles) / sizeof(styles[0])];
 29-static size_t nextstyle;
 30-
 31-static void
 32-shufflestyles(void)
 33-{
 34-	size_t i;
 35-
 36-	for (i = 0; i < sizeof(styles) / sizeof(styles[0]); i++)
 37-		styleorder[i] = i;
 38-	for (i = sizeof(styles) / sizeof(styles[0]); i > 1; i--) {
 39-		size_t j, t;
 40-
 41-		j = (size_t)(rand() % (int)i);
 42-		t = styleorder[i - 1];
 43-		styleorder[i - 1] = styleorder[j];
 44-		styleorder[j] = t;
 45-	}
 46-	nextstyle = 0;
 47-}
 48-
 49-static const struct Style *
 50-pickstyle(void)
 51-{
 52-	if (nextstyle >= sizeof(styles) / sizeof(styles[0]))
 53-		shufflestyles();
 54-	return &styles[styleorder[nextstyle++]];
 55-}
 56-
 57 static void
 58 emitstr(FILE *fp, const char *s)
 59 {
 60@@ -80,13 +32,13 @@ emitnode(FILE *fp, size_t i, const struct Target *t)
 61 {
 62 	fprintf(fp, "  n%zu [label=\"", i);
 63 	emitstr(fp, t->name);
 64-	fprintf(fp, "\", penwidth=1.2, color=\"#000000\", fillcolor=\"#FFFFFF\"");
 65+	fprintf(fp, "\"");
 66 	if (t->recipes.n > 0) {
 67-		fprintf(fp, ", shape=box, style=\"filled,rounded\"");
 68+		fprintf(fp, ", shape=box");
 69 	} else if (t->prereqs.n > 0 || t->order_only.n > 0) {
 70-		fprintf(fp, ", shape=box, style=\"filled,dashed,rounded\"");
 71+		fprintf(fp, ", shape=box, style=dashed");
 72 	} else {
 73-		fprintf(fp, ", style=filled");
 74+		fprintf(fp, ", shape=box");
 75 	}
 76 	fprintf(fp, "];\n");
 77 }
 78@@ -107,19 +59,17 @@ static void
 79 emitcluster(FILE *fp, const struct Graph *root, const struct SubGraph *sg, size_t *nextid)
 80 {
 81 	size_t i;
 82-	const struct Style *st;
 83 	size_t id;
 84 
 85 	id = (*nextid)++;
 86-	st = pickstyle();
 87 	fprintf(fp, "  subgraph cluster_%zu {\n", id);
 88 	fprintf(fp, "    label=\"");
 89 	emitownerlabel(fp, sg->prefix);
 90 	fprintf(fp, "\";\n");
 91 	fprintf(fp, "    labelloc=t;\n");
 92-	fprintf(fp, "    margin=18;\n");
 93-	fprintf(fp, "    style=\"rounded,filled\";\n");
 94-	fprintf(fp, "    color=\"%s\";\n    fillcolor=\"%s\";\n", st->stroke, st->cluster);
 95+	fprintf(fp, "    margin=12;\n");
 96+	fprintf(fp, "    style=dashed;\n");
 97+	fprintf(fp, "    color=\"#999999\";\n");
 98 	emitowners(fp, root, sg->prefix);
 99 	for (i = 0; i < sg->graph.nsubs; i++)
100 		emitcluster(fp, root, &sg->graph.subs[i], nextid);
101@@ -136,15 +86,13 @@ emitedges(FILE *fp, const struct Graph *graph, size_t i, const struct Target *t)
102 		dep = findctarget(graph, t->prereqs.v[j]);
103 		if (!dep)
104 			continue;
105-		fprintf(fp, "  n%zu -> n%zu [color=\"#475569\", penwidth=1.2];\n",
106-		        (size_t)(dep - graph->v), i);
107+		fprintf(fp, "  n%zu -> n%zu;\n", (size_t)(dep - graph->v), i);
108 	}
109 	for (j = 0; j < t->order_only.n; j++) {
110 		dep = findctarget(graph, t->order_only.v[j]);
111 		if (!dep)
112 			continue;
113-		fprintf(fp, "  n%zu -> n%zu [style=dashed, color=\"#F59E0B\", penwidth=1.2];\n",
114-		        (size_t)(dep - graph->v), i);
115+		fprintf(fp, "  n%zu -> n%zu [style=dashed];\n", (size_t)(dep - graph->v), i);
116 	}
117 }
118 
119@@ -157,14 +105,12 @@ gengraphviz(const struct Graph *graph, const char *path)
120 	fp = fopen(path, "w");
121 	if (!fp)
122 		return -1;
123-	srand((unsigned)time(0));
124-	shufflestyles();
125 
126 	fprintf(fp, "digraph shin {\n");
127-	fprintf(fp, "  rankdir=LR;\n");
128-	fprintf(fp, "  graph [bgcolor=\"#FFFFFF\", pad=0.3, nodesep=0.4, ranksep=0.7, splines=true];\n");
129-	fprintf(fp, "  node [fontname=\"monospace\", fontsize=10];\n");
130-	fprintf(fp, "  edge [arrowsize=0.7];\n");
131+	fprintf(fp, "  rankdir=\"LR\";\n");
132+	fprintf(fp, "  graph [fontname=\"serif\"];\n");
133+	fprintf(fp, "  node [fontsize=10, fontname=\"serif\", shape=box, height=0.25];\n");
134+	fprintf(fp, "  edge [fontsize=10, fontname=\"serif\"];\n");
135 	emitowners(fp, graph, 0);
136 	clusterid = 0;
137 	for (i = 0; i < graph->nsubs; i++)
+2, -0
1@@ -280,6 +280,8 @@ buildgraph(const struct RuleSet *ruleset, struct Graph *graph)
2 	for (i = 0; i < gs.nrules; i++) {
3 		size_t k;
4 
5+		if (issufrule(&gs.rules[i]))
6+			continue;
7 		if (collectsufrule(&gs.sufs, &gs.rules[i]))
8 			continue;
9 		collectpat(&gs.patterns, &gs.rules[i]);