aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-05-19 14:47:04 +0300
committerBoris Kolpackov <boris@codesynthesis.com>2020-05-27 08:35:29 +0200
commit52f3c1825660cbf9a5b39abbbbd04bc4f8172f69 (patch)
tree22dc3660fa83c0cb10aa5f9695bf11a99a77f3a0
parentdb05f8ead4c2b5ef8a27c3ffc6b20c291b0e7c8c (diff)
Add support for dry run mode for build script runner
-rw-r--r--libbuild2/build/script/runner.cxx25
-rw-r--r--libbuild2/build/script/script.hxx1
-rw-r--r--libbuild2/rule.cxx15
3 files changed, 23 insertions, 18 deletions
diff --git a/libbuild2/build/script/runner.cxx b/libbuild2/build/script/runner.cxx
index 94f1394..0be55a5 100644
--- a/libbuild2/build/script/runner.cxx
+++ b/libbuild2/build/script/runner.cxx
@@ -29,10 +29,25 @@ namespace build2
size_t li,
const location& ll)
{
- if (verb >= 2)
- text << expr;
+ if (verb >= 3)
+ text << ": " << expr;
- build2::script::run (env, expr, li, ll);
+ // Run the expression if we are not in the dry run mode or if it
+ // executes the set builtin and print the expression otherwise, unless
+ // it is already printed or the verbosity level is lower than 2.
+ //
+ // @@ Should we also run expressions that execute the exit builtin in
+ // the dry run mode?
+ //
+ if (!env.context.dry_run ||
+ find_if (expr.begin (), expr.end (),
+ [] (const expr_term& et)
+ {
+ return et.pipe.back ().program.string () == "set";
+ }) != expr.end ())
+ build2::script::run (env, expr, li, ll);
+ else if (verb == 2)
+ text << expr;
}
bool default_runner::
@@ -40,8 +55,8 @@ namespace build2
const command_expr& expr,
size_t li, const location& ll)
{
- if (verb >= 2)
- text << expr;
+ if (verb >= 3)
+ text << ": ?" << expr;
return build2::script::run_if (env, expr, li, ll);
}
diff --git a/libbuild2/build/script/script.hxx b/libbuild2/build/script/script.hxx
index 8569a1f..9ada56f 100644
--- a/libbuild2/build/script/script.hxx
+++ b/libbuild2/build/script/script.hxx
@@ -22,6 +22,7 @@ namespace build2
using build2::script::line_type;
using build2::script::redirect;
using build2::script::redirect_type;
+ using build2::script::expr_term;
using build2::script::command_expr;
// Notes:
diff --git a/libbuild2/rule.cxx b/libbuild2/rule.cxx
index 9df5f67..49cb8f3 100644
--- a/libbuild2/rule.cxx
+++ b/libbuild2/rule.cxx
@@ -579,19 +579,8 @@ namespace build2
{
build::script::parser p (ctx);
build::script::environment e (script, t);
-
- if (!ctx.dry_run)
- {
- build::script::default_runner r;
- p.execute (e, r);
- }
- else
- {
- //@@ TODO:
- //
- //build::script::print_runner r;
- //p.execute (e, r);
- }
+ build::script::default_runner r;
+ p.execute (e, r);
}
return target_state::changed;