diff options
author | Leander Beernaert <leander.beernaert@qt.io> | 2019-07-30 16:36:53 +0200 |
---|---|---|
committer | Leander Beernaert <leander.beernaert@qt.io> | 2019-07-31 12:33:44 +0000 |
commit | 059d79226421b80b5dfe5d994e37976a0e606ec9 (patch) | |
tree | 1e92da080329d6568c98a2749199c552fdefff2c /tools/qmlcachegen | |
parent | e6ed3f67eee166dccdedf645d9871bfdc21d57de (diff) |
Add support for generating qmlcache_loader without qrc
Added support for response file expansion to qmlcachegen.
Add the option --standalone-namespace to qmlcachegen so we can
generate qmlcache_loader from a collection of resource paths
instead of operating on qrc files. This is necessary, since the
namespace identifier is extraced from the qrc file name, which
we no longer have.
This pach was made in order to tend to the cmake port's version of
qtquickcompiler support which does not rely on qrc files.
Change-Id: If15190f3492e6695f5a6e61bf8816998760541f7
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tools/qmlcachegen')
-rw-r--r-- | tools/qmlcachegen/qmlcachegen.cpp | 61 |
1 files changed, 57 insertions, 4 deletions
diff --git a/tools/qmlcachegen/qmlcachegen.cpp b/tools/qmlcachegen/qmlcachegen.cpp index 0202bd4df0..512826fb18 100644 --- a/tools/qmlcachegen/qmlcachegen.cpp +++ b/tools/qmlcachegen/qmlcachegen.cpp @@ -110,6 +110,36 @@ void Error::appendDiagnostics(const QString &inputFileName, const QList<Diagnost appendDiagnostic(inputFileName, diagnostic); } +static bool argumentsFromCommandLineAndFile(QStringList& allArguments, const QStringList &arguments) +{ + allArguments.reserve(arguments.size()); + for (const QString &argument : arguments) { + // "@file" doesn't start with a '-' so we can't use QCommandLineParser for it + if (argument.startsWith(QLatin1Char('@'))) { + QString optionsFile = argument; + optionsFile.remove(0, 1); + if (optionsFile.isEmpty()) { + fprintf(stderr, "The @ option requires an input file"); + return false; + } + QFile f(optionsFile); + if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { + fprintf(stderr, "Cannot open options file specified with @"); + return false; + } + while (!f.atEnd()) { + QString line = QString::fromLocal8Bit(f.readLine().trimmed()); + if (!line.isEmpty()) + allArguments << line; + } + } else { + allArguments << argument; + } + } + return true; +} + + // Ensure that ListElement objects keep all property assignments in their string form static void annotateListElements(QmlIR::Document *document) { @@ -423,6 +453,10 @@ int main(int argc, char **argv) parser.addOption(retainOption); QCommandLineOption resourcePathOption(QStringLiteral("resource-path"), QCoreApplication::translate("main", "Qt resource file path corresponding to the file being compiled"), QCoreApplication::translate("main", "resource-path")); parser.addOption(resourcePathOption); + QCommandLineOption resourceNameOption(QStringLiteral("resource-name"), + QCoreApplication::translate("main", "Required to generate qmlcache_loader without qrc files. This is the name of the Qt resource the input files belong to."), + QCoreApplication::translate("main", "compiled-file-list")); + parser.addOption(resourceNameOption); QCommandLineOption outputFileOption(QStringLiteral("o"), QCoreApplication::translate("main", "Output file name"), QCoreApplication::translate("main", "file name")); parser.addOption(outputFileOption); @@ -432,12 +466,18 @@ int main(int argc, char **argv) parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); - parser.process(app); + + QStringList arguments; + if (!argumentsFromCommandLineAndFile(arguments, app.arguments())) + return EXIT_FAILURE; + + parser.process(arguments); enum Output { GenerateCpp, GenerateCacheFile, - GenerateLoader + GenerateLoader, + GenerateLoaderStandAlone, } target = GenerateCacheFile; QString outputFileName; @@ -450,15 +490,18 @@ int main(int argc, char **argv) target = GenerateLoader; } + if (target == GenerateLoader && parser.isSet(resourceNameOption)) + target = GenerateLoaderStandAlone; + const QStringList sources = parser.positionalArguments(); if (sources.isEmpty()){ parser.showHelp(); - } else if (sources.count() > 1 && target != GenerateLoader) { + } else if (sources.count() > 1 && (target != GenerateLoader && target != GenerateLoaderStandAlone)) { fprintf(stderr, "%s\n", qPrintable(QStringLiteral("Too many input files specified: '") + sources.join(QStringLiteral("' '")) + QLatin1Char('\''))); return EXIT_FAILURE; } - const QString inputFile = sources.first(); + const QString inputFile = !sources.isEmpty() ? sources.first() : QString(); if (outputFileName.isEmpty()) outputFileName = inputFile + QLatin1Char('c'); @@ -481,6 +524,16 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } + if (target == GenerateLoaderStandAlone) { + QStringList retainedFiles; + Error error; + if (!generateLoader(sources, retainedFiles, outputFileName, + parser.values(resourceNameOption), &error.message)) { + error.augment(QLatin1String("Error generating loader stub: ")).print(); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; + } QString inputFileUrl = inputFile; SaveFunction saveFunction; |