diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/qdoc/config.cpp | 1 | ||||
-rw-r--r-- | src/qdoc/config.h | 2 | ||||
-rw-r--r-- | src/qdoc/doc/qdoc-manual-qdocconf.qdoc | 26 | ||||
-rw-r--r-- | src/qdoc/location.cpp | 30 | ||||
-rw-r--r-- | src/qdoc/location.h | 4 | ||||
-rw-r--r-- | src/qdoc/main.cpp | 2 |
6 files changed, 63 insertions, 2 deletions
diff --git a/src/qdoc/config.cpp b/src/qdoc/config.cpp index 685add0f9..e116b24fb 100644 --- a/src/qdoc/config.cpp +++ b/src/qdoc/config.cpp @@ -119,6 +119,7 @@ QString ConfigStrings::IMAGEEXTENSIONS = QStringLiteral("imageextensions"); QString ConfigStrings::QMLONLY = QStringLiteral("qmlonly"); QString ConfigStrings::QMLTYPESPAGE = QStringLiteral("qmltypespage"); QString ConfigStrings::QMLTYPESTITLE = QStringLiteral("qmltypestitle"); +QString ConfigStrings::WARNINGLIMIT = QStringLiteral("warninglimit"); QString ConfigStrings::WRITEQAPAGES = QStringLiteral("writeqapages"); /*! diff --git a/src/qdoc/config.h b/src/qdoc/config.h index 3fa24c1d6..f4781eb10 100644 --- a/src/qdoc/config.h +++ b/src/qdoc/config.h @@ -232,6 +232,7 @@ struct ConfigStrings static QString QMLONLY; static QString QMLTYPESPAGE; static QString QMLTYPESTITLE; + static QString WARNINGLIMIT; static QString WRITEQAPAGES; }; @@ -312,6 +313,7 @@ struct ConfigStrings #define CONFIG_QMLONLY ConfigStrings::QMLONLY #define CONFIG_QMLTYPESPAGE ConfigStrings::QMLTYPESPAGE #define CONFIG_QMLTYPESTITLE ConfigStrings::QMLTYPESTITLE +#define CONFIG_WARNINGLIMIT ConfigStrings::WARNINGLIMIT #define CONFIG_WRITEQAPAGES ConfigStrings::WRITEQAPAGES QT_END_NAMESPACE diff --git a/src/qdoc/doc/qdoc-manual-qdocconf.qdoc b/src/qdoc/doc/qdoc-manual-qdocconf.qdoc index cbb233d8d..d61483f44 100644 --- a/src/qdoc/doc/qdoc-manual-qdocconf.qdoc +++ b/src/qdoc/doc/qdoc-manual-qdocconf.qdoc @@ -122,6 +122,7 @@ \li \l {tabsize-variable} {tabsize} \li \l {version-variable} {version} \li \l {versionsym-variable} {versionsym} + \li \l {warninglimit-variable} {warninglimit} \endlist \section1 Categories @@ -1120,6 +1121,31 @@ implemented. Currently, it only works within raw HTML code. See also \l {version} {\\version}. + + \target warninglimit-variable + \section1 warninglimit + + The \c warninglimit variable sets the maximum number of documentation + warnings allowed. If this limit is exceeded, QDoc continues as normal + but exits with the warning count as the error code. If the limit was + not exceeded or \c warninglimit was not defined, QDoc process exits + with 0, assuming there were no other critical errors. + + Setting the \c warninglimit to \c 0 means failure on any warning. + + \note By default, QDoc does not enforce the warning limit. Enable it + with \c {warninglimit.enabled = true} or by defining + the \c QDOC_ENABLE_WARNINGLIMIT environment variable. + + For example, + + \badcode + # Fail the documentation build if we have more than 100 warnings + warninglimit = 100 + warninglimit.enabled = true + \endcode + + The \c warninglimit variable was introduced in Qt 5.11. */ /*! diff --git a/src/qdoc/location.cpp b/src/qdoc/location.cpp index 6fd83c6ad..b60233386 100644 --- a/src/qdoc/location.cpp +++ b/src/qdoc/location.cpp @@ -42,7 +42,10 @@ QT_BEGIN_NAMESPACE const Location Location::null; int Location::tabSize; +int Location::warningCount = 0; +int Location::warningLimit = -1; QString Location::programName; +QString Location::project; QRegExp *Location::spuriousRegExp = 0; bool Location::logProgress_ = false; @@ -276,6 +279,24 @@ void Location::error(const QString& message, const QString& details) const } /*! + Returns the error code QDoc should exit with; EXIT_SUCCESS + or the number of documentation warnings if they exceeded + the limit set by warninglimit configuration variable. + */ +int Location::exitCode() +{ + if (warningLimit < 0 || warningCount <= warningLimit) + return EXIT_SUCCESS; + + Location::null.emitMessage(Error, + tr("Documentation warnings (%1) exceeded the limit (%2) for '%3'.") + .arg(QString::number(warningCount), + QString::number(warningLimit), + project), QString()); + return warningCount; +} + +/*! Writes \a message and \a detals to stderr as a formatted error message and then exits the program. qdoc prints fatal errors in either phase (Prepare or Generate). @@ -308,6 +329,11 @@ void Location::initialize(const Config& config) { tabSize = config.getInt(CONFIG_TABSIZE); programName = config.programName(); + project = config.getString(CONFIG_PROJECT); + warningCount = 0; + if (qEnvironmentVariableIsSet("QDOC_ENABLE_WARNINGLIMIT") + || config.getBool(CONFIG_WARNINGLIMIT + Config::dot + "enabled")) + warningLimit = config.getInt(CONFIG_WARNINGLIMIT); QRegExp regExp = config.getRegExp(CONFIG_SPURIOUS); if (regExp.isValid()) { @@ -382,8 +408,10 @@ void Location::emitMessage(MessageType type, result.replace("\n", "\n "); if (type == Error) result.prepend(tr(": error: ")); - else if (type == Warning) + else if (type == Warning) { result.prepend(tr(": warning: ")); + ++warningCount; + } if (type != Report) result.prepend(toString()); fprintf(stderr, "%s\n", result.toLatin1().data()); diff --git a/src/qdoc/location.h b/src/qdoc/location.h index b28e82a14..5c2c90f2d 100644 --- a/src/qdoc/location.h +++ b/src/qdoc/location.h @@ -90,6 +90,7 @@ public: static void startLoggingProgress() { logProgress_ = true; } static void stopLoggingProgress() { logProgress_ = false; } static QString canonicalRelativePath(const QString &path); + static int exitCode(); private: enum MessageType { Warning, Error, Report }; @@ -116,7 +117,10 @@ private: bool etcetera; static int tabSize; + static int warningCount; + static int warningLimit; static QString programName; + static QString project; static QRegExp *spuriousRegExp; static bool logProgress_; }; diff --git a/src/qdoc/main.cpp b/src/qdoc/main.cpp index 90cd1ec76..a88533ebe 100644 --- a/src/qdoc/main.cpp +++ b/src/qdoc/main.cpp @@ -786,5 +786,5 @@ int main(int argc, char **argv) qDebug() << "main(): qdoc database deleted"; #endif - return EXIT_SUCCESS; + return Location::exitCode(); } |