Port rcc to QCommandLineParser.
Before: ======= Qt resource compiler Usage: rcc [options] <inputs> Options: -o file write output to file rather than stdout -name name create an external initialization function with name -threshold level threshold to consider compressing files -compress level compress input files by level -root path prefix resource access path with root path -no-compress disable all compression -binary output a binary file for use as a dynamic resource -namespace turn off namespace macros -project Output a resource file containing all files from the current directory -version display version -help display this information Undocumented: -verbose and -list ! After: ====== Usage: rcc [options] inputs Qt Resource Compiler version 5.2.0 Options: -h, --help Displays this help. -v, --version Displays version information. -o, --output <file> Write output to <file> rather than stdout. --name <name> Create an external initialization function with <name>. --root <path> Prefix resource access path with root path. --compress <level> Compress input files by <level>. --no-compress Disable all compression. --threshold <level> Threshold to consider compressing files. --binary Output a binary file for use as a dynamic resource. --namespace Turn off namespace macros. --verbose Enable verbose mode. --list Only list the files, do not generate code. --project Output a resource file containing all files from the current directory. Arguments: inputs Input files (*.qrc). Change-Id: If20958afd6c01df5d0d755e13e8581bc1cb9af51 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
6ee9baf044
commit
4774ff8eb1
@ -49,32 +49,13 @@
|
|||||||
#include <qtextstream.h>
|
#include <qtextstream.h>
|
||||||
#include <qatomic.h>
|
#include <qatomic.h>
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
|
#include <qcoreapplication.h>
|
||||||
|
#include <qcommandlineoption.h>
|
||||||
|
#include <qcommandlineparser.h>
|
||||||
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
void showHelp(const QString &argv0, const QString &error)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Qt resource compiler\n");
|
|
||||||
if (!error.isEmpty())
|
|
||||||
fprintf(stderr, "%s: %s\n", qPrintable(argv0), qPrintable(error));
|
|
||||||
fprintf(stderr, "Usage: %s [options] <inputs>\n\n"
|
|
||||||
"Options:\n"
|
|
||||||
" -o file write output to file rather than stdout\n"
|
|
||||||
" -name name create an external initialization function with name\n"
|
|
||||||
" -threshold level threshold to consider compressing files\n"
|
|
||||||
" -compress level compress input files by level\n"
|
|
||||||
" -root path prefix resource access path with root path\n"
|
|
||||||
" -no-compress disable all compression\n"
|
|
||||||
" -binary output a binary file for use as a dynamic resource\n"
|
|
||||||
" -namespace turn off namespace macros\n"
|
|
||||||
" -project Output a resource file containing all\n"
|
|
||||||
" files from the current directory\n"
|
|
||||||
" -list lists .qrc file entries\n"
|
|
||||||
" -version display version\n"
|
|
||||||
" -help display this information\n",
|
|
||||||
qPrintable(argv0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void dumpRecursive(const QDir &dir, QTextStream &out)
|
void dumpRecursive(const QDir &dir, QTextStream &out)
|
||||||
{
|
{
|
||||||
QFileInfoList entries = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot
|
QFileInfoList entries = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot
|
||||||
@ -127,92 +108,103 @@ int createProject(const QString &outFileName)
|
|||||||
|
|
||||||
int runRcc(int argc, char *argv[])
|
int runRcc(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QString outFilename;
|
QCoreApplication app(argc, argv);
|
||||||
bool helpRequested = false;
|
QCoreApplication::setApplicationVersion(QString::fromLatin1(QT_VERSION_STR));
|
||||||
bool list = false;
|
|
||||||
bool projectRequested = false;
|
|
||||||
QStringList filenamesIn;
|
|
||||||
|
|
||||||
QStringList args = qCmdLineArgs(argc, argv);
|
// Note that rcc isn't translated.
|
||||||
|
// If you use this code as an example for a translated app, make sure to translate the strings.
|
||||||
|
QCommandLineParser parser;
|
||||||
|
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
|
||||||
|
parser.setApplicationDescription(QStringLiteral("Qt Resource Compiler version %1").arg(QString::fromLatin1(QT_VERSION_STR)));
|
||||||
|
parser.addHelpOption();
|
||||||
|
parser.addVersionOption();
|
||||||
|
|
||||||
|
QCommandLineOption outputOption(QStringList() << QStringLiteral("o") << QStringLiteral("output"));
|
||||||
|
outputOption.setDescription(QStringLiteral("Write output to <file> rather than stdout."));
|
||||||
|
outputOption.setValueName(QStringLiteral("file"));
|
||||||
|
parser.addOption(outputOption);
|
||||||
|
|
||||||
|
QCommandLineOption nameOption(QStringLiteral("name"), QStringLiteral("Create an external initialization function with <name>."), QStringLiteral("name"));
|
||||||
|
parser.addOption(nameOption);
|
||||||
|
|
||||||
|
QCommandLineOption rootOption(QStringLiteral("root"), QStringLiteral("Prefix resource access path with root path."), QStringLiteral("path"));
|
||||||
|
parser.addOption(rootOption);
|
||||||
|
|
||||||
|
QCommandLineOption compressOption(QStringLiteral("compress"), QStringLiteral("Compress input files by <level>."), QStringLiteral("level"));
|
||||||
|
parser.addOption(compressOption);
|
||||||
|
|
||||||
|
QCommandLineOption nocompressOption(QStringLiteral("no-compress"), QStringLiteral("Disable all compression."));
|
||||||
|
parser.addOption(nocompressOption);
|
||||||
|
|
||||||
|
QCommandLineOption thresholdOption(QStringLiteral("threshold"), QStringLiteral("Threshold to consider compressing files."), QStringLiteral("level"));
|
||||||
|
parser.addOption(thresholdOption);
|
||||||
|
|
||||||
|
QCommandLineOption binaryOption(QStringLiteral("binary"), QStringLiteral("Output a binary file for use as a dynamic resource."));
|
||||||
|
parser.addOption(binaryOption);
|
||||||
|
|
||||||
|
QCommandLineOption namespaceOption(QStringLiteral("namespace"), QStringLiteral("Turn off namespace macros."));
|
||||||
|
parser.addOption(namespaceOption);
|
||||||
|
|
||||||
|
QCommandLineOption verboseOption(QStringLiteral("verbose"), QStringLiteral("Enable verbose mode."));
|
||||||
|
parser.addOption(verboseOption);
|
||||||
|
|
||||||
|
QCommandLineOption listOption(QStringLiteral("list"), QStringLiteral("Only list .qrc file entries, do not generate code."));
|
||||||
|
parser.addOption(listOption);
|
||||||
|
|
||||||
|
QCommandLineOption projectOption(QStringLiteral("project"), QStringLiteral("Output a resource file containing all files from the current directory."));
|
||||||
|
parser.addOption(projectOption);
|
||||||
|
|
||||||
|
parser.addPositionalArgument(QStringLiteral("inputs"), QStringLiteral("Input files (*.qrc)."));
|
||||||
|
|
||||||
RCCResourceLibrary library;
|
|
||||||
|
|
||||||
//parse options
|
//parse options
|
||||||
|
parser.process(app);
|
||||||
|
|
||||||
QString errorMsg;
|
QString errorMsg;
|
||||||
for (int i = 1; i < args.count() && errorMsg.isEmpty(); i++) {
|
RCCResourceLibrary library;
|
||||||
if (args[i].isEmpty())
|
QString outFilename = parser.value(outputOption);
|
||||||
continue;
|
if (parser.isSet(nameOption))
|
||||||
if (args[i][0] == QLatin1Char('-')) { // option
|
library.setInitName(parser.value(nameOption));
|
||||||
QString opt = args[i];
|
if (parser.isSet(rootOption)) {
|
||||||
if (opt == QLatin1String("-o")) {
|
library.setResourceRoot(QDir::cleanPath(parser.value(rootOption)));
|
||||||
if (!(i < argc-1)) {
|
if (library.resourceRoot().isEmpty()
|
||||||
errorMsg = QLatin1String("Missing output name");
|
|| library.resourceRoot().at(0) != QLatin1Char('/'))
|
||||||
break;
|
errorMsg = QLatin1String("Root must start with a /");
|
||||||
}
|
}
|
||||||
outFilename = args[++i];
|
if (parser.isSet(compressOption))
|
||||||
} else if (opt == QLatin1String("-name")) {
|
library.setCompressLevel(parser.value(compressOption).toInt());
|
||||||
if (!(i < argc-1)) {
|
if (parser.isSet(nocompressOption))
|
||||||
errorMsg = QLatin1String("Missing target name");
|
library.setCompressLevel(-2);
|
||||||
break;
|
if (parser.isSet(thresholdOption))
|
||||||
}
|
library.setCompressThreshold(parser.value(thresholdOption).toInt());
|
||||||
library.setInitName(args[++i]);
|
if (parser.isSet(binaryOption))
|
||||||
} else if (opt == QLatin1String("-root")) {
|
library.setFormat(RCCResourceLibrary::Binary);
|
||||||
if (!(i < argc-1)) {
|
if (parser.isSet(namespaceOption))
|
||||||
errorMsg = QLatin1String("Missing root path");
|
library.setUseNameSpace(!library.useNameSpace());
|
||||||
break;
|
if (parser.isSet(verboseOption))
|
||||||
}
|
library.setVerbose(true);
|
||||||
library.setResourceRoot(QDir::cleanPath(args[++i]));
|
|
||||||
if (library.resourceRoot().isEmpty()
|
const bool list = parser.isSet(listOption);
|
||||||
|| library.resourceRoot().at(0) != QLatin1Char('/'))
|
const bool projectRequested = parser.isSet(projectOption);
|
||||||
errorMsg = QLatin1String("Root must start with a /");
|
const QStringList filenamesIn = parser.positionalArguments();
|
||||||
} else if (opt == QLatin1String("-compress")) {
|
|
||||||
if (!(i < argc-1)) {
|
foreach (const QString &file, filenamesIn) {
|
||||||
errorMsg = QLatin1String("Missing compression level");
|
if (!QFile::exists(file)) {
|
||||||
break;
|
qWarning("%s: File does not exist '%s'", argv[0], qPrintable(file));
|
||||||
}
|
return 1;
|
||||||
library.setCompressLevel(args[++i].toInt());
|
|
||||||
} else if (opt == QLatin1String("-threshold")) {
|
|
||||||
if (!(i < argc-1)) {
|
|
||||||
errorMsg = QLatin1String("Missing compression threshold");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
library.setCompressThreshold(args[++i].toInt());
|
|
||||||
} else if (opt == QLatin1String("-binary")) {
|
|
||||||
library.setFormat(RCCResourceLibrary::Binary);
|
|
||||||
} else if (opt == QLatin1String("-namespace")) {
|
|
||||||
library.setUseNameSpace(!library.useNameSpace());
|
|
||||||
} else if (opt == QLatin1String("-verbose")) {
|
|
||||||
library.setVerbose(true);
|
|
||||||
} else if (opt == QLatin1String("-list")) {
|
|
||||||
list = true;
|
|
||||||
} else if (opt == QLatin1String("-version") || opt == QLatin1String("-v")) {
|
|
||||||
fprintf(stderr, "Qt Resource Compiler version %s\n", QT_VERSION_STR);
|
|
||||||
return 1;
|
|
||||||
} else if (opt == QLatin1String("-help") || opt == QLatin1String("-h")) {
|
|
||||||
helpRequested = true;
|
|
||||||
} else if (opt == QLatin1String("-no-compress")) {
|
|
||||||
library.setCompressLevel(-2);
|
|
||||||
} else if (opt == QLatin1String("-project")) {
|
|
||||||
projectRequested = true;
|
|
||||||
} else {
|
|
||||||
errorMsg = QString::fromLatin1("Unknown option: '%1'").arg(args[i]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!QFile::exists(args[i])) {
|
|
||||||
qWarning("%s: File does not exist '%s'",
|
|
||||||
qPrintable(args[0]), qPrintable(args[i]));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
filenamesIn.append(args[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (projectRequested && !helpRequested) {
|
if (projectRequested) {
|
||||||
return createProject(outFilename);
|
return createProject(outFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filenamesIn.size() || !errorMsg.isEmpty() || helpRequested) {
|
if (filenamesIn.isEmpty())
|
||||||
showHelp(args[0], errorMsg);
|
errorMsg = QStringLiteral("No input files specified.");
|
||||||
|
|
||||||
|
if (!errorMsg.isEmpty()) {
|
||||||
|
fprintf(stderr, "%s: %s\n", argv[0], qPrintable(errorMsg));
|
||||||
|
parser.showHelp(1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
QFile errorDevice;
|
QFile errorDevice;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user