Skip to content

Commit

Permalink
Fix building with Qt 6.8
Browse files Browse the repository at this point in the history
QAbstractFileEngine interface has changed. Fixed so that IFW will build
with Qt6.8, and also with Qt6.6

QJSEngine no longer returns array for QVariantList, thus the changes in
the scriptengine test, see QTBUG-125289

Task-number: QTIFW-3507
Change-Id: Ida28fcfed63698c61066cdae31b9e7c4268774ea
Reviewed-by: Arttu Tarkiainen <[email protected]>
  • Loading branch information
kahema committed Oct 4, 2024
1 parent c372ed8 commit d24e8c2
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 37 deletions.
99 changes: 84 additions & 15 deletions src/libs/installer/binaryformatengine.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**************************************************************************
**
** Copyright (C) 2023 The Qt Company Ltd.
** Copyright (C) 2024 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
Expand Down Expand Up @@ -35,27 +35,48 @@ namespace {
class StringListIterator : public QAbstractFileEngineIterator
{
public:
StringListIterator( const QStringList &list, QDir::Filters filters, const QStringList &nameFilters)
StringListIterator(const QString &path, const QStringList &list, QDir::Filters filters, const QStringList &nameFilters)
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
: QAbstractFileEngineIterator(path, filters, nameFilters)
#else
: QAbstractFileEngineIterator(filters, nameFilters)
#endif
, list(list)
, index(-1)
{
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
StringListIterator(const QString &path, const QStringList &list, QDirListing::IteratorFlags filters, const QStringList &nameFilters)

: QAbstractFileEngineIterator(path, filters, nameFilters)
, list(list)
, index(-1)
{
}

bool hasNext() const
bool advance() override
{
if (index < list.size() - 1) {
++index;
return true;
}
return false;
}
#else
bool hasNext() const override
{
return index < list.size() - 1;
}

QString next()
QString next() override
{
if(!hasNext())
return QString();
++index;
return currentFilePath();
}

QString currentFileName() const
#endif
QString currentFileName() const override
{
return index < 0 ? QString() : list[index];
}
Expand Down Expand Up @@ -243,11 +264,50 @@ QAbstractFileEngine::FileFlags BinaryFormatEngine::fileFlags(FileFlags type) con
/*!
\internal
*/
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
QAbstractFileEngine::IteratorUniquePtr
BinaryFormatEngine::beginEntryList(const QString &path, QDir::Filters filters,
const QStringList &filterNames)
{
const QStringList entries = entryList(filters, filterNames);
return std::make_unique<StringListIterator>(path, entries, filters, filterNames);
}

QAbstractFileEngine::IteratorUniquePtr
BinaryFormatEngine::beginEntryList(const QString &path, QDirListing::IteratorFlags filters, const QStringList &filterNames)
{
const QStringList entries = entryList(filters, filterNames);
return std::make_unique<StringListIterator>(path, entries, filters, filterNames);
}

/*!
\internal
*/
QStringList BinaryFormatEngine::entryList(QDirListing::IteratorFlags filters, const QStringList &filterNames) const
{
if (!m_resource.isNull())
return QStringList();

QStringList result;
if (!m_collection.name().isEmpty()
&& (filters.testFlag(QDirListing::IteratorFlag::Default) || filters.testFlag(QDirListing::IteratorFlag::FilesOnly))) {
foreach (const QSharedPointer<Resource> &resource, m_collection.resources())
result.append(QString::fromUtf8(resource->name()));
} else if (m_collection.name().isEmpty()
&& (filters.testFlag(QDirListing::IteratorFlag::Default) || filters.testFlag(QDirListing::IteratorFlag::DirsOnly))) {
foreach (const ResourceCollection &collection, m_collections)
result.append(QString::fromUtf8(collection.name()));
}
return filterResults(result, filterNames);
}
#else
QAbstractFileEngineIterator *BinaryFormatEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames)
{
const QStringList entries = entryList(filters, filterNames);
return new StringListIterator(entries, filters, filterNames);
return new StringListIterator(QString(), entries, filters, filterNames);
}
#endif


/*!
\internal
Expand All @@ -265,6 +325,23 @@ QStringList BinaryFormatEngine::entryList(QDir::Filters filters, const QStringLi
foreach (const ResourceCollection &collection, m_collections)
result.append(QString::fromUtf8(collection.name()));
}
return filterResults(result, filterNames);
}


/*!
\internal
*/
qint64 BinaryFormatEngine::size() const
{
return m_resource.isNull() ? 0 : m_resource->size();
}

/*!
\internal
*/
QStringList BinaryFormatEngine::filterResults(QStringList result, const QStringList &filterNames) const
{
result.removeAll(QString()); // Remove empty names, will crash while using directory iterator.

if (filterNames.isEmpty())
Expand All @@ -291,12 +368,4 @@ QStringList BinaryFormatEngine::entryList(QDir::Filters filters, const QStringLi
return entries;
}

/*!
\internal
*/
qint64 BinaryFormatEngine::size() const
{
return m_resource.isNull() ? 0 : m_resource->size();
}

} // namespace QInstaller
11 changes: 10 additions & 1 deletion src/libs/installer/binaryformatengine.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**************************************************************************
**
** Copyright (C) 2023 The Qt Company Ltd.
** Copyright (C) 2024 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
Expand Down Expand Up @@ -61,9 +61,18 @@ class BinaryFormatEngine : public QAbstractFileEngine
QString fileName(FileName file = DefaultName) const override;
FileFlags fileFlags(FileFlags type = FileInfoAll) const override;

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
IteratorUniquePtr beginEntryList(const QString &path, QDir::Filters filters, const QStringList &filterNames) override;
IteratorUniquePtr beginEntryList(const QString &path, QDirListing::IteratorFlags filters, const QStringList &filterNames) override;
QStringList entryList(QDirListing::IteratorFlags filters, const QStringList &filterNames) const override;
#else
Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override;
#endif
QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const override;

private:
QStringList filterResults(QStringList result, const QStringList &filterNames) const;

private:
QString m_fileNamePath;

Expand Down
10 changes: 9 additions & 1 deletion src/libs/installer/binaryformatenginehandler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Copyright (C) 2024 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
Expand Down Expand Up @@ -45,11 +45,19 @@ namespace QInstaller {
Returns 0 if the engine cannot handle \a fileName.
*/
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
std::unique_ptr<QAbstractFileEngine> BinaryFormatEngineHandler::create(const QString &fileName) const
{
return fileName.startsWith(QLatin1String("installer://"), Qt::CaseInsensitive )
? std::make_unique<BinaryFormatEngine>(m_resources, fileName) : nullptr;
}
#else
QAbstractFileEngine *BinaryFormatEngineHandler::create(const QString &fileName) const
{
return fileName.startsWith(QLatin1String("installer://"), Qt::CaseInsensitive )
? new BinaryFormatEngine(m_resources, fileName) : nullptr;
}
#endif

/*!
Clears the contents of the binary format engine.
Expand Down
5 changes: 4 additions & 1 deletion src/libs/installer/binaryformatenginehandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ class INSTALLER_EXPORT BinaryFormatEngineHandler : public QAbstractFileEngineHan
Q_DISABLE_COPY(BinaryFormatEngineHandler)

public:
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
std::unique_ptr<QAbstractFileEngine> create(const QString &fileName) const;
#else
QAbstractFileEngine *create(const QString &fileName) const;

#endif
void clear();
static BinaryFormatEngineHandler *instance();

Expand Down
75 changes: 62 additions & 13 deletions src/libs/installer/remotefileengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ namespace QInstaller {

// -- RemoteFileEngineHandler

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
std::unique_ptr<QAbstractFileEngine> RemoteFileEngineHandler::create(const QString &fileName) const
#else
QAbstractFileEngine* RemoteFileEngineHandler::create(const QString &fileName) const
#endif
{
if (!RemoteClient::instance().isActive())
return 0;
Expand All @@ -57,34 +61,61 @@ QAbstractFileEngine* RemoteFileEngineHandler::create(const QString &fileName) co

std::unique_ptr<RemoteFileEngine> client(new RemoteFileEngine());
client->setFileName(fileName);
if (client->isConnectedToServer())
if (client->isConnectedToServer()) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
return client;
#else
return client.release();
#endif
}
return 0;
}


// -- RemoteFileEngineIterator

/*!
\class QInstaller::RemoteFileEngineIterator
\inmodule QtInstallerFramework
\internal
*/
class RemoteFileEngineIterator : public QAbstractFileEngineIterator
{
public:
RemoteFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters,
RemoteFileEngineIterator(const QString &path, QDir::Filters filters, const QStringList &nameFilters,
const QStringList &files)
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
: QAbstractFileEngineIterator(path, filters, nameFilters)
#else
: QAbstractFileEngineIterator(filters, nameFilters)
#endif
, index(-1)
, entries(files)
{
}

QString next();
bool hasNext() const;
QString currentFileName() const;
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
bool advance() override;
#else
QString next() override;
bool hasNext() const override;
#endif
QString currentFileName() const override;

private:
qint32 index;
QStringList entries;
};

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
/*!
\reimp
*/
bool RemoteFileEngineIterator::advance()
{
if (index < entries.size() - 1) {
++index;
return true;
}
return false;
}
#else
/*
Advances the iterator to the next entry, and returns the current file path of this new
entry. If hasNext() returns \c false, the function does nothing and returns an empty QString.
Expand All @@ -105,12 +136,15 @@ QString RemoteFileEngineIterator::next()
++index;
return currentFilePath();
}
#endif

/*
Returns the name of the current directory entry, excluding the path.
/*!
\reimp
*/
QString RemoteFileEngineIterator::currentFileName() const
{
if (index < 0 || index > entries.size())
return QString();
return entries.at(index);
}

Expand Down Expand Up @@ -141,19 +175,34 @@ bool RemoteFileEngine::atEnd() const
/*!
\reimp
*/
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
QAbstractFileEngine::IteratorUniquePtr
RemoteFileEngine::beginEntryList(const QString &path, QDir::Filters filters,
const QStringList &filterNames)
#else
QAbstractFileEngine::Iterator* RemoteFileEngine::beginEntryList(QDir::Filters filters,
const QStringList &filterNames)
#endif
{
if (connectToServer()) {
QStringList entries = entryList(filters, filterNames);
entries.removeAll(QString());
return new RemoteFileEngineIterator(filters, filterNames, entries);
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
return std::make_unique<RemoteFileEngineIterator>(path, filters, filterNames, entries);
}
return m_fileEngine.beginEntryList(path, filters, filterNames);
#else
return new RemoteFileEngineIterator(QString(), filters, filterNames, entries);
}
return m_fileEngine.beginEntryList(filters, filterNames);

#endif
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
QAbstractFileEngine::IteratorUniquePtr RemoteFileEngine::endEntryList()
#else
QAbstractFileEngine::Iterator* RemoteFileEngine::endEntryList()
#endif
{
if (connectToServer())
return 0; // right now all other implementations return 0 too
Expand Down
10 changes: 9 additions & 1 deletion src/libs/installer/remotefileengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ class INSTALLER_EXPORT RemoteFileEngineHandler : public QAbstractFileEngineHandl

public:
RemoteFileEngineHandler() : QAbstractFileEngineHandler() {}
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
std::unique_ptr<QAbstractFileEngine> create(const QString &fileName) const override;
#else
QAbstractFileEngine* create(const QString &fileName) const override;
#endif
};

class RemoteFileEngine : public RemoteObject, public QAbstractFileEngine
Expand Down Expand Up @@ -97,9 +101,13 @@ class RemoteFileEngine : public RemoteObject, public QAbstractFileEngine
bool atEnd() const;
uchar *map(qint64, qint64, QFile::MemoryMapFlags) { return 0; }
bool unmap(uchar *) { return true; }

#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
IteratorUniquePtr beginEntryList(const QString &path, QDir::Filters filters, const QStringList &filterNames) override;
IteratorUniquePtr endEntryList() override;
#else
Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override;
Iterator *endEntryList() override;
#endif

qint64 read(char *data, qint64 maxlen) override;
qint64 readLine(char *data, qint64 maxlen) override;
Expand Down
Loading

0 comments on commit d24e8c2

Please sign in to comment.