From 9254560cc32fe219da9d9fe454e396e8f2a13b33 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 10 Nov 2022 17:54:57 +0300 Subject: Make $process.run() print builtin command line on error and verbosity level >= 3 --- libbuild2/functions-process.cxx | 11 ++++------- libbuild2/script/run.cxx | 35 +++++++++++++---------------------- libbuild2/utility.cxx | 15 +++++++++++++++ libbuild2/utility.hxx | 12 ++++++++++++ 4 files changed, 44 insertions(+), 29 deletions(-) (limited to 'libbuild2') diff --git a/libbuild2/functions-process.cxx b/libbuild2/functions-process.cxx index 948f581..bbcbbab 100644 --- a/libbuild2/functions-process.cxx +++ b/libbuild2/functions-process.cxx @@ -143,6 +143,9 @@ namespace build2 builtin_callbacks cb; fdpipe ofd (open_pipe ()); + if (verb >= 3) + print_process (process_args (bn, args)); + uint8_t rs; // Storage. butl::builtin b (bf (rs, args, @@ -177,17 +180,11 @@ namespace build2 diag_record dr; dr << fail << "builtin " << bn << " " << process_exit (rs); - // @@ DBUF - // @@ TMP: this and need to print command line at verbosite >= 3 - // line for the process case. - // -#if 0 if (verb >= 1 && verb <= 2) { dr << info << "command line: "; - print_process (dr, args); + print_process (dr, process_args (bn, args)); } -#endif dr << endf; } diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx index 1ce5564..cbd750f 100644 --- a/libbuild2/script/run.cxx +++ b/libbuild2/script/run.cxx @@ -1715,13 +1715,7 @@ namespace build2 auto process_args = [&c] () -> cstrings { - cstrings args {c.program.recall_string ()}; - - for (const auto& a: c.arguments) - args.push_back (a.c_str ()); - - args.push_back (nullptr); - return args; + return build2::process_args (c.program.recall_string (), c.arguments); }; // Prior to opening file descriptors for command input/output redirects @@ -2450,30 +2444,27 @@ namespace build2 if (!valid || (!success && diag)) { - dr << error (ll) << w << ' '; + dr << error (ll) << w << ' ' << pr << ' '; if (!exit->normal ()) - dr << pr << ' ' << *exit; + dr << *exit; else { uint16_t ec (exit->code ()); // Make sure printed as integer. if (!valid) - dr << pr << " exit code " << ec << " out of 0-255 range"; - else if (!success) + dr << "exit code " << ec << " out of 0-255 range"; + else { - if (diag) - { - if (cmd.exit) - dr << pr << " exit code " << ec - << (cmp == exit_comparison::eq ? " != " : " == ") - << exc; - else - dr << pr << " exited with code " << ec; - } + assert (!success && diag); + + if (cmd.exit) + dr << "exit code " << ec + << (cmp == exit_comparison::eq ? " != " : " == ") + << exc; + else + dr << "exited with code " << ec; } - else - assert (false); } if (verb == 1) diff --git a/libbuild2/utility.cxx b/libbuild2/utility.cxx index 5659771..3ce0026 100644 --- a/libbuild2/utility.cxx +++ b/libbuild2/utility.cxx @@ -607,6 +607,21 @@ namespace build2 run_finish_impl (dbuf, args, pr, true /* fail */, finish_verbosity); } + cstrings + process_args (const char* program, const strings& args) + { + cstrings r; + r.reserve (args.size () + 2); + + r.push_back (program); + + for (const string& a: args) + r.push_back (a.c_str ()); + + r.push_back (nullptr); + return r; + } + fdpipe open_pipe () { diff --git a/libbuild2/utility.hxx b/libbuild2/utility.hxx index 0271642..5fffc8c 100644 --- a/libbuild2/utility.hxx +++ b/libbuild2/utility.hxx @@ -872,6 +872,18 @@ namespace build2 bool trim = true, sha256* checksum = nullptr); + // Concatenate the program path and arguments into a shallow NULL-terminated + // vector of C-strings. + // + LIBBUILD2_SYMEXPORT cstrings + process_args (const char* program, const strings& args); + + inline cstrings + process_args (const string& program, const strings& args) + { + return process_args (program.c_str (), args); + } + // File descriptor streams. // fdpipe -- cgit v1.1