aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmltc
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2022-01-24 13:46:58 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-02-03 08:46:02 +0000
commit4cbbe17dedd0274e0e46c523d0f868a87ae7e957 (patch)
treeb7394e8e609a453cf0eddaf1571408d40a5a9800 /tools/qmltc
parent1140e5551ebb6f67252ba4af193015e5d4ceaaf0 (diff)
qmltc: Rely on QQmlJSResourceFileMapper
Similarly to qmllint, we should use QQmlJSResourceFileMapper in qmltc. This should in theory allow us to avoid implicit import dir vs qmldir path issues (where the former comes from source dir while the latter comes from build dir) At present, it does not seem to be the case, however. But this is to be addressed separately Task-number: QTBUG-100103 Change-Id: Ie85799cb0a4b8b1620964000bc5939e9d046678e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 8a72c684464a48595337b01ada5605f612f7971e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tools/qmltc')
-rw-r--r--tools/qmltc/main.cpp44
1 files changed, 38 insertions, 6 deletions
diff --git a/tools/qmltc/main.cpp b/tools/qmltc/main.cpp
index 8ae320c79e..5851f0d7ac 100644
--- a/tools/qmltc/main.cpp
+++ b/tools/qmltc/main.cpp
@@ -33,6 +33,7 @@
#include <QtQml/private/qqmlirbuilder_p.h>
#include <private/qqmljscompiler_p.h>
+#include <private/qqmljsresourcefilemapper_p.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qurl.h>
@@ -86,6 +87,7 @@ int main(int argc, char **argv)
QCoreApplication::translate("main", "h path")
};
parser.addOption(outputHOption);
+
QCommandLineOption resourcePathOption {
u"resource-path"_qs,
QCoreApplication::translate(
@@ -93,6 +95,13 @@ int main(int argc, char **argv)
QCoreApplication::translate("main", "resource path")
};
parser.addOption(resourcePathOption);
+ QCommandLineOption resourceOption {
+ u"resource"_qs,
+ QCoreApplication::translate(
+ "main", "Qt resource file that might later contain one of the compiled files"),
+ QCoreApplication::translate("main", "resource file name")
+ };
+ parser.addOption(resourceOption);
QCommandLineOption namespaceOption {
u"namespace"_qs, QCoreApplication::translate("main", "Namespace of the generated C++ code"),
QCoreApplication::translate("main", "namespace")
@@ -132,7 +141,6 @@ int main(int argc, char **argv)
QStringList importPaths = parser.values(importPathOption);
importPaths.append(QLibraryInfo::path(QLibraryInfo::QmlImportsPath));
- importPaths.append(QFileInfo(url).absolutePath());
QStringList qmldirFiles = parser.values(qmldirOption);
QString outputCppFile;
@@ -149,8 +157,8 @@ int main(int argc, char **argv)
outputHFile = parser.value(outputHOption);
}
- if (!parser.isSet(resourcePathOption)) {
- fprintf(stderr, "No resource path for file: %s\n", qPrintable(inputFile));
+ if (!parser.isSet(resourceOption) && !parser.isSet(resourcePathOption)) {
+ fprintf(stderr, "No resource paths for file: %s\n", qPrintable(inputFile));
return EXIT_FAILURE;
}
@@ -164,19 +172,43 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
+ const QStringList resourceFiles = parser.values(resourceOption);
+ QQmlJSResourceFileMapper mapper(resourceFiles);
+
+ // verify that we can map current file to qrc (then use the qrc path later)
+ const QStringList paths = mapper.resourcePaths(QQmlJSResourceFileMapper::localFileFilter(url));
+ QString resolvedResourcePath;
+ if (paths.size() != 1) {
+ if (parser.isSet(resourcePathOption)) {
+ qWarning("--resource-path option is deprecated. Prefer --resource along with "
+ "automatically generated resource file");
+ resolvedResourcePath = parser.value(resourcePathOption);
+ } else if (paths.isEmpty()) {
+ fprintf(stderr, "Failed to find a resource path for file: %s\n", qPrintable(inputFile));
+ return EXIT_FAILURE;
+ } else if (paths.size() > 1) {
+ fprintf(stderr, "Too many (expected 1) resource paths for file: %s\n",
+ qPrintable(inputFile));
+ return EXIT_FAILURE;
+ }
+ } else {
+ resolvedResourcePath = paths.first();
+ }
+
Options options;
options.outputCppFile = parser.value(outputCppOption);
options.outputHFile = parser.value(outputHOption);
- options.resourcePath = parser.value(resourcePathOption);
+ options.resourcePath = resolvedResourcePath;
options.outNamespace = parser.value(namespaceOption);
- QQmlJSImporter importer { importPaths, /* resource file mapper */ nullptr };
+ QQmlJSImporter importer { importPaths, &mapper };
QQmlJSLogger logger;
logger.setFileName(url);
logger.setCode(sourceCode);
setupLogger(logger);
- Qmltc::Visitor visitor(&importer, &logger, implicitImportDirectory, qmldirFiles);
+ Qmltc::Visitor visitor(&importer, &logger,
+ QQmlJSImportVisitor::implicitImportDirectory(url, &mapper), qmldirFiles);
Qmltc::TypeResolver typeResolver { &importer };
typeResolver.init(visitor, document.program);