summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLucie GĂ©rard <lucie.gerard@qt.io>2021-06-16 10:39:42 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-30 13:05:46 +0000
commit0e2ccdf0df7b97f41164e9bd07878540bbcb6354 (patch)
treeb407fe4ac599a73a3d5610e70a90e7cbd01a8660 /src
parent2cba25343e18bdc0cb44a7a6684e340e67cd86fc (diff)
lupdate/clang: Make sure warning are printed in consistent order
This is for the QT_TR_NOOP case, when the call is ignored because context could not be found Change-Id: I4d00547da8de5970cc5a5decb90ab467fc2961e8 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit 1af073702f2af44ac1c5180822d2202e6b4a9805) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/linguist/lupdate/clangtoolastreader.cpp24
-rw-r--r--src/linguist/lupdate/cpp_clang.cpp29
-rw-r--r--src/linguist/lupdate/cpp_clang.h5
-rw-r--r--src/linguist/shared/translatormessage.h4
4 files changed, 41 insertions, 21 deletions
diff --git a/src/linguist/lupdate/clangtoolastreader.cpp b/src/linguist/lupdate/clangtoolastreader.cpp
index ba91f49fa..8aac00ddf 100644
--- a/src/linguist/lupdate/clangtoolastreader.cpp
+++ b/src/linguist/lupdate/clangtoolastreader.cpp
@@ -840,22 +840,14 @@ void LupdateVisitor::generateOuput()
{
qCDebug(lcClang) << "=================m_trCallserateOuput============================";
m_noopTranslationMacroAll.erase(std::remove_if(m_noopTranslationMacroAll.begin(),
- m_noopTranslationMacroAll.end(), [this](const TranslationRelatedStore &store) {
- // only fill if a context has been retrieved in the file we're currently visiting
- // emit warning if both context are empty
- // do not emit warning if the Macro is from a different input file, it's normal the context was not found.
- if ( m_inputFile != qPrintable(store.lupdateLocationFile))
- return true;
- if (store.contextRetrieved.isEmpty() && store.contextArg.isEmpty()
- && !store.funcName.contains(QLatin1String("QT_TRID"))) {
- std::cerr << qPrintable(store.lupdateLocationFile) << ":";
- std::cerr << store.lupdateLocationLine << ":";
- std::cerr << store.locationCol << ": ";
- std::cerr << " \'" << qPrintable(store.funcName) << "\' cannot be called without context.";
- std::cerr << " The call is ignored (missing Q_OBJECT maybe?)\n";
- }
- return store.contextRetrieved.isEmpty() && store.contextArg.isEmpty()
- && !store.funcName.contains(QLatin1String("QT_TRID"));
+ m_noopTranslationMacroAll.end(), [this](const TranslationRelatedStore &store) {
+ // Macros not located in the currently visited file are missing context (and it's normal),
+ // so an output is only generated for macros present in the currently visited file.
+ // If context could not be found, it is warned against in ClangCppParser::collectMessages
+ // (where it is possible to order the warnings and print them consistantly)
+ if ( m_inputFile != qPrintable(store.lupdateLocationFile))
+ return true;
+ return false;
}), m_noopTranslationMacroAll.end());
m_stores->QNoopTranlsationWithContext.emplace_bulk(std::move(m_noopTranslationMacroAll));
diff --git a/src/linguist/lupdate/cpp_clang.cpp b/src/linguist/lupdate/cpp_clang.cpp
index aa4d22098..f613431c7 100644
--- a/src/linguist/lupdate/cpp_clang.cpp
+++ b/src/linguist/lupdate/cpp_clang.cpp
@@ -433,6 +433,8 @@ void ClangCppParser::loadCPP(Translator &translator, const QStringList &files, C
for (TranslatorMessage &msg : messages) {
if (!msg.warning().isEmpty()) {
std::cerr << qPrintable(msg.warning());
+ if (msg.warningOnly() == true)
+ continue;
}
translator.extend(std::move(msg), cd);
}
@@ -467,9 +469,20 @@ void ClangCppParser::collectMessages(TranslatorMessageVector &result,
store.lupdateWarning.append(QString::fromStdString(warning.str()));
qCDebug(lcClang) << "//% is ignored when using tr function\n";
}
- if (store.contextRetrieved.isEmpty() && store.contextArg.isEmpty())
+ if (store.contextRetrieved.isEmpty() && store.contextArg.isEmpty()) {
+ std::stringstream warning;
+ warning << qPrintable(store.lupdateLocationFile) << ":"
+ << store.lupdateLocationLine << ":"
+ << store.locationCol << ": "
+ << qPrintable(store.funcName) << " cannot be called without context."
+ << " The call is ignored (missing Q_OBJECT maybe?)\n";
+ store.lupdateWarning.append(QString::fromStdString(warning.str()));
qCDebug(lcClang) << "tr() cannot be called without context \n";
- else
+ // The message need to be added to the results so that the warning can be ordered
+ // and printed in a consistent way.
+ // the message won't appear in the .ts file
+ result.push_back(translatorMessage(store, store.lupdateIdMetaData, plural, false, true));
+ } else
result.push_back(translatorMessage(store, store.lupdateIdMetaData, plural, false));
break;
@@ -528,8 +541,18 @@ static QString ensureCanonicalPath(const QString &filePath)
}
TranslatorMessage ClangCppParser::translatorMessage(const TranslationRelatedStore &store,
- const QString &id, bool plural, bool isId)
+ const QString &id, bool plural, bool isId, bool isWarningOnly)
{
+ if (isWarningOnly) {
+ TranslatorMessage msg;
+ // msg filled with file name and line number should be enough for the message ordering
+ msg.setFileName(ensureCanonicalPath(store.lupdateLocationFile));
+ msg.setLineNumber(store.lupdateLocationLine);
+ msg.setWarning(store.lupdateWarning);
+ msg.setWarningOnly(isWarningOnly);
+ return msg;
+ }
+
QString context;
if (!isId) {
context = ParserTool::transcode(store.contextArg.isEmpty() ? store.contextRetrieved
diff --git a/src/linguist/lupdate/cpp_clang.h b/src/linguist/lupdate/cpp_clang.h
index 4e6829f4b..eeab83b9b 100644
--- a/src/linguist/lupdate/cpp_clang.h
+++ b/src/linguist/lupdate/cpp_clang.h
@@ -234,7 +234,8 @@ struct Stores
TranslationStores Preprocessor;
WriteSynchronizedRef<TranslationRelatedStore> AST;
WriteSynchronizedRef<TranslationRelatedStore> QDeclareTrWithContext;
- WriteSynchronizedRef<TranslationRelatedStore> QNoopTranlsationWithContext;
+ WriteSynchronizedRef<TranslationRelatedStore> QNoopTranlsationWithContext; // or with warnings that need to be
+ //displayed in the same order, always
};
namespace LupdatePrivate
@@ -320,7 +321,7 @@ namespace ClangCppParser
using TranslatorMessageVector = std::vector<TranslatorMessage>;
void collectMessages(TranslatorMessageVector &result, TranslationRelatedStore &store);
TranslatorMessage translatorMessage(const TranslationRelatedStore &store,
- const QString &id, bool plural, bool isID);
+ const QString &id, bool plural, bool isID, bool isWarningOnly = false);
void correctAstTranslationContext(ReadSynchronizedRef<TranslationRelatedStore> &ast,
WriteSynchronizedRef<TranslationRelatedStore> &newAst, const TranslationStores &qDecl);
diff --git a/src/linguist/shared/translatormessage.h b/src/linguist/shared/translatormessage.h
index 85059f4f9..aa7431b78 100644
--- a/src/linguist/shared/translatormessage.h
+++ b/src/linguist/shared/translatormessage.h
@@ -131,6 +131,9 @@ public:
void setExtras(const ExtraData &extras) { m_extra = extras; }
void unsetExtra(const QString &key);
+ bool warningOnly() const { return m_warningOnly; }
+ void setWarningOnly(bool isWarningOnly) { m_warningOnly = isWarningOnly; }
+
void dump() const;
private:
@@ -149,6 +152,7 @@ private:
QString m_fileName;
int m_lineNumber;
References m_extraRefs;
+ bool m_warningOnly = false;
Type m_type;
bool m_plural;