From 4a44bc569abde28b8c9d7440447295af683b92f4 Mon Sep 17 00:00:00 2001 From: David Shah Date: Mon, 26 Nov 2018 19:14:38 +0000 Subject: Print warning and error count at end of execution Signed-off-by: David Shah --- common/command.cc | 15 ++++++++++++++- common/command.h | 1 + common/log.cc | 2 ++ common/log.h | 3 ++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/common/command.cc b/common/command.cc index 6cc9fbe7..206a4d30 100644 --- a/common/command.cc +++ b/common/command.cc @@ -36,6 +36,7 @@ #include "jsonparse.h" #include "log.h" #include "timing.h" +#include "util.h" #include "version.h" NEXTPNR_NAMESPACE_BEGIN @@ -282,6 +283,15 @@ void CommandHandler::conflicting_options(const boost::program_options::variables } } +void CommandHandler::printFooter() +{ + int warning_count = get_or_default(message_count_by_level, LogLevel::WARNING, 0), + error_count = get_or_default(message_count_by_level, LogLevel::ERROR, 0); + if (warning_count > 0 || error_count > 0) + log_always("%d warning%s, %d error%s\n", warning_count, warning_count == 1 ? "" : "s", error_count, + error_count == 1 ? "" : "s"); +} + int CommandHandler::exec() { try { @@ -300,8 +310,11 @@ int CommandHandler::exec() settings = std::unique_ptr(new Settings(ctx.get())); setupContext(ctx.get()); setupArchContext(ctx.get()); - return executeMain(std::move(ctx)); + int rc = executeMain(std::move(ctx)); + printFooter(); + return rc; } catch (log_execution_error_exception) { + printFooter(); return -1; } } diff --git a/common/command.h b/common/command.h index 30e0e58b..d0f1d328 100644 --- a/common/command.h +++ b/common/command.h @@ -54,6 +54,7 @@ class CommandHandler int executeMain(std::unique_ptr ctx); po::options_description getGeneralOptions(); void run_script_hook(const std::string &name); + void printFooter(); protected: po::variables_map vm; diff --git a/common/log.cc b/common/log.cc index 82e09fec..0a75b020 100644 --- a/common/log.cc +++ b/common/log.cc @@ -38,6 +38,7 @@ log_write_type log_write_function = nullptr; std::string log_last_error; void (*log_error_atexit)() = NULL; +std::unordered_map message_count_by_level; static int log_newline_count = 0; bool had_nonfatal_error = false; @@ -112,6 +113,7 @@ void logv(const char *format, va_list ap, LogLevel level = LogLevel::LOG) void log_with_level(LogLevel level, const char *format, ...) { + message_count_by_level[level]++; va_list ap; va_start(ap, format); logv(format, ap, level); diff --git a/common/log.h b/common/log.h index f1727ac6..77adbb2f 100644 --- a/common/log.h +++ b/common/log.h @@ -26,8 +26,8 @@ #include #include #include +#include #include - #include "nextpnr.h" NEXTPNR_NAMESPACE_BEGIN @@ -57,6 +57,7 @@ extern log_write_type log_write_function; extern std::string log_last_error; extern void (*log_error_atexit)(); extern bool had_nonfatal_error; +extern std::unordered_map message_count_by_level; std::string stringf(const char *fmt, ...); std::string vstringf(const char *fmt, va_list ap); -- cgit v1.2.3