From fc90de96c43a2c2c73a54f15655f2bf4eae9a28e Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 20 Jun 2017 00:21:24 +0300 Subject: Make bbot worker to set operation warning status --- bbot/worker.cxx | 58 +++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/bbot/worker.cxx b/bbot/worker.cxx index 82dc318..3e0def5 100644 --- a/bbot/worker.cxx +++ b/bbot/worker.cxx @@ -8,6 +8,7 @@ # include // getenv(), _putenv() #endif +#include #include #include @@ -55,9 +56,17 @@ catch (const system_error& e) fail << "unable to change current directory to " << d << ": " << e << endf; } +using regexes = vector; + +// If warn_detect argument is not NULL, match lines read from the command's +// stderr against the regular expressions and return the warning result +// status (instead of success) in case of a match. +// template static result_status -run_bpkg (tracer& t, string& log, const string& cmd, A&&... a) +run_bpkg (tracer& t, + string& log, const regexes& warn_detect, + const string& cmd, A&&... a) { try { @@ -87,6 +96,8 @@ run_bpkg (tracer& t, string& log, const string& cmd, A&&... a) pipe.out.close (); + result_status r (result_status::success); + // Log the diagnostics. // { @@ -97,11 +108,26 @@ run_bpkg (tracer& t, string& log, const string& cmd, A&&... a) getline (is, l); log += l; log += '\n'; + + // Match the log line with the warning-detecting regular expressions + // until the first match. + // + if (r != result_status::warning) + { + for (const auto& re: warn_detect) + { + if (regex_search (l, re)) + { + r = result_status::warning; + break; + } + } + } } } if (pr.wait ()) - return result_status::success; + return r; log += "bpkg " + cmd; const process_exit& e (*pr.exit); @@ -169,6 +195,22 @@ build (size_t argc, const char* argv[]) for (;;) // The "breakout" loop. { + // Regular expressions that detect different forms of build2 toolchain + // warnings. Accidently (or not), they also cover GCC and Clang warnings + // (for the English locale). + // + // The expressions will be matched multiple times, so let's make the + // matching faster, with the potential cost of making regular expressions + // creation slower. + // + regex::flag_type f (regex_constants::optimize); // ECMAScript is implied. + + regexes wre ({ + regex ("^warning: ", f), + regex ("^.+: warning: ", f), + regex ("^.+:\\d+: warning: ", f), + regex ("^.+:\\d+:\\d+: warning: ", f)}); + // Configure. // { @@ -182,7 +224,7 @@ build (size_t argc, const char* argv[]) // dir_path dir (tm.target ? tm.target->string () : tm.machine); - r.status |= run_bpkg (trace, r.log, + r.status |= run_bpkg (trace, r.log, wre, "create", "-d", dir.string (), "--wipe", @@ -196,7 +238,7 @@ build (size_t argc, const char* argv[]) // bpkg add // - r.status |= run_bpkg (trace, r.log, "add", tm.repository.string ()); + r.status |= run_bpkg (trace, r.log, wre, "add", tm.repository.string ()); if (!r.status) break; @@ -217,14 +259,14 @@ build (size_t argc, const char* argv[]) } } - r.status |= run_bpkg (trace, r.log, "fetch", ts, t); + r.status |= run_bpkg (trace, r.log, wre, "fetch", ts, t); if (!r.status) break; // bpkg build --configure-only / // - r.status |= run_bpkg (trace, r.log, + r.status |= run_bpkg (trace, r.log, wre, "build", "--configure-only", "--yes", @@ -243,7 +285,7 @@ build (size_t argc, const char* argv[]) // bpkg update // - r.status |= run_bpkg (trace, r.log, "update", tm.name); + r.status |= run_bpkg (trace, r.log, wre, "update", tm.name); if (!r.status) break; @@ -258,7 +300,7 @@ build (size_t argc, const char* argv[]) // bpkg test // - r.status |= run_bpkg (trace, r.log, "test", tm.name); + r.status |= run_bpkg (trace, r.log, wre, "test", tm.name); if (!r.status) break; -- cgit v1.1