From 15148d8e4454ff3277131ea52a4204c5fa0b7ab0 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 30 Nov 2016 18:26:44 +0100 Subject: [PATCH] ProParser: Use the "Default Codec" when reading qmake files This change adds a QTextCodec* member to QMakeVfs. It is used to decode the qmake file contents in QMakeVfs::readFile. The QMakeProjectManager sets it to the current "Default Codec". This is necessary only in Qt Creator, where the parser would actually use Local8Bit (unlike qmake's Latin1), which would sometimes lead to misinterpreted multi-byte chars in comments swallowing newlines and thus falsifying the actual code. Bootstrapped qmake is not affected by this addition. Task-number: QTCREATORBUG-17309 Change-Id: I34b42bd19e0de973deb2291e91f306d1ca7c630e Reviewed-by: Oswald Buddenhagen --- .../qmakeprojectmanager/qmakeproject.cpp | 4 ++++ src/shared/proparser/qmakevfs.cpp | 20 ++++++++++++++++++- src/shared/proparser/qmakevfs.h | 11 ++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp index 2bce60f5dfb..3841339ef88 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp @@ -35,6 +35,7 @@ #include "findqmakeprofiles.h" #include +#include #include #include #include @@ -263,6 +264,9 @@ QmakeProject::QmakeProject(QmakeManager *manager, const QString &fileName) : setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX)); setRequiredKitMatcher(QtSupport::QtKitInformation::qtVersionMatcher()); + const QTextCodec *codec = Core::EditorManager::defaultTextCodec(); + m_qmakeVfs->setTextCodec(codec); + m_asyncUpdateTimer.setSingleShot(true); m_asyncUpdateTimer.setInterval(3000); connect(&m_asyncUpdateTimer, &QTimer::timeout, this, &QmakeProject::asyncUpdate); diff --git a/src/shared/proparser/qmakevfs.cpp b/src/shared/proparser/qmakevfs.cpp index 6115a024572..4dd1192aff7 100644 --- a/src/shared/proparser/qmakevfs.cpp +++ b/src/shared/proparser/qmakevfs.cpp @@ -32,6 +32,10 @@ using namespace QMakeInternal; #include #include +#ifndef QT_NO_TEXTCODEC +#include +#endif + #define fL1S(s) QString::fromLatin1(s) QT_BEGIN_NAMESPACE @@ -42,6 +46,9 @@ QMakeVfs::QMakeVfs() , m_magicExisting(fL1S("existing")) #endif { +#ifndef QT_NO_TEXTCODEC + m_textCodec = 0; +#endif } bool QMakeVfs::writeFile(const QString &fn, QIODevice::OpenMode mode, VfsFlags flags, @@ -184,7 +191,11 @@ QMakeVfs::ReadResult QMakeVfs::readFile( *errStr = fL1S("Unexpected UTF-8 BOM"); return ReadOtherError; } - *contents = QString::fromLocal8Bit(bcont); + *contents = +#ifndef QT_NO_TEXTCODEC + m_textCodec ? m_textCodec->toUnicode(bcont) : +#endif + QString::fromLocal8Bit(bcont); return ReadOk; } @@ -242,4 +253,11 @@ void QMakeVfs::invalidateContents() } #endif +#ifndef QT_NO_TEXTCODEC +void QMakeVfs::setTextCodec(const QTextCodec *textCodec) +{ + m_textCodec = textCodec; +} +#endif + QT_END_NAMESPACE diff --git a/src/shared/proparser/qmakevfs.h b/src/shared/proparser/qmakevfs.h index 02c0a6406b4..b6b93fb5dd5 100644 --- a/src/shared/proparser/qmakevfs.h +++ b/src/shared/proparser/qmakevfs.h @@ -36,6 +36,10 @@ # endif #endif +#ifndef QT_NO_TEXTCODEC +QT_FORWARD_DECLARE_CLASS(QTextCodec) +#endif + #ifdef PROEVALUATOR_DUAL_VFS # ifndef PROEVALUATOR_CUMULATIVE # error PROEVALUATOR_DUAL_VFS requires PROEVALUATOR_CUMULATIVE @@ -79,6 +83,10 @@ public: void invalidateContents(); #endif +#ifndef QT_NO_TEXTCODEC + void setTextCodec(const QTextCodec *textCodec); +#endif + private: #ifndef PROEVALUATOR_FULL # ifdef PROEVALUATOR_THREAD_SAFE @@ -88,6 +96,9 @@ private: QString m_magicMissing; QString m_magicExisting; #endif +#ifndef QT_NO_TEXTCODEC + const QTextCodec *m_textCodec; +#endif }; Q_DECLARE_OPERATORS_FOR_FLAGS(QMakeVfs::VfsFlags)