Add support for scanning qrc files in qmlimportscanner
This reuses the ResourceFileMapper and extends it slightly to return full paths on request. Subsequently, this is moved into a shared directory inside tools. Fixes: QTBUG-55259 Change-Id: Ice5fc68d03b767a4185742e182556ab4290bd28d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
45652a0491
commit
fbc463e84d
|
@ -5,8 +5,10 @@ DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
|
|||
|
||||
SOURCES = qmlcachegen.cpp \
|
||||
resourcefilter.cpp \
|
||||
generateloader.cpp \
|
||||
resourcefilemapper.cpp
|
||||
generateloader.cpp
|
||||
|
||||
include(../shared/shared.pri)
|
||||
|
||||
TARGET = qmlcachegen
|
||||
|
||||
build_integration.files = qmlcache.prf qtquickcompiler.prf
|
||||
|
@ -38,5 +40,3 @@ QMAKE_TARGET_DESCRIPTION = QML Cache Generator
|
|||
|
||||
load(qt_tool)
|
||||
|
||||
HEADERS += \
|
||||
resourcefilemapper.h
|
||||
|
|
|
@ -49,6 +49,8 @@
|
|||
#include <QtCore/QJsonDocument>
|
||||
#include <QtCore/QLibraryInfo>
|
||||
|
||||
#include <resourcefilemapper.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -80,7 +82,8 @@ void printUsage(const QString &appNameIn)
|
|||
#endif
|
||||
std::wcerr
|
||||
<< "Usage: " << appName << " -rootPath path/to/app/qml/directory -importPath path/to/qt/qml/directory\n"
|
||||
" " << appName << " -qmlFiles file1 file2 -importPath path/to/qt/qml/directory\n\n"
|
||||
" " << appName << " -qmlFiles file1 file2 -importPath path/to/qt/qml/directory\n"
|
||||
" " << appName << " -qrcFiles file1.qrc file2.qrc -importPath path/to/qt/qml/directory\n\n"
|
||||
"Example: " << appName << " -rootPath . -importPath "
|
||||
<< QDir::toNativeSeparators(qmlPath).toStdWString()
|
||||
<< '\n';
|
||||
|
@ -542,6 +545,7 @@ int main(int argc, char *argv[])
|
|||
QStringList qmlRootPaths;
|
||||
QStringList scanFiles;
|
||||
QStringList qmlImportPaths;
|
||||
QStringList qrcFiles;
|
||||
bool generateCmakeContent = false;
|
||||
|
||||
int i = 1;
|
||||
|
@ -569,6 +573,8 @@ int main(int argc, char *argv[])
|
|||
argReceiver = &qmlImportPaths;
|
||||
} else if (arg == QLatin1String("-cmake-output")) {
|
||||
generateCmakeContent = true;
|
||||
} else if (arg == QLatin1String("-qrcFiles")) {
|
||||
argReceiver = &qrcFiles;
|
||||
} else {
|
||||
std::cerr << qPrintable(appName) << ": Invalid argument: \""
|
||||
<< qPrintable(arg) << "\"\n";
|
||||
|
@ -590,6 +596,9 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if (!qrcFiles.isEmpty())
|
||||
scanFiles << ResourceFileMapper(qrcFiles).qmlCompilerFiles(ResourceFileMapper::FileOutput::AbsoluteFilePath);
|
||||
|
||||
g_qmlImportPaths = qmlImportPaths;
|
||||
|
||||
// Find the imports!
|
||||
|
|
|
@ -4,6 +4,7 @@ QT = core qmldevtools-private
|
|||
DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
|
||||
|
||||
SOURCES += main.cpp
|
||||
include(../shared/shared.pri)
|
||||
|
||||
load(cmake_functions)
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ QStringList ResourceFileMapper::resourcePaths(const QString &fileName)
|
|||
return resourcePaths;
|
||||
}
|
||||
|
||||
QStringList ResourceFileMapper::qmlCompilerFiles() const
|
||||
QStringList ResourceFileMapper::qmlCompilerFiles(FileOutput fo) const
|
||||
{
|
||||
QStringList files;
|
||||
for (auto it = qrcPathToFileSystemPath.constBegin(), end = qrcPathToFileSystemPath.constEnd();
|
||||
|
@ -67,7 +67,10 @@ QStringList ResourceFileMapper::qmlCompilerFiles() const
|
|||
const QString suffix = QFileInfo(qrcPath).suffix();
|
||||
if (suffix != QStringLiteral("qml") && suffix != QStringLiteral("js") && suffix != QStringLiteral("mjs"))
|
||||
continue;
|
||||
files << qrcPath;
|
||||
if (fo == FileOutput::AbsoluteFilePath)
|
||||
files << it.value();
|
||||
else
|
||||
files << qrcPath;
|
||||
}
|
||||
return files;
|
||||
}
|
|
@ -34,12 +34,16 @@
|
|||
|
||||
struct ResourceFileMapper
|
||||
{
|
||||
enum class FileOutput {
|
||||
RelativeFilePath,
|
||||
AbsoluteFilePath
|
||||
};
|
||||
ResourceFileMapper(const QStringList &resourceFiles);
|
||||
|
||||
bool isEmpty() const;
|
||||
|
||||
QStringList resourcePaths(const QString &fileName);
|
||||
QStringList qmlCompilerFiles() const;
|
||||
QStringList qmlCompilerFiles(FileOutput fo = FileOutput::RelativeFilePath) const;
|
||||
|
||||
private:
|
||||
void populateFromQrcFile(QFile &file);
|
|
@ -0,0 +1,3 @@
|
|||
INCLUDEPATH += $$PWD
|
||||
SOURCES += $$PWD/resourcefilemapper.cpp
|
||||
HEADERS += $$PWD/resourcefilemapper.h
|
Loading…
Reference in New Issue