diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-09-13 16:07:41 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2022-09-13 16:07:41 +0200 |
commit | ce4b3b115957575c2055291c54fc6452817dab87 (patch) | |
tree | c2e993b609bdba211df5ac1ed4f95a8816703c23 /libbuild2/parser.cxx | |
parent | 0b18c9cc4531da4a3f20212152254a894d2cbff3 (diff) |
Fix bug in handling of disabled recipes in ad hoc pattern rules
Diffstat (limited to 'libbuild2/parser.cxx')
-rw-r--r-- | libbuild2/parser.cxx | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index 7e48ad8..03b912d 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -1253,8 +1253,13 @@ namespace build2 for (shared_ptr<adhoc_rule>& pr: recipes) { - pr->pattern = &rp; // Connect recipe to pattern. - rp.rules.push_back (move (pr)); + // Can be NULL if the recipe is disabled with a condition. + // + if (pr != nullptr) + { + pr->pattern = &rp; // Connect recipe to pattern. + rp.rules.push_back (move (pr)); + } } // Register this adhoc rule for all its actions. @@ -1766,7 +1771,15 @@ namespace build2 t = start; tt = t.type; for (size_t i (0); tt == type::percent || tt == type::multi_lcbrace; ++i) { - recipes.push_back (nullptr); // For missing else/default (see below). + // For missing else/default (see below). + // + // Note that it may remain NULL if we have, say, an if-condition that + // evaluates to false and no else. While it may be tempting to get rid + // of such "holes", it's not easy due to the replay semantics (see the + // target_ != nullptr block below). So we expect the caller to be + // prepared to handle this. + // + recipes.push_back (nullptr); attributes as; buildspec bs; |