diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2017-03-31 14:34:53 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2017-04-03 07:18:35 +0000 |
commit | b925265d48dca753335e788a9f5efe944ff1a7a6 (patch) | |
tree | 57491f191a188a6120891f226ebc10bcd9f509b7 | |
parent | 7a412abb420e9fdfbe81ad35f1ee406a20736705 (diff) |
Cumulate delayed product errors
If a delayed error leads to other errors later on, we would output the
later errors without showing the original - more important - delayed
errors.
Cumulate delayed product errors and pass them up the stack.
Change-Id: Ibdfc6d3e301a80ef265792907b3e4a150a22ef8b
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r-- | src/lib/corelib/language/projectresolver.cpp | 34 | ||||
-rw-r--r-- | src/lib/corelib/language/projectresolver.h | 2 | ||||
-rw-r--r-- | src/lib/corelib/tools/error.cpp | 12 | ||||
-rw-r--r-- | src/lib/corelib/tools/error.h | 2 |
4 files changed, 45 insertions, 5 deletions
diff --git a/src/lib/corelib/language/projectresolver.cpp b/src/lib/corelib/language/projectresolver.cpp index 5265c6d2e..0669f7893 100644 --- a/src/lib/corelib/language/projectresolver.cpp +++ b/src/lib/corelib/language/projectresolver.cpp @@ -152,8 +152,29 @@ TopLevelProjectPtr ProjectResolver::resolve() m_productContext = 0; m_moduleContext = 0; m_elapsedTimeModPropEval = m_elapsedTimeAllPropEval = m_elapsedTimeGroups = 0; - const TopLevelProjectPtr tlp = resolveTopLevelProject(); - printProfilingInfo(); + TopLevelProjectPtr tlp; + try { + tlp = resolveTopLevelProject(); + printProfilingInfo(); + } catch (const ErrorInfo &errorInfo) { + ErrorInfo e; + for (auto it = m_loadResult.productInfos.cbegin(); it != m_loadResult.productInfos.cend(); + ++it) { + const auto &productInfo = it.value(); + if (productInfo.delayedError.hasError()) { + try { + QString name = m_evaluator->stringValue(it.key(), QStringLiteral("name")); + e.append(Tr::tr("Errors in product '%1':").arg(name), it.key()->location()); + } catch (const ErrorInfo &/* ignore */) { + // The name cannot be determined because of other errors. + e.append(Tr::tr("Errors in product:"), it.key()->location()); + } + appendError(e, productInfo.delayedError); + } + } + appendError(e, errorInfo); + throw e; + } return tlp; } @@ -346,7 +367,7 @@ void ProjectResolver::resolveProduct(Item *item, ProjectContext *projectContext) m_logger.qbsTrace() << "[PR] resolveProduct " << product->uniqueName(); m_productsByName.insert(product->uniqueName(), product); product->enabled = m_evaluator->boolValue(item, QLatin1String("condition")); - const ModuleLoaderResult::ProductInfo &pi = m_loadResult.productInfos.value(item); + ModuleLoaderResult::ProductInfo &pi = m_loadResult.productInfos[item]; if (pi.delayedError.hasError()) { if (product->enabled) { switch (m_setupParams.productErrorMode()) { @@ -357,9 +378,14 @@ void ProjectResolver::resolveProduct(Item *item, ProjectContext *projectContext) product->enabled = false; break; case ErrorHandlingMode::Strict: - throw pi.delayedError; + { + ErrorInfo errorInfo; + std::swap(pi.delayedError, errorInfo); + throw errorInfo; + } } } + pi.delayedError.clear(); return; } product->fileTags = m_evaluator->fileTagsValue(item, QLatin1String("type")); diff --git a/src/lib/corelib/language/projectresolver.h b/src/lib/corelib/language/projectresolver.h index d2768959d..cd5d5fe6b 100644 --- a/src/lib/corelib/language/projectresolver.h +++ b/src/lib/corelib/language/projectresolver.h @@ -141,7 +141,7 @@ private: mutable QHash<std::pair<QStringRef, QStringList>, QString> m_scriptFunctions; mutable QHash<QStringRef, QString> m_sourceCode; const SetupProjectParameters &m_setupParams; - const ModuleLoaderResult &m_loadResult; + ModuleLoaderResult m_loadResult; Set<CodeLocation> m_groupLocationWarnings; qint64 m_elapsedTimeModPropEval; qint64 m_elapsedTimeAllPropEval; diff --git a/src/lib/corelib/tools/error.cpp b/src/lib/corelib/tools/error.cpp index 82e351611..6ebee2879 100644 --- a/src/lib/corelib/tools/error.cpp +++ b/src/lib/corelib/tools/error.cpp @@ -208,6 +208,11 @@ void ErrorInfo::appendBacktrace(const QString &description, const CodeLocation & d->items.append(ErrorItem(description, location, true)); } +void ErrorInfo::append(const ErrorItem &item) +{ + d->items.append(item); +} + void ErrorInfo::append(const QString &description, const CodeLocation &location) { d->items.append(ErrorItem(description, location)); @@ -277,4 +282,11 @@ void ErrorInfo::store(Internal::PersistentPool &pool) const pool.store(d->internalError); } +void appendError(ErrorInfo &dst, const ErrorInfo &src) +{ + const QList<ErrorItem> &sourceItems = src.items(); + for (const ErrorItem &item : sourceItems) + dst.append(item); +} + } // namespace qbs diff --git a/src/lib/corelib/tools/error.h b/src/lib/corelib/tools/error.h index 93a42f90d..a6a5711cb 100644 --- a/src/lib/corelib/tools/error.h +++ b/src/lib/corelib/tools/error.h @@ -91,6 +91,7 @@ public: ~ErrorInfo(); void appendBacktrace(const QString &description, const CodeLocation &location = CodeLocation()); + void append(const ErrorItem &item); void append(const QString &description, const CodeLocation &location = CodeLocation()); void prepend(const QString &description, const CodeLocation &location = CodeLocation()); QList<ErrorItem> items() const; @@ -107,6 +108,7 @@ private: QSharedDataPointer<ErrorInfoPrivate> d; }; +void appendError(ErrorInfo &dst, const ErrorInfo &src); inline uint qHash(const ErrorInfo &e) { return qHash(e.toString()); } inline bool operator==(const ErrorInfo &e1, const ErrorInfo &e2) { return e1.toString() == e2.toString(); |