aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/build/script
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/build/script')
-rw-r--r--libbuild2/build/script/parser.cxx3
-rw-r--r--libbuild2/build/script/parser.test.cxx2
-rw-r--r--libbuild2/build/script/script.cxx19
-rw-r--r--libbuild2/build/script/script.hxx24
-rw-r--r--libbuild2/build/script/token.cxx2
-rw-r--r--libbuild2/build/script/token.hxx2
6 files changed, 24 insertions, 28 deletions
diff --git a/libbuild2/build/script/parser.cxx b/libbuild2/build/script/parser.cxx
index 648cc7b..e64db91 100644
--- a/libbuild2/build/script/parser.cxx
+++ b/libbuild2/build/script/parser.cxx
@@ -269,9 +269,6 @@ 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
diff --git a/libbuild2/build/script/parser.test.cxx b/libbuild2/build/script/parser.test.cxx
index 42681e3..9046312 100644
--- a/libbuild2/build/script/parser.test.cxx
+++ b/libbuild2/build/script/parser.test.cxx
@@ -166,7 +166,7 @@ namespace build2
{
case mode::run:
{
- environment e (perform_update_id, tt);
+ environment e (perform_update_id, tt, false /* temp_dir */);
print_runner r (print_line);
p.execute (ctx.global_scope, ctx.global_scope, e, s, r);
break;
diff --git a/libbuild2/build/script/script.cxx b/libbuild2/build/script/script.cxx
index e344b59..3485f54 100644
--- a/libbuild2/build/script/script.cxx
+++ b/libbuild2/build/script/script.cxx
@@ -22,7 +22,7 @@ namespace build2
static const optional<string> wd_name ("current directory");
environment::
- environment (action a, const target_type& t)
+ environment (action a, const target_type& t, bool temp)
: build2::script::environment (
t.ctx,
cast<target_triplet> (t.ctx.global_scope["build.host"]),
@@ -34,9 +34,7 @@ namespace build2
target (t),
vars (context, false /* global */)
{
- // Set special variables. Note that the $~ variable is set later and
- // only if the temporary directory is required for the script
- // execution (see create_temp_dir() for details).
+ // Set special variables.
//
{
// $>
@@ -65,6 +63,14 @@ namespace build2
assign (var_pool.insert ("<")) = move (ns);
}
+
+ // Set the $~ special variable.
+ //
+ if (temp)
+ {
+ create_temp_dir ();
+ assign (var_pool.insert<dir_path> ("~")) = temp_dir.path;
+ }
}
void environment::
@@ -118,11 +124,6 @@ namespace build2
<< e;
}
- // Set the $~ special variable.
- //
- value& v (assign (var_pool.insert<dir_path> ("~")));
- v = td;
-
if (verb >= 3)
text << "mkdir " << td;
}
diff --git a/libbuild2/build/script/script.hxx b/libbuild2/build/script/script.hxx
index 7d27840..2118568 100644
--- a/libbuild2/build/script/script.hxx
+++ b/libbuild2/build/script/script.hxx
@@ -29,11 +29,10 @@ namespace build2
// Notes:
//
// - Once parsed, the script can be executed in multiple threads with
- // the state (variable values, etc) maintained in the environment
- // object.
+ // the state (variable values, etc) maintained in the environment.
//
- // - The default script command redirects semantics is none for stdin,
- // merge into stderr for stdout, and pass for stderr.
+ // - The default script command redirects semantics is 'none' for stdin,
+ // 'merge' into stderr for stdout, and 'pass' for stderr.
//
class script
{
@@ -53,7 +52,7 @@ namespace build2
// properly tracked (the variable value change will not trigger the
// target rebuild).
//
- small_vector<string, 1> vars;
+ small_vector<string, 2> vars; // 2 for command and options.
// True if script references the $~ special variable.
//
@@ -68,7 +67,7 @@ namespace build2
public:
using target_type = build2::target;
- environment (action, const target_type&);
+ environment (action, const target_type&, bool temp_dir);
environment (environment&&) = delete;
environment (const environment&) = delete;
@@ -76,15 +75,16 @@ namespace build2
environment& operator= (const environment&) = delete;
public:
+ // Primary target this environment is for.
+ //
const target_type& target;
- // Script-local variable pool.
+ // Script-local variable pool and map.
//
- variable_pool var_pool;
-
- // Note that if we pass the variable name as a string, then it will
- // be looked up in the wrong pool.
+ // Note that if we lookup the variable by passing name as a string,
+ // then it will be looked up in the wrong pool.
//
+ variable_pool var_pool;
variable_map vars;
// Temporary directory for the script run.
@@ -110,8 +110,6 @@ namespace build2
const string& attrs,
const location&) override;
- // Create the temporary directory and set the $~ variable.
- //
virtual void
create_temp_dir () override;
diff --git a/libbuild2/build/script/token.cxx b/libbuild2/build/script/token.cxx
index 7c15dff..8f8477b 100644
--- a/libbuild2/build/script/token.cxx
+++ b/libbuild2/build/script/token.cxx
@@ -14,7 +14,7 @@ namespace build2
void
token_printer (ostream& os, const token& t, print_mode m)
{
- // No build script-specific tokens so far.
+ // No buildscript-specific tokens so far.
//
build2::script::token_printer (os, t, m);
}
diff --git a/libbuild2/build/script/token.hxx b/libbuild2/build/script/token.hxx
index 90c1379..954b412 100644
--- a/libbuild2/build/script/token.hxx
+++ b/libbuild2/build/script/token.hxx
@@ -19,7 +19,7 @@ namespace build2
{
using base_type = build2::script::token_type;
- // No build script-specific tokens so far.
+ // No buildscript-specific tokens so far.
//
token_type () = default;