aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmlcachegen/qmlcachegen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/qmlcachegen/qmlcachegen.cpp')
-rw-r--r--tools/qmlcachegen/qmlcachegen.cpp116
1 files changed, 83 insertions, 33 deletions
diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp
index 29fe609469..3648a10f95 100644
--- a/tools/qmlcachegen/qmlcachegen.cpp
+++ b/tools/qmlcachegen/qmlcachegen.cpp
@@ -36,6 +36,8 @@
#include <QSaveFile>
#include <QScopedPointer>
#include <QScopeGuard>
+#include <QLibraryInfo>
+#include <QLoggingCategory>
#include <private/qqmlirbuilder_p.h>
#include <private/qqmljsparser_p.h>
@@ -47,7 +49,9 @@
#include <algorithm>
-using namespace QQmlJS;
+QT_BEGIN_NAMESPACE
+Q_DECLARE_LOGGING_CATEGORY(lcAotCompiler);
+QT_END_NAMESPACE
static bool argumentsFromCommandLineAndFile(QStringList& allArguments, const QStringList &arguments)
{
@@ -106,12 +110,21 @@ int main(int argc, char **argv)
QCommandLineOption directCallsOption(QStringLiteral("direct-calls"), QCoreApplication::translate("main", "This option is ignored."));
directCallsOption.setFlags(QCommandLineOption::HiddenFromHelp);
parser.addOption(directCallsOption);
- QCommandLineOption includesOption(QStringLiteral("i"), QCoreApplication::translate("main", "This option is ignored."), QCoreApplication::translate("main", "ignored file"));
- includesOption.setFlags(QCommandLineOption::HiddenFromHelp);
- parser.addOption(includesOption);
- QCommandLineOption importPathOption(QStringLiteral("I"), QCoreApplication::translate("main", "This option is ignored."), QCoreApplication::translate("main", "ignored path"));
- importPathOption.setFlags(QCommandLineOption::HiddenFromHelp);
+ QCommandLineOption importsOption(
+ QStringLiteral("i"),
+ QCoreApplication::translate("main", "Import extra qmltypes"),
+ QCoreApplication::translate("main", "qmltypes file"));
+ parser.addOption(importsOption);
+ QCommandLineOption importPathOption(
+ QStringLiteral("I"),
+ QCoreApplication::translate("main", "Look for QML modules in specified directory"),
+ QCoreApplication::translate("main", "import directory"));
parser.addOption(importPathOption);
+ QCommandLineOption onlyBytecode(
+ QStringLiteral("only-bytecode"),
+ QCoreApplication::translate(
+ "main", "Generate only byte code for bindings and functions, no C++ code"));
+ parser.addOption(onlyBytecode);
QCommandLineOption outputFileOption(QStringLiteral("o"), QCoreApplication::translate("main", "Output file name"), QCoreApplication::translate("main", "file name"));
parser.addOption(outputFileOption);
@@ -188,35 +201,34 @@ int main(int argc, char **argv)
QString inputFileUrl = inputFile;
QQmlJSSaveFunction saveFunction;
- if (target == GenerateCpp) {
- QQmlJSResourceFileMapper fileMapper(parser.values(resourceOption));
- QString inputResourcePath = parser.value(resourcePathOption);
-
- // If the user didn't specify the resource path corresponding to the file on disk being
- // compiled, try to determine it from the resource file, if one was supplied.
- if (inputResourcePath.isEmpty()) {
- const QStringList resourcePaths = fileMapper.resourcePaths(
- QQmlJSResourceFileMapper::localFileFilter(inputFile));
- if (resourcePaths.isEmpty()) {
- fprintf(stderr, "No resource path for file: %s\n", qPrintable(inputFile));
- return EXIT_FAILURE;
- }
-
- if (resourcePaths.size() != 1) {
- fprintf(stderr, "Multiple resource paths for file %s. "
- "Use the --%s option to disambiguate:\n",
- qPrintable(inputFile),
- qPrintable(resourcePathOption.names().first()));
- for (const QString &resourcePath: resourcePaths)
- fprintf(stderr, "\t%s\n", qPrintable(resourcePath));
- return EXIT_FAILURE;
- }
+ QQmlJSResourceFileMapper fileMapper(parser.values(resourceOption));
+ QString inputResourcePath = parser.value(resourcePathOption);
+
+ // If the user didn't specify the resource path corresponding to the file on disk being
+ // compiled, try to determine it from the resource file, if one was supplied.
+ if (inputResourcePath.isEmpty()) {
+ const QStringList resourcePaths = fileMapper.resourcePaths(
+ QQmlJSResourceFileMapper::localFileFilter(inputFile));
+ if (target == GenerateCpp && resourcePaths.isEmpty()) {
+ fprintf(stderr, "No resource path for file: %s\n", qPrintable(inputFile));
+ return EXIT_FAILURE;
+ }
+ if (resourcePaths.size() == 1) {
inputResourcePath = resourcePaths.first();
+ } else if (target == GenerateCpp) {
+ fprintf(stderr, "Multiple resource paths for file %s. "
+ "Use the --%s option to disambiguate:\n",
+ qPrintable(inputFile),
+ qPrintable(resourcePathOption.names().first()));
+ for (const QString &resourcePath: resourcePaths)
+ fprintf(stderr, "\t%s\n", qPrintable(resourcePath));
+ return EXIT_FAILURE;
}
+ }
+ if (target == GenerateCpp) {
inputFileUrl = QStringLiteral("qrc://") + inputResourcePath;
-
saveFunction = [inputResourcePath, outputFileName](
const QV4::CompiledData::SaveableUnitPointer &unit,
const QQmlJSAotFunctionMap &aotFunctions,
@@ -240,9 +252,47 @@ int main(int argc, char **argv)
if (inputFile.endsWith(QLatin1String(".qml"))) {
QQmlJSCompileError error;
- if (!qCompileQmlFile(inputFile, saveFunction, nullptr, &error)) {
- error.augment(QLatin1String("Error compiling qml file: ")).print();
- return EXIT_FAILURE;
+ if (target != GenerateCpp || inputResourcePath.isEmpty() || parser.isSet(onlyBytecode)) {
+ if (!qCompileQmlFile(inputFile, saveFunction, nullptr, &error,
+ /* storeSourceLocation */ false)) {
+ error.augment(QStringLiteral("Error compiling qml file: ")).print();
+ return EXIT_FAILURE;
+ }
+ } else {
+ QStringList importPaths;
+ if (parser.isSet(importPathOption))
+ importPaths = parser.values(importPathOption);
+
+ importPaths.append(QLibraryInfo::path(QLibraryInfo::QmlImportsPath));
+
+ QQmlJSImporter importer(
+ importPaths, parser.isSet(resourceOption) ? &fileMapper : nullptr);
+ QQmlJSLogger logger;
+
+ // Always trigger the qFatal() on "pragma Strict" violations.
+ logger.setCategoryError(Log_Compiler, true);
+
+ // By default, we're completely silent,
+ // as the lcAotCompiler category default is QtFatalMsg
+ if (lcAotCompiler().isDebugEnabled())
+ logger.setCategoryLevel(Log_Compiler, QtDebugMsg);
+ else if (lcAotCompiler().isInfoEnabled())
+ logger.setCategoryLevel(Log_Compiler, QtInfoMsg);
+ else if (lcAotCompiler().isWarningEnabled())
+ logger.setCategoryLevel(Log_Compiler, QtWarningMsg);
+ else if (lcAotCompiler().isCriticalEnabled())
+ logger.setCategoryLevel(Log_Compiler, QtCriticalMsg);
+ else
+ logger.setSilent(true);
+
+ QQmlJSAotCompiler cppCodeGen(
+ &importer, u':' + inputResourcePath, parser.values(importsOption), &logger);
+
+ if (!qCompileQmlFile(inputFile, saveFunction, &cppCodeGen, &error,
+ /* storeSourceLocation */ true)) {
+ error.augment(QStringLiteral("Error compiling qml file: ")).print();
+ return EXIT_FAILURE;
+ }
}
} else if (inputFile.endsWith(QLatin1String(".js")) || inputFile.endsWith(QLatin1String(".mjs"))) {
QQmlJSCompileError error;