From d38dbf711c9532eea99607368278a8396b3db667 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 4 Dec 2020 12:53:52 +0300 Subject: In update ad hoc recipe buildscripts allow non-pure function calls only in depdeb preamble --- libbuild2/build/script/parser.cxx | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'libbuild2/build/script/parser.cxx') diff --git a/libbuild2/build/script/parser.cxx b/libbuild2/build/script/parser.cxx index 04a257f..9b9f324 100644 --- a/libbuild2/build/script/parser.cxx +++ b/libbuild2/build/script/parser.cxx @@ -5,6 +5,7 @@ #include +#include #include #include @@ -26,7 +27,7 @@ namespace build2 // script parser:: - pre_parse (const target& tg, const adhoc_actions& acts, + pre_parse (const target& tg, const adhoc_actions& as, istream& is, const path_name& pn, uint64_t line, optional diag, const location& diag_loc) { @@ -40,12 +41,15 @@ namespace build2 // The script shouldn't be able to modify the target/scopes. // target_ = const_cast (&tg); - actions_ = &acts; + actions_ = &as; scope_ = const_cast (&tg.base_scope ()); root_ = scope_->root_scope (); pbase_ = scope_->src_path_; + perform_update_ = find (as.begin (), as.end (), perform_update_id) != + as.end (); + script s; script_ = &s; runner_ = nullptr; @@ -65,6 +69,15 @@ namespace build2 s.end_loc = get_location (t); + // Diagnose impure function calls. + // + if (impure_func_) + fail (impure_func_->second) + << "call to impure function " << impure_func_->first << " is " + << "only allowed in depdb preamble" << + info << "consider using 'depdb' builtin to track its result " + << "changes"; + // Diagnose absent/ambigous script name. // { @@ -538,6 +551,11 @@ namespace build2 script_->body_temp_dir = false; } + // Reset the impure function call info since it's valid for the + // depdb preamble. + // + impure_func_ = nullopt; + // Instruct the parser to save the depdb builtin line separately // from the script lines, when it is fully parsed. Note that the // builtin command arguments will be validated during execution, @@ -1164,6 +1182,18 @@ namespace build2 return r; } + + void parser:: + lookup_function (string&& name, const location& loc) + { + if (perform_update_ && !impure_func_) + { + const function_overloads* f (ctx.functions.find (name)); + + if (f != nullptr && !f->pure) + impure_func_ = make_pair (move (name), loc); + } + } } } } -- cgit v1.1