Skip to content

Commit

Permalink
issue #8023 Add option to exit with non-zero exit code on warnings ev…
Browse files Browse the repository at this point in the history
…en 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.
  • Loading branch information
albert-github committed Nov 23, 2020
1 parent 4e75d77 commit b88e809
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions src/doxygen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11912,6 +11912,7 @@ void generateOutput()
QDir thisDir;
thisDir.remove(Doxygen::objDBFileName);
thisDir.remove(Doxygen::filterDBFileName);
finishWarnExit();
Config::deinit();
QTextCodec::deleteAllCodecs();
delete Doxygen::clangUsrMap;
Expand Down
32 changes: 26 additions & 6 deletions src/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand All @@ -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)";
}
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions src/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b88e809

Please sign in to comment.