From d6581aa9be74e83cc689bfdaae9aaf2e78287975 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 26 May 2020 14:55:40 +0300 Subject: Create build script temporary directory on demand --- libbuild2/test/script/parser.cxx | 10 +++++++++- libbuild2/test/script/parser.hxx | 12 ++++++------ libbuild2/test/script/script.cxx | 29 ++++++++++++++++++++++++++--- libbuild2/test/script/script.hxx | 11 ++++++++++- 4 files changed, 51 insertions(+), 11 deletions(-) (limited to 'libbuild2/test') diff --git a/libbuild2/test/script/parser.cxx b/libbuild2/test/script/parser.cxx index c206e0a..f663c11 100644 --- a/libbuild2/test/script/parser.cxx +++ b/libbuild2/test/script/parser.cxx @@ -389,7 +389,7 @@ namespace build2 // string& n (t.value); - if (n == "*" || n == "~" || n == "@" || digit (n)) + if (special_variable (n)) fail (t) << "attempt to set '" << n << "' variable directly"; // Pre-enter the variables now while we are executing serially. @@ -1598,6 +1598,14 @@ namespace build2 // The rest. // + // When add a special variable don't forget to update lexer::word(). + // + bool parser:: + special_variable (const string& n) noexcept + { + return n == "*" || n == "~" || n == "@" || digit (n); + } + lookup parser:: lookup_variable (name&& qual, string&& name, const location& loc) { diff --git a/libbuild2/test/script/parser.hxx b/libbuild2/test/script/parser.hxx index 19d4f76..aa64943 100644 --- a/libbuild2/test/script/parser.hxx +++ b/libbuild2/test/script/parser.hxx @@ -91,12 +91,6 @@ namespace build2 command_expr parse_command_line (token&, token_type&); - // Workaround for GCC 4.9 that fails to compile the base class - // protected member function call from a lambda defined in the derived - // class. - // - using build2::parser::apply_value_attributes; - // Execute. Issue diagnostics and throw failed in case of an error. // public: @@ -110,6 +104,12 @@ namespace build2 void exec_scope_body (); + // Helpers. + // + public: + static bool + special_variable (const string&) noexcept; + // Customization hooks. // protected: diff --git a/libbuild2/test/script/script.cxx b/libbuild2/test/script/script.cxx index b56da1b..34d4723 100644 --- a/libbuild2/test/script/script.cxx +++ b/libbuild2/test/script/script.cxx @@ -8,7 +8,7 @@ #include #include -#include // parser::apply_value_attributes() +#include using namespace std; @@ -96,8 +96,16 @@ namespace build2 } void scope:: - set_variable (string&& nm, names&& val, const string& attrs) + set_variable (string&& nm, + names&& val, + const string& attrs, + const location& ll) { + // Check if we are trying to modify any of the special variables. + // + if (parser::special_variable (nm)) + fail (ll) << "attempt to set '" << nm << "' variable directly"; + // Set the variable value and attributes. Note that we need to aquire // unique lock before potentially changing the script's variable // pool. The obtained variable reference can safelly be used with no @@ -118,7 +126,22 @@ namespace build2 lhs.assign (move (val), &var); else { - build2::script::parser p (context); + // If there is an error in the attributes string, our diagnostics + // will look like this: + // + // :1:1 error: unknown value attribute x + // testscript:10:1 info: while parsing attributes '[x]' + // + // Note that the attributes parsing error is the only reason for a + // failure. + // + auto df = make_diag_frame ( + [attrs, &ll](const diag_record& dr) + { + dr << info (ll) << "while parsing attributes '" << attrs << "'"; + }); + + parser p (context); p.apply_value_attributes (&var, lhs, value (move (val)), diff --git a/libbuild2/test/script/script.hxx b/libbuild2/test/script/script.hxx index 7bdb2ac..6356501 100644 --- a/libbuild2/test/script/script.hxx +++ b/libbuild2/test/script/script.hxx @@ -91,8 +91,17 @@ namespace build2 scope_state state = scope_state::unknown; + void + set_variable (string&& name, + names&&, + const string& attrs, + const location&) override; + + // Noop since the temporary directory is a working directory and so + // is created before the scope commands execution. + // virtual void - set_variable (string&& name, names&&, const string& attrs) override; + create_temp_dir () override {assert (false);}; // Variables. // -- cgit v1.1