commit a999e66
shrub
·
2026-04-23 18:28:43 +0000 UTC
parent bb32398
make sure only the chosen branch's recipes end up on the target in condional cases
1 files changed,
+32,
-12
+32,
-12
1@@ -754,6 +754,33 @@ blanknode(const struct PreLine *line)
2 return state;
3 }
4
5+static int
6+ruleinlist(const struct NodeList *out, const struct Node *rule)
7+{
8+ size_t i;
9+
10+ for (i = 0; i < out->n; i++) {
11+ if (&out->v[i] == rule)
12+ return 1;
13+ }
14+ return 0;
15+}
16+
17+static struct Node *
18+branchrule(struct NodeList *out, const struct Node *src, const struct PreLine *line)
19+{
20+ struct Node state;
21+
22+ memset(&state, 0, sizeof(state));
23+ state.kind = NODE_RULE;
24+ state.loc.line0 = line->line0;
25+ state.loc.line1 = line->line1;
26+ state.data.rule.dcolon = src->data.rule.dcolon;
27+ addwords(&state.data.rule.targets, &src->data.rule.targets);
28+ addnode(out, state);
29+ return &out->v[out->n - 1];
30+}
31+
32 static int
33 parsedefine(const struct Pre *pre, size_t *i, struct Node *out)
34 {
35@@ -970,6 +997,8 @@ parseblock(const struct Pre *pre, size_t *i, struct NodeList *out, struct Node *
36 line = &pre->v[*i];
37 if (line->isrecipe) {
38 if (last_rule) {
39+ if (!ruleinlist(out, last_rule))
40+ last_rule = branchrule(out, last_rule, line);
41 addrecipe(&last_rule->data.rule.recipes, line->text + 1);
42 last_rule->loc.line1 = line->line1;
43 (*i)++;
44@@ -996,18 +1025,9 @@ parseblock(const struct Pre *pre, size_t *i, struct NodeList *out, struct Node *
45 int last_rule_in_out;
46
47 last_rule_idx = 0;
48- last_rule_in_out = 0;
49- if (last_rule) {
50- size_t lrk;
51-
52- for (lrk = 0; lrk < out->n; lrk++) {
53- if (&out->v[lrk] == last_rule) {
54- last_rule_idx = lrk;
55- last_rule_in_out = 1;
56- break;
57- }
58- }
59- }
60+ last_rule_in_out = last_rule && ruleinlist(out, last_rule);
61+ if (last_rule_in_out)
62+ last_rule_idx = (size_t)(last_rule - out->v);
63 state = parsecond(line, trim);
64 free(trim);
65 (*i)++;