diff options
author | Andrew Knight <andrew.knight@digia.com> | 2014-03-27 15:58:47 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-08 09:20:37 +0200 |
commit | 94899dc03496275d25fe61a42f2e053a6d117ca8 (patch) | |
tree | 838dababe2cdb71fc870146a36463afd7efcc1fe | |
parent | 2f9ba37d90f4e1a7328fedb06ac9b1dcd78d9236 (diff) | |
download | qttools-94899dc03496275d25fe61a42f2e053a6d117ca8.tar.gz |
qtd3dservice: Add options for retrieving shader information
To ease packaging shaders, the following command line options are added:
- list-source: List the shader sources
- list-binary: List the shader binaries
- qrc: Output in QRC format instead of a list
Change-Id: I2041523c25f940e3ced23ca32d347807babcade7
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
-rw-r--r-- | src/qtd3dservice/d3dservice.h | 6 | ||||
-rw-r--r-- | src/qtd3dservice/info.cpp | 86 | ||||
-rw-r--r-- | src/qtd3dservice/main.cpp | 121 | ||||
-rw-r--r-- | src/qtd3dservice/qtd3dservice.pro | 3 |
4 files changed, 214 insertions, 2 deletions
diff --git a/src/qtd3dservice/d3dservice.h b/src/qtd3dservice/d3dservice.h index d7d0e5943..e50e1bf06 100644 --- a/src/qtd3dservice/d3dservice.h +++ b/src/qtd3dservice/d3dservice.h @@ -45,6 +45,7 @@ #include <QtCore/qt_windows.h> #include <QtCore/QPair> #include <QtCore/QString> +#include <QtCore/QStringList> #include <QtCore/QLoggingCategory> QT_USE_NAMESPACE @@ -55,6 +56,11 @@ namespace D3DService HRESULT compileShader(const QString &source, const QString &destination); bool start(); + + QStringList devices(); + QStringList apps(const QString &device); + QStringList sources(const QString &device, const QString &app); + QStringList binaries(const QString &device, const QString &app); } Q_DECLARE_LOGGING_CATEGORY(lcD3DService) diff --git a/src/qtd3dservice/info.cpp b/src/qtd3dservice/info.cpp new file mode 100644 index 000000000..1824647f1 --- /dev/null +++ b/src/qtd3dservice/info.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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:LGPL$ +** 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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "d3dservice.h" + +#include <QtCore/QDir> +#include <QtCore/QStandardPaths> + +QT_USE_NAMESPACE + +QStringList D3DService::devices() +{ + const QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + + QStringLiteral("/qtd3dservice")); + return dir.entryList(QDir::Dirs|QDir::NoDotAndDotDot); +} + +QStringList D3DService::apps(const QString &device) +{ + const QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + + QStringLiteral("/qtd3dservice/") + + (device.isEmpty() ? QStringLiteral("local") : device)); + return dir.entryList(QDir::Dirs|QDir::NoDotAndDotDot); +} + +QStringList D3DService::sources( const QString &device, const QString &app) +{ + const QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + + QStringLiteral("/qtd3dservice/") + + (device.isEmpty() ? QStringLiteral("local") : device) + + QLatin1Char('/') + app + QStringLiteral("/source")); + QStringList entries; + foreach (const QFileInfo &info, dir.entryInfoList(QDir::Files)) + entries.append(info.absoluteFilePath()); + return entries; +} + +QStringList D3DService::binaries(const QString &device, const QString &app) +{ + const QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + + QStringLiteral("/qtd3dservice/") + + (device.isEmpty() ? QStringLiteral("local") : device) + + QLatin1Char('/') + app + QStringLiteral("/binary")); + QStringList entries; + foreach (const QFileInfo &info, dir.entryInfoList(QDir::Files)) + entries.append(info.absoluteFilePath()); + return entries; +} diff --git a/src/qtd3dservice/main.cpp b/src/qtd3dservice/main.cpp index a24120513..167ab54f3 100644 --- a/src/qtd3dservice/main.cpp +++ b/src/qtd3dservice/main.cpp @@ -40,7 +40,10 @@ ****************************************************************************/ #include <QtCore/QCommandLineParser> +#include <QtCore/QDir> #include <QtCore/QFile> +#include <QtCore/QFileInfo> +#include <QtCore/QXmlStreamWriter> #include <iostream> @@ -53,6 +56,39 @@ static void outputFileMessageHandler(QtMsgType, const QMessageLogContext &, cons outputFile.write("\r\n"); } +static void outputList(const QStringList &files, bool useLogger) +{ + foreach (const QString &file, files) { + if (useLogger) + qCCritical(lcD3DService, qPrintable(file)); + else + std::wcout << reinterpret_cast<const wchar_t *>(file.utf16()) << std::endl; + } +} + +static void outputQrc(const QStringList &files, bool useLogger) +{ + QString stream; + QXmlStreamWriter xml(&stream); + xml.setAutoFormatting(true); + xml.writeStartElement(QStringLiteral("RCC")); + xml.writeStartElement(QStringLiteral("qresource")); + xml.writeAttribute(QStringLiteral("prefix"), QStringLiteral("qt.d3dcompiler")); + foreach (const QString &file, files) { + xml.writeStartElement(QStringLiteral("file")); + xml.writeAttribute(QStringLiteral("alias"), QFileInfo(file).fileName()); + xml.writeCharacters(file); + xml.writeEndElement(); + } + xml.writeEndElement(); + xml.writeEndElement(); + + if (useLogger) + qCCritical(lcD3DService, qPrintable(stream)); + else + std::wcout << reinterpret_cast<const wchar_t *>(stream.utf16()) << std::endl; +} + int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); @@ -73,12 +109,43 @@ int main(int argc, char *argv[]) "(0 - silent, 1 - info, 2 - debug). Defaults to 1."), QStringLiteral("level"), QStringLiteral("1")); parser.addOption(verbosityOption); + QCommandLineOption listSourceOption( + QStringLiteral("list-source"), + QLatin1String("List the known shader sources. Use with --app and/or --device " + "to narrow the scope.")); + parser.addOption(listSourceOption); + QCommandLineOption listBinaryOption( + QStringLiteral("list-binary"), + QLatin1String("List the known shader binaries. Use with --app and/or --device " + "to narrow the scope.")); + parser.addOption(listBinaryOption); + QCommandLineOption appOption( + QStringLiteral("app"), + QStringLiteral("Specifies the application to act upon."), + QStringLiteral("name")); + parser.addOption(appOption); + QCommandLineOption deviceOption( + QStringLiteral("device"), + QStringLiteral("Specifies the device to act upon."), + QStringLiteral("name")); + parser.addOption(deviceOption); + QCommandLineOption qrcOption( + QStringLiteral("qrc"), + QLatin1String("Outputs the content of --list-source/--list-binary in " + "Qt resource file format.")); + parser.addOption(qrcOption); parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); parser.addHelpOption(); parser.process(app.arguments()); - if (parser.isSet(outputOption)) { + + const bool useLogger = parser.isSet(outputOption); + const bool useQrc = parser.isSet(qrcOption); + const bool listSource = parser.isSet(listSourceOption); + const bool listBinary = parser.isSet(listBinaryOption); + + if (useLogger) { outputFile.setFileName(parser.value(outputOption)); if (!outputFile.open(QFile::WriteOnly)) { qCWarning(lcD3DService) << "The output file could not be opened:" @@ -88,6 +155,16 @@ int main(int argc, char *argv[]) qInstallMessageHandler(&outputFileMessageHandler); } + if (useQrc && !(listSource || listBinary)) { + qCWarning(lcD3DService) << "The --qrc option is only valid with either --list-source or --list--binary."; + return 1; + } + + if (listSource && listBinary) { + qCWarning(lcD3DService) << "Please specify only --list-binary or --list source, not both."; + return 1; + } + QStringList filterRules = QStringList() // Default logging rules << QStringLiteral("qt.d3dservice.warning=true") << QStringLiteral("qt.d3dservice.critical=true"); @@ -111,9 +188,51 @@ int main(int argc, char *argv[]) default: // Impossible break; } + } else if (listSource || listBinary) { + // In list mode, silence warnings by default + filterRules.removeFirst(); } QLoggingCategory::setFilterRules(filterRules.join(QLatin1Char('\n'))); + const QString deviceName = parser.value(deviceOption); + const QString appName = parser.value(appOption); + QStringList devices; + if (listSource || listBinary) + devices = deviceName.isEmpty() ? D3DService::devices() : QStringList(deviceName); + + if (listSource) { + foreach (const QString &device, devices) { + const QStringList apps = appName.isEmpty() + ? D3DService::apps(device) : QStringList(appName); + foreach (const QString &app, apps) { + const QStringList files = D3DService::sources(device, app); + if (useQrc) + outputQrc(files, useLogger); + else + outputList(files, useLogger); + } + } + + return 0; + } + + if (listBinary) { + foreach (const QString &device, devices) { + const QStringList apps = appName.isEmpty() + ? D3DService::apps(device) : QStringList(appName); + foreach (const QString &app, apps) { + const QStringList files = D3DService::binaries(device, app); + if (useQrc) + outputQrc(files, useLogger); + else + outputList(files, useLogger); + } + } + + return 0; + } + + // Default (start service) if (!D3DService::start()) { qCWarning(lcD3DService) << "The service failed to start."; return 1; diff --git a/src/qtd3dservice/qtd3dservice.pro b/src/qtd3dservice/qtd3dservice.pro index 158449267..1ca7890b1 100644 --- a/src/qtd3dservice/qtd3dservice.pro +++ b/src/qtd3dservice/qtd3dservice.pro @@ -14,7 +14,8 @@ SOURCES = \ d3dservice.cpp \ main.cpp \ xaphandler.cpp \ - compilation.cpp + compilation.cpp \ + info.cpp HEADERS = \ d3dservice.h |