From b679b1452d6513c0769928a2238ccd367c2b78f7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 31 Mar 2020 08:07:02 +0200 Subject: Handle duplicate config directives for same variable --- libbuild2/parser.cxx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'libbuild2/parser.cxx') diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index 532b357..797a484 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -1885,7 +1885,24 @@ namespace build2 if (l.var != nullptr) { - config_report.push_back (make_pair (l, move (*report))); + auto r (make_pair (l, move (*report))); + + // If we have a duplicate, update it (it could be useful to have + // multiple config directives to "probe" the value before calculating + // the default; see lookup_config() for details). + // + auto i (find_if (config_report.begin (), + config_report.end (), + [&l] (const pair& p) + { + return p.first.var == l.var; + })); + + if (i == config_report.end ()) + config_report.push_back (move (r)); + else + *i = move (r); + config_report_new = config_report_new || new_val; } } -- cgit v1.1