Print warning and error count at end of execution

Signed-off-by: David Shah <dave@ds0.me>
This commit is contained in:
David Shah 2018-11-26 19:14:38 +00:00
parent 0adc0d7529
commit 4a44bc569a
4 changed files with 19 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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);