summaryrefslogtreecommitdiffstats
path: root/src/linguist/lprodump/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/linguist/lprodump/main.cpp')
-rw-r--r--src/linguist/lprodump/main.cpp101
1 files changed, 38 insertions, 63 deletions
diff --git a/src/linguist/lprodump/main.cpp b/src/linguist/lprodump/main.cpp
index eed1e706f..3d30e4a63 100644
--- a/src/linguist/lprodump/main.cpp
+++ b/src/linguist/lprodump/main.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Linguist of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <profileevaluator.h>
#include <profileutils.h>
@@ -49,6 +24,8 @@
#include <iostream>
+using namespace Qt::StringLiterals;
+
static void printOut(const QString &out)
{
std::cout << qPrintable(out);
@@ -101,9 +78,11 @@ Options:
Trace processing .pro files. Specify twice for more verbosity.
-out <filename>
Name of the output file.
+ -translations-variables <variable_1>[,<variable_2>,...]
+ Comma-separated list of QMake variables containing .ts files.
-version
Display the version of lprodump and exit.
-)"_qs);
+)"_s);
}
static void print(const QString &fileName, int lineNo, const QString &msg)
@@ -140,13 +119,6 @@ public:
static EvalHandler evalHandler;
-static bool isSupportedExtension(const QString &ext)
-{
- return ext == QLatin1String("qml")
- || ext == QLatin1String("js") || ext == QLatin1String("qs")
- || ext == QLatin1String("ui") || ext == QLatin1String("jui");
-}
-
static QStringList getResources(const QString &resourceFile, QMakeVfs *vfs)
{
Q_ASSERT(vfs);
@@ -177,7 +149,7 @@ static QStringList getSources(const char *var, const char *vvar, const QStringLi
}
static QStringList getSources(const ProFileEvaluator &visitor, const QString &projectDir,
- const QStringList &excludes, QMakeVfs *vfs)
+ QMakeVfs *vfs)
{
QStringList baseVPaths;
baseVPaths += visitor.absolutePathValues(QLatin1String("VPATH"), projectDir);
@@ -200,7 +172,7 @@ static QStringList getSources(const ProFileEvaluator &visitor, const QString &pr
+ visitor.values(QLatin1String("DEPLOYMENT"));
installs.removeDuplicates();
QDir baseDir(projectDir);
- for (const QString &inst : qAsConst(installs)) {
+ for (const QString &inst : std::as_const(installs)) {
for (const QString &file : visitor.values(inst + QLatin1String(".files"))) {
QFileInfo info(file);
if (!info.isAbsolute())
@@ -229,18 +201,6 @@ static QStringList getSources(const ProFileEvaluator &visitor, const QString &pr
sourceFiles.removeDuplicates();
sourceFiles.sort();
-
- for (const QString &ex : excludes) {
- // TODO: take advantage of the file list being sorted
- QRegularExpression rx(QRegularExpression::wildcardToRegularExpression(ex));
- for (auto it = sourceFiles.begin(); it != sourceFiles.end(); ) {
- if (rx.match(*it).hasMatch())
- it = sourceFiles.erase(it);
- else
- ++it;
- }
- }
-
return sourceFiles;
}
@@ -269,11 +229,13 @@ static void excludeProjects(const ProFileEvaluator &visitor, QStringList *subPro
}
static QJsonArray processProjects(bool topLevel, const QStringList &proFiles,
+ const QStringList &translationsVariables,
const QHash<QString, QString> &outDirMap,
ProFileGlobals *option, QMakeVfs *vfs, QMakeParser *parser,
bool *fail);
-static QJsonObject processProject(const QString &proFile, ProFileGlobals *option, QMakeVfs *vfs,
+static QJsonObject processProject(const QString &proFile, const QStringList &translationsVariables,
+ ProFileGlobals *option, QMakeVfs *vfs,
QMakeParser *parser, ProFileEvaluator &visitor)
{
QJsonObject result;
@@ -286,7 +248,7 @@ static QJsonObject processProject(const QString &proFile, ProFileGlobals *option
excludeProjects(visitor, &subProjects);
QStringList subProFiles;
QDir proDir(proPath);
- for (const QString &subdir : qAsConst(subProjects)) {
+ for (const QString &subdir : std::as_const(subProjects)) {
QString realdir = visitor.value(subdir + QLatin1String(".subdir"));
if (realdir.isEmpty())
realdir = visitor.value(subdir + QLatin1String(".file"));
@@ -301,23 +263,23 @@ static QJsonObject processProject(const QString &proFile, ProFileGlobals *option
subProFiles << subPro;
}
}
- QJsonArray subResults = processProjects(false, subProFiles,
+ QJsonArray subResults = processProjects(false, subProFiles, translationsVariables,
QHash<QString, QString>(), option, vfs, parser,
nullptr);
if (!subResults.isEmpty())
setValue(result, "subProjects", subResults);
} else {
- const QStringList excludes = getExcludes(visitor, proPath);
- const QStringList sourceFiles = getSources(visitor, proPath, excludes, vfs);
+ const QStringList sourceFiles = getSources(visitor, proPath, vfs);
setValue(result, "includePaths",
visitor.absolutePathValues(QLatin1String("INCLUDEPATH"), proPath));
- setValue(result, "excluded", excludes);
+ setValue(result, "excluded", getExcludes(visitor, proPath));
setValue(result, "sources", sourceFiles);
}
return result;
}
static QJsonArray processProjects(bool topLevel, const QStringList &proFiles,
+ const QStringList &translationsVariables,
const QHash<QString, QString> &outDirMap,
ProFileGlobals *option, QMakeVfs *vfs, QMakeParser *parser, bool *fail)
{
@@ -343,16 +305,20 @@ static QJsonArray processProjects(bool topLevel, const QStringList &proFiles,
continue;
}
- QJsonObject prj = processProject(proFile, option, vfs, parser, visitor);
+ QJsonObject prj = processProject(proFile, translationsVariables, option, vfs, parser,
+ visitor);
setValue(prj, "projectFile", proFile);
- if (visitor.contains(QLatin1String("TRANSLATIONS"))) {
- QStringList tsFiles;
+ QStringList tsFiles;
+ for (const QString &varName : translationsVariables) {
+ if (!visitor.contains(varName))
+ continue;
QDir proDir(QFileInfo(proFile).path());
- const QStringList translations = visitor.values(QLatin1String("TRANSLATIONS"));
+ const QStringList translations = visitor.values(varName);
for (const QString &tsFile : translations)
tsFiles << proDir.filePath(tsFile);
- setValue(prj, "translations", tsFiles);
}
+ if (!tsFiles.isEmpty())
+ setValue(prj, "translations", tsFiles);
if (visitor.contains(QLatin1String("LUPDATE_COMPILE_COMMANDS_PATH"))) {
const QStringList thepathjson = visitor.values(
QLatin1String("LUPDATE_COMPILE_COMMANDS_PATH"));
@@ -369,6 +335,7 @@ int main(int argc, char **argv)
QCoreApplication app(argc, argv);
QStringList args = app.arguments();
QStringList proFiles;
+ QStringList translationsVariables = { u"TRANSLATIONS"_s };
QString outDir = QDir::currentPath();
QHash<QString, QString> outDirMap;
QString outputFilePath;
@@ -384,7 +351,7 @@ int main(int argc, char **argv)
} else if (arg == QLatin1String("-out")) {
++i;
if (i == argc) {
- printErr(u"The option -out requires a parameter.\n"_qs);
+ printErr(u"The option -out requires a parameter.\n"_s);
return 1;
}
outputFilePath = args[i];
@@ -411,6 +378,14 @@ int main(int argc, char **argv)
return 1;
}
outDir = QDir::cleanPath(QFileInfo(args[i]).absoluteFilePath());
+ } else if (arg == u"-translations-variables"_s) {
+ ++i;
+ if (i == argc) {
+ printErr(u"The -translations-variables option must be followed by a "_s
+ u"comma-separated list of variable names.\n"_s);
+ return 1;
+ }
+ translationsVariables = args.at(i).split(QLatin1Char(','));
} else if (arg.startsWith(QLatin1String("-")) && arg != QLatin1String("-")) {
printErr(QStringLiteral("Unrecognized option '%1'.\n").arg(arg));
return 1;
@@ -450,8 +425,8 @@ int main(int argc, char **argv)
QMakeVfs vfs;
QMakeParser parser(0, &vfs, &evalHandler);
- QJsonArray results = processProjects(true, proFiles, outDirMap, &option, &vfs,
- &parser, &fail);
+ QJsonArray results = processProjects(true, proFiles, translationsVariables, outDirMap, &option,
+ &vfs, &parser, &fail);
if (fail)
return 1;