diff options
author | Craig Scott <craig.scott@qt.io> | 2021-05-05 16:30:46 +1000 |
---|---|---|
committer | Craig Scott <craig.scott@qt.io> | 2021-05-07 07:31:32 +1000 |
commit | d63d8cce9754d2bb7a08f0da067a22cc8b650d9d (patch) | |
tree | 8e320da2d976da6a331f536b2226952d6001c117 /tools | |
parent | 546df684e272bbbc5e8b871ae9b224fdb34a4cfa (diff) |
Extend qmlimportscanner to support response files on the command line
This is preparation for being able to list individual qml files on the
command line instead of requiring them to be in a .qrc file.
To avoid running into line length issues when there are a lot of files,
allow response files to be used to store arguments instead.
Use the common tool convention of a leading "@" before the name of the
response file.
Change-Id: Id91daf08a6022033a448e9ed98085df8b246a849
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qmlimportscanner/main.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/tools/qmlimportscanner/main.cpp b/tools/qmlimportscanner/main.cpp index bda88541b0..6ad5ab257d 100644 --- a/tools/qmlimportscanner/main.cpp +++ b/tools/qmlimportscanner/main.cpp @@ -581,13 +581,44 @@ QString generateCmakeIncludeFileContent(const QVariantList &importList) { return content; } +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; +} + } // namespace int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR)); - QStringList args = app.arguments(); + QStringList args; + if (!argumentsFromCommandLineAndFile(args, app.arguments())) + return EXIT_FAILURE; const QString appName = QFileInfo(app.applicationFilePath()).baseName(); if (args.size() < 2) { printUsage(appName); |