From 52f3c1825660cbf9a5b39abbbbd04bc4f8172f69 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 19 May 2020 14:47:04 +0300 Subject: Add support for dry run mode for build script runner --- libbuild2/build/script/runner.cxx | 25 ++++++++++++++++++++----- libbuild2/build/script/script.hxx | 1 + libbuild2/rule.cxx | 15 ++------------- 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; -- cgit v1.1