diff options
author | albert-github <albert.tests@gmail.com> | 2020-11-23 14:17:17 (GMT) |
---|---|---|
committer | albert-github <albert.tests@gmail.com> | 2020-11-23 14:17:17 (GMT) |
commit | b88e8097acdb30175c024ed47258739cec30f903 (patch) | |
tree | 23530963101cc692e5e63994c2296491a21ea742 | |
parent | 4e75d77f60bd173019247177686376ce36ace90b (diff) | |
download | Doxygen-b88e8097acdb30175c024ed47258739cec30f903.zip Doxygen-b88e8097acdb30175c024ed47258739cec30f903.tar.gz Doxygen-b88e8097acdb30175c024ed47258739cec30f903.tar.bz2 |
issue #8023 Add option to exit with non-zero exit code on warnings even if WARN_AS_ERROR is OFF
In case we want for a Continuous integration system a non-zero exit status at the end of a doxygen we can now set `WARN_AS_ERRORS=FAIL_ON_WARNINGS`.
The behavior for `NO` and `YES` remains as it was.
-rw-r--r-- | src/config.xml | 8 | ||||
-rw-r--r-- | src/doxygen.cpp | 1 | ||||
-rw-r--r-- | src/message.cpp | 32 | ||||
-rw-r--r-- | src/message.h | 1 |
4 files changed, 35 insertions, 7 deletions
diff --git a/src/config.xml b/src/config.xml index 0ec4219..2880cbe 100644 --- a/src/config.xml +++ b/src/config.xml @@ -1335,13 +1335,19 @@ FILE_VERSION_FILTER = "cleartool desc -fmt \%Vn" ]]> </docs> </option> - <option type='bool' id='WARN_AS_ERROR' defval='0'> + <option type='enum' id='WARN_AS_ERROR' defval='NO'> <docs> <![CDATA[ If the \c WARN_AS_ERROR tag is set to \c YES then doxygen will immediately stop when a warning is encountered. + If the \c WARN_AS_ERROR tag is set to \c FAIL_ON_WARNINGS then doxygen will continue + running as if \c WARN_AS_ERROR tag is set to \c NO, but at the end of the doxygen + process doxygen will return with a non-zero status. ]]> </docs> + <value name="NO"/> + <value name="YES" /> + <value name="FAIL_ON_WARNINGS" /> </option> <option type='string' id='WARN_FORMAT' format='string' defval='$file:$line: $text'> <docs> diff --git a/src/doxygen.cpp b/src/doxygen.cpp index 6c8c67a..2eec97e 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -11912,6 +11912,7 @@ void generateOutput() QDir thisDir; thisDir.remove(Doxygen::objDBFileName); thisDir.remove(Doxygen::filterDBFileName); + finishWarnExit(); Config::deinit(); QTextCodec::deleteAllCodecs(); delete Doxygen::clangUsrMap; diff --git a/src/message.cpp b/src/message.cpp index e107139..95a7553 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -34,6 +34,14 @@ 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; @@ -99,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; } @@ -129,7 +141,6 @@ static void format_warn(const char *file,int line,const char *text) QCString textSubst = text; QCString versionSubst; // substitute markers by actual values - bool warnAsError = Config_getBool(WARN_AS_ERROR); QCString msgText = substitute( substitute( @@ -144,7 +155,7 @@ 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)"; } @@ -155,22 +166,23 @@ static void format_warn(const char *file,int line,const char *text) // print resulting message fwrite(msgText.data(),1,msgText.length(),warnFile); } - if (warnAsError) + if (warnBehavior == WARN_YES) { exit(1); } + warnStat = true; } static void handle_warn_as_error() { - static bool warnAsError = Config_getBool(WARN_AS_ERROR); - if (warnAsError) + 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) @@ -312,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); + } +} diff --git a/src/message.h b/src/message.h index dd9eeeb..af49632 100644 --- a/src/message.h +++ b/src/message.h @@ -36,6 +36,7 @@ extern void err_full(const char *file,int line,const char *fmt, ...) PRINTFLIKE( extern void term(const char *fmt, ...) PRINTFLIKE(1, 2); void initWarningFormat(); void warn_flush(); +extern void finishWarnExit(); extern void printlex(int dbg, bool enter, const char *lexName, const char *fileName); |