aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/build/script
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2024-01-23 13:33:00 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2024-01-23 13:33:00 +0200
commitd807adcd677392c93fed65e04af0a46ae159c8ef (patch)
treec36c131e6ffd3b21fa0c2c7f7632f33a04878763 /libbuild2/build/script
parentbcde39204f0f15f207a10da59347db514936c617 (diff)
Fix bug in Buildscript pre-parsing logic
Diffstat (limited to 'libbuild2/build/script')
-rw-r--r--libbuild2/build/script/parser.cxx20
-rw-r--r--libbuild2/build/script/parser.hxx7
2 files changed, 23 insertions, 4 deletions
diff --git a/libbuild2/build/script/parser.cxx b/libbuild2/build/script/parser.cxx
index 2298780..3ecf23d 100644
--- a/libbuild2/build/script/parser.cxx
+++ b/libbuild2/build/script/parser.cxx
@@ -47,7 +47,7 @@ namespace build2
{
path_ = &pn;
- pre_parse_ = true;
+ top_pre_parse_ = pre_parse_ = true;
lexer l (is, *path_, line, lexer_mode::command_line);
set_lexer (&l);
@@ -973,6 +973,11 @@ namespace build2
if (!skip_diag)
{
+ // Sanity check: we should not be suspending the pre-parse mode
+ // turned on by the base parser.
+ //
+ assert (top_pre_parse_);
+
pre_parse_ = false; // Make parse_names() perform expansions.
pre_parse_suspended_ = true;
}
@@ -1547,7 +1552,7 @@ namespace build2
{
path_ = nullptr; // Set by replays.
- pre_parse_ = false;
+ top_pre_parse_ = pre_parse_ = false;
set_lexer (nullptr);
@@ -3397,6 +3402,12 @@ namespace build2
{
lookup r;
+ // Note that pre-parse can be switched on by the base parser even
+ // during execute.
+ //
+ if (!top_pre_parse_)
+ return r;
+
// Add the variable name skipping special variables and suppressing
// duplicates, unless the default variables change tracking is
// canceled with `depdb clear`. While at it, check if the script
@@ -3479,7 +3490,10 @@ namespace build2
void parser::
lookup_function (string&& name, const location& loc)
{
- if (perform_update_ && file_based_ && !impure_func_)
+ // Note that pre-parse can be switched on by the base parser even
+ // during execute.
+ //
+ if (top_pre_parse_ && perform_update_ && file_based_ && !impure_func_)
{
const function_overloads* f (ctx->functions.find (name));
diff --git a/libbuild2/build/script/parser.hxx b/libbuild2/build/script/parser.hxx
index ce550fc..8f86b24 100644
--- a/libbuild2/build/script/parser.hxx
+++ b/libbuild2/build/script/parser.hxx
@@ -396,7 +396,12 @@ namespace build2
//
optional<location> computed_var_;
- // True during pre-parsing when the pre-parse mode is temporarily
+ // True if we (rather than the base parser) turned on the pre-parse
+ // mode.
+ //
+ bool top_pre_parse_;
+
+ // True during top-pre-parsing when the pre-parse mode is temporarily
// suspended to perform expansion.
//
bool pre_parse_suspended_ = false;