From 73ad5d9e292da525cebbf5da35a81750bf89218a Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 20 Apr 2023 15:27:07 +0300 Subject: Log configuration UUIDs after bpkg.configure.build step id --- bbot/worker/worker.cxx | 122 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 111 insertions(+), 11 deletions(-) diff --git a/bbot/worker/worker.cxx b/bbot/worker/worker.cxx index 0c159f6..aee7d3c 100644 --- a/bbot/worker/worker.cxx +++ b/bbot/worker/worker.cxx @@ -379,6 +379,12 @@ log_line (string&& l, string& log, tracer* trace = nullptr) log += '\n'; } +#ifndef _WIN32 +const char* comment_begin ("#"); +#else +const char* comment_begin ("rem"); +#endif + // Run the worker script command. Name is used for logging and diagnostics // only. Match lines read from the command's stderr against the regular // expressions and return the warning result status (instead of success) in @@ -398,11 +404,17 @@ log_line (string&& l, string& log, tracer* trace = nullptr) // For the special end step no command is executed. In this case only the user // is potentially prompted and the step is traced/logged. // +// If specified, the pre-run callback is called after the step id is logged +// but before the command is logged/executed. +// +using pre_run_function = void (); + template static result_status run_cmd (step_id step, tracer& t, string& log, + const function& pre_run, optional* out_str, const path& out_file, const regexes& warn_detect, const string& name, @@ -448,7 +460,7 @@ run_cmd (step_id step, } }; - auto prompt_step = [step, &t, &log, &bkp_step, &prompt] () + auto prompt_step = [step, &t, &log, &bkp_step, &prompt, &pre_run] () { const string& sid (to_string (step)); @@ -466,15 +478,15 @@ run_cmd (step_id step, // l3 ([&]{t << "step id: " << sid << ' ' << ts;}); -#ifndef _WIN32 - log += "# step id: "; -#else - log += "rem step id: "; -#endif + log += comment_begin; + log += " step id: "; log += sid; log += ' '; log += ts; log += '\n'; + + if (pre_run) + pre_run (); }; try @@ -619,12 +631,43 @@ run_cmd (step_id step, } } +template +static result_status +run_cmd (step_id step, + tracer& t, + string& log, + optional* out_str, const path& out_file, + const regexes& warn_detect, + const string& name, + const optional& bkp_step, + const optional& bkp_status, + string& last_cmd, + const process_env& pe, + A&&... a) +{ + return run_cmd (step, + t, + log, + nullptr /* pre_run */, + out_str, out_file, + warn_detect, + name, + bkp_step, + bkp_status, + last_cmd, + pe, + forward (a)...); +} + template static result_status run_bpkg (step_id step, const V& envvars, tracer& t, - string& log, optional& out, const regexes& warn_detect, + string& log, + const function& pre_run, + optional& out, + const regexes& warn_detect, const optional& bkp_step, const optional& bkp_status, string& last_cmd, @@ -633,7 +676,10 @@ run_bpkg (step_id step, { return run_cmd (step, t, - log, &out, path () /* out_file */, warn_detect, + log, + pre_run, + &out, path () /* out_file */, + warn_detect, "bpkg " + cmd, bkp_step, bkp_status, last_cmd, process_env ("bpkg", envvars), @@ -667,7 +713,10 @@ template static result_status run_bpkg (step_id step, tracer& t, - string& log, optional& out, const regexes& warn_detect, + string& log, + const function& pre_run, + optional& out, + const regexes& warn_detect, const optional& bkp_step, const optional& bkp_status, string& last_cmd, @@ -679,7 +728,10 @@ run_bpkg (step_id step, return run_bpkg (step, envvars, t, - log, out, warn_detect, + log, + pre_run, + out, + warn_detect, bkp_step, bkp_status, last_cmd, verbosity, cmd, forward (a)...); } @@ -2098,6 +2150,14 @@ build (size_t argc, const char* argv[]) // then when running the bpkg-pkg-build command we need to specify the // configuration for each package explicitly via --config-uuid. // + // While it's tempting to use the --config-name option instead of + // --config-uuid, that wouldn't work well for multiple current + // configurations. For --config-name the configuration search is carried + // out among configurations explicitly linked to the main configuration + // only. That's in contrast to --config-uuid, when the whole + // configuration cluster is searched (see bpkg-pkg-build implementation + // for details). + // // Let's not generate random UUIDs but use some predefined values which // we can easily recognize in the build logs. // @@ -3043,9 +3103,49 @@ build (size_t argc, const char* argv[]) optional dependency_checksum; + // Only log configuration UUIDs if they are specified on the command + // line. + // + function log_uuids ( + [&r, &trace, + target_uuid, host_uuid, module_uuid, install_uuid, + target_pkg] () + { + if (!target_pkg) + { + auto log = [&r, &trace] (const char* uuid, const char* name) + { + string s (uuid); + s += " - "; + s += name; + + l3 ([&]{trace << s;}); + + r.log += comment_begin; + r.log += ' '; + r.log += s; + r.log += '\n'; + }; + + r.log += comment_begin; + r.log += '\n'; + + log (target_uuid, "target"); + log (host_uuid, "host"); + log (module_uuid, "module"); + log (install_uuid, "install"); + + r.log += comment_begin; + r.log += '\n'; + } + }); + r.status |= run_bpkg ( b, - trace, r.log, dependency_checksum, wre, + trace, r.log, + log_uuids, + dependency_checksum, + wre, bkp_step, bkp_status, last_cmd, "-v", "build", -- cgit v1.1