commit 4d9df5a

shrub  ·  2026-04-28 16:29:14 +0000 UTC
parent 56bb02d
fix subgraph ownership being too strict
1 files changed,  +8, -7
+8, -7
 1@@ -236,8 +236,7 @@ scopegraph(struct Graph *graph, const char *prefix)
 2 		graph->v[i].name = intern(name);
 3 		free(name);
 4 		free(graph->v[i].owner);
 5-		if (graph->v[i].defined || graph->v[i].recipes.n > 0 ||
 6-		    graph->v[i].prereqs.n > 0 || graph->v[i].order_only.n > 0)
 7+		if (graph->v[i].defined || graph->v[i].recipes.n > 0)
 8 			graph->v[i].owner = xstrdup(prefix);
 9 		else
10 			graph->v[i].owner = 0;
11@@ -263,11 +262,13 @@ mergetarget(struct Graph *graph, const struct Target *src)
12 	} else if (!dst->owner && src->owner) {
13 		dst->owner = xstrdup(src->owner);
14 	} else if (dst->owner && src->owner && !sameprefix(dst->owner, src->owner)) {
15-		fprintf(stderr, "target `%s' crosses subgraph ownership (%s vs %s)\n",
16-		        src->name,
17-		        dst->owner ? dst->owner : ".",
18-		        src->owner ? src->owner : ".");
19-		return -1;
20+		/*
21+		 * shared targets like ../lib/libzstd.a may be referenced from
22+		 * multiple sibling subgraphs; if that happens, treat the
23+		 * target as shared instead of attributing it to one owner and erroring.
24+		 */
25+		free(dst->owner);
26+		dst->owner = 0;
27 	} else if (dst->defined && src->defined && dst->dcolon != src->dcolon) {
28 		fprintf(stderr, "target file `%s' has both : and :: entries, i can't handle that!\n", dst->name);
29 		return -1;