From 2a9204cab666d47770bf3809d95a689088019121 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 27 May 2020 15:27:57 +0200 Subject: Various minor fixes and cleanups --- libbuild2/build/script/parser.cxx | 3 --- libbuild2/build/script/parser.test.cxx | 2 +- libbuild2/build/script/script.cxx | 19 ++++++++++--------- libbuild2/build/script/script.hxx | 24 +++++++++++------------- libbuild2/build/script/token.cxx | 2 +- libbuild2/build/script/token.hxx | 2 +- 6 files changed, 24 insertions(+), 28 deletions(-) (limited to 'libbuild2/build') 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 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 (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 ("~")) = temp_dir.path; + } } void environment:: @@ -118,11 +124,6 @@ namespace build2 << e; } - // Set the $~ special variable. - // - value& v (assign (var_pool.insert ("~"))); - 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 vars; + small_vector 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; -- cgit v1.1