1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#include <profileutils.h>
5#include <runqttool.h>
6
7#include <QtCore/qcoreapplication.h>
8#include <QtCore/qdebug.h>
9#include <QtCore/qdir.h>
10#include <QtCore/qfile.h>
11#include <QtCore/qfileinfo.h>
12#include <QtCore/qlibraryinfo.h>
13#include <QtCore/qstring.h>
14#include <QtCore/qstringlist.h>
15#include <QtCore/qtemporaryfile.h>
16#include <QtCore/qtranslator.h>
17
18#include <iostream>
19
20using namespace Qt::StringLiterals;
21
22static void printOut(const QString & out)
23{
24 std::cout << qPrintable(out);
25}
26
27static void printErr(const QString & out)
28{
29 std::cerr << qPrintable(out);
30}
31
32static void printUsage()
33{
34 printOut(
35 out: uR"(Usage:
36lupdate-pro [options] [project-file]... [-ts ts-files...]
37lupdate-pro is part of Qt's Linguist tool chain. It extracts project
38information from qmake projects and passes it to lupdate.
39All command line options that are not consumed by lupdate-pro are
40passed to lupdate.
41
42Options:
43 -help Display this information and exit.
44 -silent
45 Do not explain what is being done.
46 -pro <filename>
47 Name of a .pro file. Useful for files with .pro file syntax but
48 different file suffix. Projects are recursed into and merged.
49 -pro-out <directory>
50 Virtual output directory for processing subsequent .pro files.
51 -pro-debug
52 Trace processing .pro files. Specify twice for more verbosity.
53 -version
54 Display the version of lupdate-pro and exit.
55)"_s);
56}
57
58int main(int argc, char **argv)
59{
60 QCoreApplication app(argc, argv);
61#ifndef QT_BOOTSTRAPPED
62#ifndef Q_OS_WIN32
63 QTranslator translator;
64 QTranslator qtTranslator;
65 QString sysLocale = QLocale::system().name();
66 QString resourceDir = QLibraryInfo::path(p: QLibraryInfo::TranslationsPath);
67 if (translator.load(filename: QLatin1String("linguist_") + sysLocale, directory: resourceDir)
68 && qtTranslator.load(filename: QLatin1String("qt_") + sysLocale, directory: resourceDir)) {
69 app.installTranslator(messageFile: &translator);
70 app.installTranslator(messageFile: &qtTranslator);
71 }
72#endif // Q_OS_WIN32
73#endif
74
75 QStringList args = app.arguments();
76 QStringList lupdateOptions;
77 QStringList lprodumpOptions;
78 bool hasProFiles = false;
79 bool keepProjectDescription = false;
80
81 for (int i = 1; i < args.size(); ++i) {
82 QString arg = args.at(i);
83 if (arg == QLatin1String("-help")
84 || arg == QLatin1String("--help")
85 || arg == QLatin1String("-h")) {
86 printUsage();
87 return 0;
88 } else if (arg == QLatin1String("-keep")) {
89 keepProjectDescription = true;
90 } else if (arg == QLatin1String("-silent")) {
91 lupdateOptions << arg;
92 lprodumpOptions << arg;
93 } else if (arg == QLatin1String("-pro-debug")) {
94 lprodumpOptions << arg;
95 } else if (arg == QLatin1String("-version")) {
96 printOut(QStringLiteral("lupdate-pro version %1\n").arg(a: QLatin1String(QT_VERSION_STR)));
97 return 0;
98 } else if (arg == QLatin1String("-pro")) {
99 ++i;
100 if (i == argc) {
101 printErr(out: u"The -pro option should be followed by a filename of .pro file.\n"_s);
102 return 1;
103 }
104 lprodumpOptions << arg << args[i];
105 hasProFiles = true;
106 } else if (arg == QLatin1String("-pro-out")) {
107 ++i;
108 if (i == argc) {
109 printErr(out: u"The -pro-out option should be followed by a directory name.\n"_s);
110 return 1;
111 }
112 lprodumpOptions << arg << args[i];
113 } else if (isProOrPriFile(filePath: arg)) {
114 lprodumpOptions << arg;
115 hasProFiles = true;
116 } else {
117 lupdateOptions << arg;
118 }
119 } // for args
120
121 if (!hasProFiles) {
122 printErr(out: u"lupdate-pro: No .pro/.pri files given.\n"_s);
123 return 1;
124 }
125
126 std::unique_ptr<QTemporaryFile> projectDescription = createProjectDescription(args: lprodumpOptions);
127 if (keepProjectDescription)
128 projectDescription->setAutoRemove(false);
129 lupdateOptions << QStringLiteral("-project") << projectDescription->fileName();
130
131 runQtTool(QStringLiteral("lupdate"), arguments: lupdateOptions);
132 return 0;
133}
134

source code of qttools/src/linguist/lupdate-pro/main.cpp