diff options
author | David Shah <davey1576@gmail.com> | 2018-11-26 19:37:03 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-26 19:37:03 +0000 |
commit | cdfd35e6aaadd2f07ee5c00f51a13a1c74301748 (patch) | |
tree | 78b4c878958f1a1c6c81d5702d0cef5d8e1a0765 | |
parent | 0adc0d75297fa81034aa3f325cf2758314ca1336 (diff) | |
parent | 4a44bc569abde28b8c9d7440447295af683b92f4 (diff) | |
download | nextpnr-cdfd35e6aaadd2f07ee5c00f51a13a1c74301748.tar.gz nextpnr-cdfd35e6aaadd2f07ee5c00f51a13a1c74301748.tar.bz2 nextpnr-cdfd35e6aaadd2f07ee5c00f51a13a1c74301748.zip |
Merge pull request #150 from YosysHQ/err_warn_count
Print warning and error count at end of execution
-rw-r--r-- | common/command.cc | 15 | ||||
-rw-r--r-- | common/command.h | 1 | ||||
-rw-r--r-- | common/log.cc | 2 | ||||
-rw-r--r-- | 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<Settings>(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<Context> 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<LogLevel, int> 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 <stdarg.h> #include <stdio.h> #include <string> +#include <unordered_map> #include <vector> - #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<LogLevel, int> message_count_by_level; std::string stringf(const char *fmt, ...); std::string vstringf(const char *fmt, va_list ap); |