diff options
Diffstat (limited to 'src/message.cpp')
-rw-r--r-- | src/message.cpp | 99 |
1 files changed, 70 insertions, 29 deletions
diff --git a/src/message.cpp b/src/message.cpp index d8f83ef..95a7553 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -1,6 +1,6 @@ /****************************************************************************** * - * Copyright (C) 1997-2015 by Dimitri van Heesch. + * Copyright (C) 1997-2020 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its * documentation under the terms of the GNU General Public License is hereby @@ -14,14 +14,13 @@ */ #include <stdio.h> -#include <qdatetime.h> #include "config.h" -#include "util.h" #include "debug.h" -#include "doxygen.h" #include "portable.h" -#include "filedef.h" #include "message.h" +#include "doxygen.h" + +#include <mutex> static QCString outputFormat; static const char *warning_str = "warning: "; @@ -35,6 +34,17 @@ static const char *error_str = "error: "; static FILE *warnFile = stderr; +enum warn_as_error +{ + WARN_NO, + WARN_YES, + FAIL_ON_WARNINGS, +}; +static warn_as_error warnBehavior = WARN_NO; +static bool warnStat = false; + +static std::mutex g_mutex; + void initWarningFormat() { // int filePos = Config_getString(WARN_FORMAT).find("$file"); @@ -97,7 +107,11 @@ void initWarningFormat() warnFile = stderr; } - if (Config_getBool(WARN_AS_ERROR)) + QCString warnStr = Config_getEnum(WARN_AS_ERROR).upper(); + if (warnStr =="NO") warnBehavior=WARN_NO; + else if (warnStr =="YES") warnBehavior=WARN_YES; + else if (warnStr =="FAIL_ON_WARNINGS") warnBehavior=FAIL_ON_WARNINGS; + if (warnBehavior == WARN_YES) { warning_str = error_str; } @@ -108,9 +122,10 @@ void msg(const char *fmt, ...) { if (!Config_getBool(QUIET)) { + std::unique_lock<std::mutex> lock(g_mutex); if (Debug::isFlagSet(Debug::Time)) { - printf("%.3f sec: ",((double)Doxygen::runningTime.elapsed())/1000.0); + printf("%.3f sec: ",((double)Debug::elapsedTime())); } va_list args; va_start(args, fmt); @@ -125,17 +140,7 @@ static void format_warn(const char *file,int line,const char *text) QCString lineSubst; lineSubst.setNum(line); QCString textSubst = text; QCString versionSubst; - if (file) // get version from file name - { - bool ambig; - FileDef *fd=findFileDef(Doxygen::inputNameDict,file,ambig); - if (fd) - { - versionSubst = fd->getVersion(); - } - } // substitute markers by actual values - bool warnAsError = Config_getBool(WARN_AS_ERROR); QCString msgText = substitute( substitute( @@ -150,18 +155,34 @@ static void format_warn(const char *file,int line,const char *text) ), "$text",textSubst ); - if (warnAsError) + if (warnBehavior == WARN_YES) { msgText += " (warning treated as error, aborting now)"; } msgText += '\n'; - // print resulting message - fwrite(msgText.data(),1,msgText.length(),warnFile); - if (warnAsError) + { + std::unique_lock<std::mutex> lock(g_mutex); + // print resulting message + fwrite(msgText.data(),1,msgText.length(),warnFile); + } + if (warnBehavior == WARN_YES) { exit(1); } + warnStat = true; +} + +static void handle_warn_as_error() +{ + if (warnBehavior == WARN_YES) + { + std::unique_lock<std::mutex> lock(g_mutex); + QCString msgText = " (warning treated as error, aborting now)\n"; + fwrite(msgText.data(),1,msgText.length(),warnFile); + exit(1); + } + warnStat = true; } static void do_warn(bool enabled, const char *file, int line, const char *prefix, const char *fmt, va_list args) @@ -174,7 +195,7 @@ static void do_warn(bool enabled, const char *file, int line, const char *prefix int l=0; if (prefix) { - l=strlen(prefix); + l=(int)strlen(prefix); } // determine needed buffersize based on: // format + arguments @@ -233,6 +254,7 @@ void warn_uncond(const char *fmt, ...) va_start(args, fmt); vfprintf(warnFile, (QCString(warning_str) + fmt).data(), args); va_end(args); + handle_warn_as_error(); } void err(const char *fmt, ...) @@ -241,6 +263,7 @@ void err(const char *fmt, ...) va_start(args, fmt); vfprintf(warnFile, (QCString(error_str) + fmt).data(), args); va_end(args); + handle_warn_as_error(); } extern void err_full(const char *file,int line,const char *fmt, ...) @@ -253,18 +276,27 @@ extern void err_full(const char *file,int line,const char *fmt, ...) void term(const char *fmt, ...) { - va_list args; - va_start(args, fmt); - vfprintf(warnFile, (QCString(error_str) + fmt).data(), args); - va_end(args); - if (warnFile != stderr) { - for (int i = 0; i < strlen(error_str); i++) fprintf(warnFile, " "); - fprintf(warnFile, "%s\n", "Exiting..."); + std::unique_lock<std::mutex> lock(g_mutex); + va_list args; + va_start(args, fmt); + vfprintf(warnFile, (QCString(error_str) + fmt).data(), args); + va_end(args); + if (warnFile != stderr) + { + for (int i = 0; i < (int)strlen(error_str); i++) fprintf(warnFile, " "); + fprintf(warnFile, "%s\n", "Exiting..."); + } } exit(1); } +void warn_flush() +{ + fflush(warnFile); +} + + void printlex(int dbg, bool enter, const char *lexName, const char *fileName) { const char *enter_txt = "entering"; @@ -276,6 +308,7 @@ void printlex(int dbg, bool enter, const char *lexName, const char *fileName) enter_txt_uc = "Finished"; } + std::unique_lock<std::mutex> lock(g_mutex); if (dbg) { if (fileName) @@ -291,3 +324,11 @@ void printlex(int dbg, bool enter, const char *lexName, const char *fileName) Debug::print(Debug::Lex,0,"%s lexical analyzer: %s\n",enter_txt_uc, qPrint(lexName)); } } + +extern void finishWarnExit() +{ + if (warnStat && warnBehavior == FAIL_ON_WARNINGS) + { + exit(1); + } +} |