aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/build/script/parser.cxx
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/build/script/parser.cxx
parente6470e37093084251b7ee60a904a78e54d13e31b (diff)
Create build script temporary directory on demand
Diffstat (limited to 'libbuild2/build/script/parser.cxx')
-rw-r--r--libbuild2/build/script/parser.cxx33
1 files changed, 22 insertions, 11 deletions
diff --git a/libbuild2/build/script/parser.cxx b/libbuild2/build/script/parser.cxx
index b170088..648cc7b 100644
--- a/libbuild2/build/script/parser.cxx
+++ b/libbuild2/build/script/parser.cxx
@@ -16,12 +16,6 @@ namespace build2
{
using type = token_type;
- static inline bool
- special_variable (const string& name)
- {
- return name == ">" || name == "<";
- }
-
//
// Pre-parse.
//
@@ -101,11 +95,11 @@ namespace build2
{
case line_type::var:
{
- // Check if we are trying to modify any of the special variables
- // ($>, $<).
+ // Check if we are trying to modify any of the special variables.
//
if (special_variable (t.value))
- fail (t) << "attempt to set '" << t.value << "' variable";
+ fail (t) << "attempt to set '" << t.value << "' special "
+ << "variable";
// We don't pre-enter variables.
//
@@ -275,6 +269,9 @@ namespace build2
{
const script& s (*script_);
+ if (s.temp_dir)
+ environment_->create_temp_dir ();
+
runner_->enter (*environment_, s.start_loc);
// Note that we rely on "small function object" optimization for the
@@ -339,6 +336,14 @@ namespace build2
runner_->leave (*environment_, s.end_loc);
}
+ // When add a special variable don't forget to update lexer::word().
+ //
+ bool parser::
+ special_variable (const string& n) noexcept
+ {
+ return n == ">" || n == "<" || n == "~";
+ }
+
lookup parser::
lookup_variable (name&& qual, string&& name, const location& loc)
{
@@ -348,9 +353,15 @@ namespace build2
if (pre_parse_)
{
// Add the variable name skipping special variables and suppressing
- // duplicates.
+ // duplicates. While at it, check if the script temporary directory
+ // is referenced and set the flag, if that's the case.
//
- if (!name.empty () && !special_variable (name))
+ if (special_variable (name))
+ {
+ if (name == "~")
+ script_->temp_dir = true;
+ }
+ else if (!name.empty ())
{
auto& vars (script_->vars);