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 <oswald.buddenhagen@qt.io>
This commit is contained in:
Alessandro Portale
2016-11-30 18:26:44 +01:00
parent a228ad7e49
commit 15148d8e44
3 changed files with 34 additions and 1 deletions

View File

@@ -35,6 +35,7 @@
#include "findqmakeprofiles.h" #include "findqmakeprofiles.h"
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icontext.h> #include <coreplugin/icontext.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
@@ -263,6 +264,9 @@ QmakeProject::QmakeProject(QmakeManager *manager, const QString &fileName) :
setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX)); setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
setRequiredKitMatcher(QtSupport::QtKitInformation::qtVersionMatcher()); setRequiredKitMatcher(QtSupport::QtKitInformation::qtVersionMatcher());
const QTextCodec *codec = Core::EditorManager::defaultTextCodec();
m_qmakeVfs->setTextCodec(codec);
m_asyncUpdateTimer.setSingleShot(true); m_asyncUpdateTimer.setSingleShot(true);
m_asyncUpdateTimer.setInterval(3000); m_asyncUpdateTimer.setInterval(3000);
connect(&m_asyncUpdateTimer, &QTimer::timeout, this, &QmakeProject::asyncUpdate); connect(&m_asyncUpdateTimer, &QTimer::timeout, this, &QmakeProject::asyncUpdate);

View File

@@ -32,6 +32,10 @@ using namespace QMakeInternal;
#include <qfile.h> #include <qfile.h>
#include <qfileinfo.h> #include <qfileinfo.h>
#ifndef QT_NO_TEXTCODEC
#include <qtextcodec.h>
#endif
#define fL1S(s) QString::fromLatin1(s) #define fL1S(s) QString::fromLatin1(s)
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@@ -42,6 +46,9 @@ QMakeVfs::QMakeVfs()
, m_magicExisting(fL1S("existing")) , m_magicExisting(fL1S("existing"))
#endif #endif
{ {
#ifndef QT_NO_TEXTCODEC
m_textCodec = 0;
#endif
} }
bool QMakeVfs::writeFile(const QString &fn, QIODevice::OpenMode mode, VfsFlags flags, 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"); *errStr = fL1S("Unexpected UTF-8 BOM");
return ReadOtherError; return ReadOtherError;
} }
*contents = QString::fromLocal8Bit(bcont); *contents =
#ifndef QT_NO_TEXTCODEC
m_textCodec ? m_textCodec->toUnicode(bcont) :
#endif
QString::fromLocal8Bit(bcont);
return ReadOk; return ReadOk;
} }
@@ -242,4 +253,11 @@ void QMakeVfs::invalidateContents()
} }
#endif #endif
#ifndef QT_NO_TEXTCODEC
void QMakeVfs::setTextCodec(const QTextCodec *textCodec)
{
m_textCodec = textCodec;
}
#endif
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@@ -36,6 +36,10 @@
# endif # endif
#endif #endif
#ifndef QT_NO_TEXTCODEC
QT_FORWARD_DECLARE_CLASS(QTextCodec)
#endif
#ifdef PROEVALUATOR_DUAL_VFS #ifdef PROEVALUATOR_DUAL_VFS
# ifndef PROEVALUATOR_CUMULATIVE # ifndef PROEVALUATOR_CUMULATIVE
# error PROEVALUATOR_DUAL_VFS requires PROEVALUATOR_CUMULATIVE # error PROEVALUATOR_DUAL_VFS requires PROEVALUATOR_CUMULATIVE
@@ -79,6 +83,10 @@ public:
void invalidateContents(); void invalidateContents();
#endif #endif
#ifndef QT_NO_TEXTCODEC
void setTextCodec(const QTextCodec *textCodec);
#endif
private: private:
#ifndef PROEVALUATOR_FULL #ifndef PROEVALUATOR_FULL
# ifdef PROEVALUATOR_THREAD_SAFE # ifdef PROEVALUATOR_THREAD_SAFE
@@ -88,6 +96,9 @@ private:
QString m_magicMissing; QString m_magicMissing;
QString m_magicExisting; QString m_magicExisting;
#endif #endif
#ifndef QT_NO_TEXTCODEC
const QTextCodec *m_textCodec;
#endif
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(QMakeVfs::VfsFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(QMakeVfs::VfsFlags)