diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qmlbundle/main.cpp | 189 | ||||
-rw-r--r-- | tools/qmlbundle/qmlbundle.pro | 6 | ||||
-rw-r--r-- | tools/qmlimportscanner/main.cpp | 79 | ||||
-rw-r--r-- | tools/qmljs/qmljs.cpp | 22 | ||||
-rw-r--r-- | tools/qmlmin/main.cpp | 14 | ||||
-rw-r--r-- | tools/qmlplugindump/main.cpp | 4 | ||||
-rw-r--r-- | tools/qmlscene/main.cpp | 16 | ||||
-rw-r--r-- | tools/tools.pro | 1 |
8 files changed, 78 insertions, 253 deletions
diff --git a/tools/qmlbundle/main.cpp b/tools/qmlbundle/main.cpp deleted file mode 100644 index 56aa6f797c..0000000000 --- a/tools/qmlbundle/main.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the tools applications of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <private/qqmlbundle_p.h> -#include <QtCore/QCoreApplication> -#include <QtCore/QSet> -#include <QtCore/QStringList> -#include <iostream> - -static bool createBundle(const QString &fileName, const QStringList &fileNames) -{ - QQmlBundle bundle(fileName); - if (!bundle.open(QFile::WriteOnly)) - return false; - foreach (const QString &fileName, fileNames) - bundle.add(fileName); - return true; -} - -static bool removeFiles(const QString &fileName, const QStringList &fileNames) -{ - const QSet<QString> filesToRemove = QSet<QString>::fromList(fileNames); - - QQmlBundle bundle(fileName); - bundle.open(QFile::ReadWrite); - foreach (const QQmlBundle::FileEntry *entry, bundle.files()) { - if (filesToRemove.contains(entry->fileName())) - bundle.remove(entry); - } - return true; -} - -static void showHelp() -{ - std::cerr << "Usage: qmlbundle <command> [<args>]" << std::endl - << std::endl - << "The commands are:" << std::endl - << " create Create a new bundle" << std::endl - << " add Add files to the bundle" << std::endl - << " rm Remove files from the bundle" << std::endl - << " update Add files to the bundle or update them if they are already added" << std::endl - << " ls List the files in the bundle" << std::endl - << " cat Concatenates files and print on the standard output" << std::endl - << " optimize Insert optimization data for all recognised content" << std::endl - << std::endl - << "See 'qmlbundle help <command>' for more information on a specific command." << std::endl; -} - -static void usage(const QString &action, const QString &error = QString()) -{ - if (! error.isEmpty()) - std::cerr << qPrintable(error) << std::endl << std::endl; - - if (action == QLatin1String("create")) { - std::cerr << "usage: qmlbundle create <bundle name> [files]" << std::endl; - } else if (action == QLatin1String("add")) { - std::cerr << "usage: qmlbundle add <bundle name> [files]" << std::endl; - } else if (action == QLatin1String("rm")) { - std::cerr << "usage: qmlbundle rm <bundle name> [files]" << std::endl; - } else if (action == QLatin1String("update")) { - std::cerr << "usage: qmlbundle update <bundle name> [files]" << std::endl; - } else if (action == QLatin1String("ls")) { - std::cerr << "usage: qmlbundle ls <bundle name>" << std::endl; - } else if (action == QLatin1String("cat")) { - std::cerr << "usage: qmlbundle cat <bundle name> [files]" << std::endl; - } else { - showHelp(); - } -} - -int main(int argc, char *argv[]) -{ - QCoreApplication app(argc, argv); - - QStringList args = app.arguments(); - /*const QString exeName =*/ args.takeFirst(); - - if (args.isEmpty()) { - showHelp(); - return 0; - } - - const QString action = args.takeFirst(); - - if (action == QLatin1String("help")) { - if (args.empty()) - showHelp(); - else - usage(args.takeFirst()); - } else if (action == QLatin1String("ls")) { - if (args.isEmpty()) { - usage(action, "You must specify a bundle"); - return EXIT_FAILURE; - } - QQmlBundle bundle(args.takeFirst()); - if (bundle.open(QFile::ReadOnly)) { - foreach (const QQmlBundle::FileEntry *fileEntry, bundle.files()) - std::cout << qPrintable(fileEntry->fileName()) << std::endl; - } - } else if (action == QLatin1String("create")) { - if (args.isEmpty()) { - usage(action, "You must specify a bundle"); - return EXIT_FAILURE; - } - const QString bundleFileName = args.takeFirst(); - createBundle(bundleFileName, args); - } else if (action == QLatin1String("add")) { - if (args.isEmpty()) { - usage(action, "You must specify a bundle"); - return EXIT_FAILURE; - } - const QString bundleFileName = args.takeFirst(); - QQmlBundle bundle(bundleFileName); - bundle.open(); - foreach (const QString &fileName, args) { - if (! bundle.add(fileName)) - std::cerr << "cannot add file " << qPrintable(fileName) << " to " << qPrintable(bundleFileName) << std::endl; - } - } else if (action == QLatin1String("rm")) { - if (args.isEmpty()) { - usage(action, "You must specify a bundle"); - return EXIT_FAILURE; - } - const QString bundleFileName = args.takeFirst(); - removeFiles(bundleFileName, args); - } else if (action == QLatin1String("update")) { - if (args.isEmpty()) { - usage(action, "You must specify a bundle"); - return EXIT_FAILURE; - } - const QString bundleFileName = args.takeFirst(); - removeFiles(bundleFileName, args); - QQmlBundle bundle(bundleFileName); - bundle.open(); - foreach (const QString &fileName, args) { - if (! bundle.add(fileName)) - std::cerr << "cannot add file " << qPrintable(fileName) << " to " << qPrintable(bundleFileName) << std::endl; - } - } else if (action == QLatin1String("cat")) { - if (args.isEmpty()) { - usage(action, "You must specify a bundle"); - return EXIT_FAILURE; - } - const QString bundleFileName = args.takeFirst(); - QQmlBundle bundle(bundleFileName); - if (bundle.open(QFile::ReadOnly)) { - const QSet<QString> filesToShow = QSet<QString>::fromList(args); - - foreach (const QQmlBundle::FileEntry *fileEntry, bundle.files()) { - if (filesToShow.contains(fileEntry->fileName())) - std::cout.write(fileEntry->contents(), fileEntry->fileSize()); - } - } - } else { - showHelp(); - } - - return 0; -} diff --git a/tools/qmlbundle/qmlbundle.pro b/tools/qmlbundle/qmlbundle.pro deleted file mode 100644 index 60c5906f65..0000000000 --- a/tools/qmlbundle/qmlbundle.pro +++ /dev/null @@ -1,6 +0,0 @@ -QT = core qml-private core-private -CONFIG += no_import_scan - -SOURCES += main.cpp - -load(qt_tool) diff --git a/tools/qmlimportscanner/main.cpp b/tools/qmlimportscanner/main.cpp index 6f5ec28c4d..08710d358f 100644 --- a/tools/qmlimportscanner/main.cpp +++ b/tools/qmlimportscanner/main.cpp @@ -246,6 +246,41 @@ static QVariantList findQmlImportsInQmlFile(const QString &filePath) return findQmlImportsInQmlCode(filePath, code); } +struct ImportCollector : public QQmlJS::Directives +{ + QVariantList imports; + + virtual void importFile(const QString &jsfile, const QString &module, int line, int column) + { + QVariantMap entry; + entry[QLatin1String("type")] = QStringLiteral("javascript"); + entry[QLatin1String("path")] = jsfile; + imports << entry; + + Q_UNUSED(module); + Q_UNUSED(line); + Q_UNUSED(column); + } + + virtual void importModule(const QString &uri, const QString &version, const QString &module, int line, int column) + { + QVariantMap entry; + if (uri.contains(QLatin1Char('/'))) { + entry[QLatin1String("type")] = QStringLiteral("directory"); + entry[QLatin1String("name")] = uri; + } else { + entry[QLatin1String("type")] = QStringLiteral("module"); + entry[QLatin1String("name")] = uri; + entry[QLatin1String("version")] = version; + } + imports << entry; + + Q_UNUSED(module); + Q_UNUSED(line); + Q_UNUSED(column); + } +}; + // Scan a single javascrupt file for import statements QVariantList findQmlImportsInJavascriptFile(const QString &filePath) { @@ -256,42 +291,22 @@ QVariantList findQmlImportsInJavascriptFile(const QString &filePath) return QVariantList(); } - QVariantList imports; - QString sourceCode = QString::fromUtf8(file.readAll()); file.close(); - QmlIR::Document doc(/*debug mode*/false); - QQmlJS::DiagnosticMessage error; - doc.extractScriptMetaData(sourceCode, &error); - if (!error.message.isEmpty()) - return imports; - foreach (const QV4::CompiledData::Import *import, doc.imports) { - QVariantMap entry; - const QString name = doc.stringAt(import->uriIndex); - switch (import->type) { - case QV4::CompiledData::Import::ImportScript: - entry[QStringLiteral("type")] = QStringLiteral("javascript"); - entry[QStringLiteral("path")] = name; - break; - case QV4::CompiledData::Import::ImportLibrary: - if (name.contains(QLatin1Char('/'))) { - entry[QStringLiteral("type")] = QStringLiteral("directory"); - entry[QStringLiteral("name")] = name; - } else { - entry[QStringLiteral("type")] = QStringLiteral("module"); - entry[QStringLiteral("name")] = name; - entry[QStringLiteral("version")] = QString::number(import->majorVersion) + QLatin1Char('.') + QString::number(import->minorVersion); - } - break; - default: - Q_UNREACHABLE(); - continue; - } - imports << entry; - } + QQmlJS::Engine ee; + ImportCollector collector; + ee.setDirectives(&collector); + QQmlJS::Lexer lexer(&ee); + lexer.setCode(sourceCode, /*line*/1, /*qml mode*/false); + QQmlJS::Parser parser(&ee); + parser.parseProgram(); - return imports; + foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) + if (m.isError()) + return QVariantList(); + + return collector.imports; } // Scan a single qml or js file for import statements diff --git a/tools/qmljs/qmljs.cpp b/tools/qmljs/qmljs.cpp index d159e5c754..f4a561fac6 100644 --- a/tools/qmljs/qmljs.cpp +++ b/tools/qmljs/qmljs.cpp @@ -64,9 +64,9 @@ using namespace QV4; struct Print: FunctionObject { - struct Data : FunctionObject::Data { + struct Data : Heap::FunctionObject { Data(ExecutionContext *scope) - : FunctionObject::Data(scope, QStringLiteral("print")) { + : Heap::FunctionObject(scope, QStringLiteral("print")) { setVTable(staticVTable()); } }; @@ -89,9 +89,9 @@ DEFINE_OBJECT_VTABLE(Print); struct GC: public FunctionObject { - struct Data : FunctionObject::Data { + struct Data : Heap::FunctionObject { Data(ExecutionContext *scope) - : FunctionObject::Data(scope, QStringLiteral("gc")) + : Heap::FunctionObject(scope, QStringLiteral("gc")) { setVTable(staticVTable()); } @@ -116,10 +116,10 @@ static void showException(QV4::ExecutionContext *ctx, const QV4::ValueRef except QV4::ScopedValue ex(scope, *exception); QV4::ErrorObject *e = ex->asErrorObject(); if (!e) { - std::cerr << "Uncaught exception: " << qPrintable(ex->toString(ctx)->toQString()) << std::endl; + std::cerr << "Uncaught exception: " << qPrintable(ex->toQString()) << std::endl; } else { QV4::ScopedString m(scope, scope.engine->newString(QStringLiteral("message"))); - QV4::ScopedValue message(scope, e->get(m.getPointer())); + QV4::ScopedValue message(scope, e->get(m)); std::cerr << "Uncaught exception: " << qPrintable(message->toQStringNoThrow()) << std::endl; } @@ -185,10 +185,10 @@ int main(int argc, char *argv[]) QV4::ExecutionEngine vm(iSelFactory); - QV4::ExecutionContext *ctx = vm.rootContext; - QV4::Scope scope(ctx); + QV4::Scope scope(&vm); + QV4::ScopedContext ctx(scope, vm.rootContext()); - QV4::ScopedObject globalObject(scope, vm.globalObject); + QV4::ScopedObject globalObject(scope, vm.globalObject()); QV4::ScopedObject print(scope, vm.memoryManager->alloc<builtins::Print>(ctx)); globalObject->put(QV4::ScopedString(scope, vm.newIdentifier(QStringLiteral("print"))).getPointer(), print); QV4::ScopedObject gc(scope, vm.memoryManager->alloc<builtins::GC>(ctx)); @@ -208,13 +208,13 @@ int main(int argc, char *argv[]) result = script.run(); if (scope.engine->hasException) { QV4::StackTrace trace; - QV4::ScopedValue ex(scope, ctx->catchException(&trace)); + QV4::ScopedValue ex(scope, scope.engine->catchException(&trace)); showException(ctx, ex, trace); return EXIT_FAILURE; } if (!result->isUndefined()) { if (! qgetenv("SHOW_EXIT_VALUE").isEmpty()) - std::cout << "exit value: " << qPrintable(result->toString(ctx)->toQString()) << std::endl; + std::cout << "exit value: " << qPrintable(result->toQString()) << std::endl; } } else { std::cerr << "Error: cannot open file " << fn.toUtf8().constData() << std::endl; diff --git a/tools/qmlmin/main.cpp b/tools/qmlmin/main.cpp index aa3adf053d..aa99b242a7 100644 --- a/tools/qmlmin/main.cpp +++ b/tools/qmlmin/main.cpp @@ -93,7 +93,7 @@ public: _directives += QLatin1String(".pragma library\n"); } - virtual void importFile(const QString &jsfile, const QString &module) + virtual void importFile(const QString &jsfile, const QString &module, int line, int column) { _directives += QLatin1String(".import"); _directives += QLatin1Char('"'); @@ -102,9 +102,11 @@ public: _directives += QLatin1String("as "); _directives += module; _directives += QLatin1Char('\n'); + Q_UNUSED(line); + Q_UNUSED(column); } - virtual void importModule(const QString &uri, const QString &version, const QString &module) + virtual void importModule(const QString &uri, const QString &version, const QString &module, int line, int column) { _directives += QLatin1String(".import "); _directives += uri; @@ -113,6 +115,8 @@ public: _directives += QLatin1String(" as "); _directives += module; _directives += QLatin1Char('\n'); + Q_UNUSED(line); + Q_UNUSED(column); } protected: @@ -262,7 +266,8 @@ bool Minify::parse(int startToken) if (startToken == T_FEED_JS_PROGRAM) { // parse optional pragma directive - if (scanDirectives(this)) { + DiagnosticMessage error; + if (scanDirectives(this, &error)) { // append the scanned directives to the minifier code. append(directives()); @@ -433,7 +438,8 @@ bool Tokenize::parse(int startToken) if (startToken == T_FEED_JS_PROGRAM) { // parse optional pragma directive - if (scanDirectives(this)) { + DiagnosticMessage error; + if (scanDirectives(this, &error)) { // append the scanned directives as one token to // the token stream. _minifiedCode.append(directives()); diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index b387e4ff6e..36af41c246 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -62,7 +62,9 @@ #include <signal.h> #endif #ifdef Q_OS_WIN -#include <crtdbg.h> +# if !defined(Q_CC_MINGW) +# include <crtdbg.h> +# endif #include <qt_windows.h> #endif diff --git a/tools/qmlscene/main.cpp b/tools/qmlscene/main.cpp index 2a86b724f4..522a810d9e 100644 --- a/tools/qmlscene/main.cpp +++ b/tools/qmlscene/main.cpp @@ -351,7 +351,7 @@ static void usage() puts(" --quit .................................... Quit immediately after starting"); puts(" --disable-context-sharing ................. Disable the use of a shared GL context for QtQuick Windows"); puts(" -I <path> ................................. Add <path> to the list of import paths"); - puts(" -B <name> <file> .......................... Add a named bundle"); + puts(" -P <path> ................................. Add <path> to the list of plugin paths"); puts(" -translation <translationfile> ............ Set the language to run in"); puts(" "); @@ -363,7 +363,7 @@ int main(int argc, char ** argv) Options options; QStringList imports; - QList<QPair<QString, QString> > bundles; + QStringList pluginPaths; for (int i = 1; i < argc; ++i) { if (*argv[i] != '-' && QFileInfo(QFile::decodeName(argv[i])).exists()) { options.file = QUrl::fromLocalFile(argv[i]); @@ -393,11 +393,9 @@ int main(int argc, char ** argv) options.contextSharing = false; else if (lowerArgument == QLatin1String("-i") && i + 1 < argc) imports.append(QString::fromLatin1(argv[++i])); - else if (lowerArgument == QLatin1String("-b") && i + 2 < argc) { - QString name = QString::fromLatin1(argv[++i]); - QString file = QString::fromLatin1(argv[++i]); - bundles.append(qMakePair(name, file)); - } else if (lowerArgument == QLatin1String("--help") + else if (lowerArgument == QLatin1String("-p") && i + 1 < argc) + pluginPaths.append(QString::fromLatin1(argv[++i])); + else if (lowerArgument == QLatin1String("--help") || lowerArgument == QLatin1String("-help") || lowerArgument == QLatin1String("--h") || lowerArgument == QLatin1String("-h")) @@ -460,8 +458,8 @@ int main(int argc, char ** argv) QPointer<QQmlComponent> component = new QQmlComponent(&engine); for (int i = 0; i < imports.size(); ++i) engine.addImportPath(imports.at(i)); - for (int i = 0; i < bundles.size(); ++i) - engine.addNamedBundle(bundles.at(i).first, bundles.at(i).second); + for (int i = 0; i < pluginPaths.size(); ++i) + engine.addPluginPath(pluginPaths.at(i)); if (options.file.isLocalFile()) { QFileInfo fi(options.file.toLocalFile()); #ifndef QT_NO_TRANSLATION diff --git a/tools/tools.pro b/tools/tools.pro index af0965a0a5..b2e9e27066 100644 --- a/tools/tools.pro +++ b/tools/tools.pro @@ -10,7 +10,6 @@ qmlimportscanner.CONFIG = host_build SUBDIRS += \ qml \ qmlprofiler \ - qmlbundle \ qmllint qtHaveModule(quick) { !static: SUBDIRS += qmlscene qmlplugindump |