aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/test
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-05-26 14:55:40 +0300
committerBoris Kolpackov <boris@codesynthesis.com>2020-05-27 14:38:01 +0200
commitd6581aa9be74e83cc689bfdaae9aaf2e78287975 (patch)
treee741d2c6fcdb567d8c7b897d17f3f0ca2358d307 /libbuild2/test
parente6470e37093084251b7ee60a904a78e54d13e31b (diff)
Create build script temporary directory on demand
Diffstat (limited to 'libbuild2/test')
-rw-r--r--libbuild2/test/script/parser.cxx10
-rw-r--r--libbuild2/test/script/parser.hxx12
-rw-r--r--libbuild2/test/script/script.cxx29
-rw-r--r--libbuild2/test/script/script.hxx11
4 files changed, 51 insertions, 11 deletions
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 <libbuild2/target.hxx>
#include <libbuild2/algorithm.hxx>
-#include <libbuild2/script/parser.hxx> // parser::apply_value_attributes()
+#include <libbuild2/test/script/parser.hxx>
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:
+ //
+ // <attributes>: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.
//