1/****************************************************************************
2**
3** Copyright (C) 2018 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Linguist of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <profileutils.h>
30#include <runqttool.h>
31
32#include <QtCore/qcoreapplication.h>
33#include <QtCore/qdebug.h>
34#include <QtCore/qdir.h>
35#include <QtCore/qfile.h>
36#include <QtCore/qfileinfo.h>
37#include <QtCore/qlibraryinfo.h>
38#include <QtCore/qstring.h>
39#include <QtCore/qstringlist.h>
40#include <QtCore/qtemporaryfile.h>
41#include <QtCore/qtranslator.h>
42
43#include <iostream>
44
45static void printOut(const QString & out)
46{
47 std::cout << qPrintable(out);
48}
49
50static void printErr(const QString & out)
51{
52 std::cerr << qPrintable(out);
53}
54
55class LU {
56 Q_DECLARE_TR_FUNCTIONS(LUpdate)
57};
58
59static void printUsage()
60{
61 printOut(out: LU::tr(
62 sourceText: "Usage:\n"
63 " lupdate-pro [options] [project-file]... [-ts ts-files...]\n"
64 "lupdate-pro is part of Qt's Linguist tool chain. It extracts project\n"
65 "information from qmake projects and passes it to lupdate.\n"
66 "All command line options that are not consumed by lupdate-pro are\n"
67 "passed to lupdate.\n\n"
68 "Options:\n"
69 " -help Display this information and exit.\n"
70 " -silent\n"
71 " Do not explain what is being done.\n"
72 " -pro <filename>\n"
73 " Name of a .pro file. Useful for files with .pro file syntax but\n"
74 " different file suffix. Projects are recursed into and merged.\n"
75 " -pro-out <directory>\n"
76 " Virtual output directory for processing subsequent .pro files.\n"
77 " -pro-debug\n"
78 " Trace processing .pro files. Specify twice for more verbosity.\n"
79 " -version\n"
80 " Display the version of lupdate-pro and exit.\n"
81 ));
82}
83
84int main(int argc, char **argv)
85{
86 QCoreApplication app(argc, argv);
87#ifndef QT_BOOTSTRAPPED
88#ifndef Q_OS_WIN32
89 QTranslator translator;
90 QTranslator qtTranslator;
91 QString sysLocale = QLocale::system().name();
92 QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
93 if (translator.load(filename: QLatin1String("linguist_") + sysLocale, directory: resourceDir)
94 && qtTranslator.load(filename: QLatin1String("qt_") + sysLocale, directory: resourceDir)) {
95 app.installTranslator(messageFile: &translator);
96 app.installTranslator(messageFile: &qtTranslator);
97 }
98#endif // Q_OS_WIN32
99#endif
100
101 QStringList args = app.arguments();
102 QStringList lupdateOptions;
103 QStringList lprodumpOptions;
104 bool hasProFiles = false;
105 bool keepProjectDescription = false;
106
107 for (int i = 1; i < args.size(); ++i) {
108 QString arg = args.at(i);
109 if (arg == QLatin1String("-help")
110 || arg == QLatin1String("--help")
111 || arg == QLatin1String("-h")) {
112 printUsage();
113 return 0;
114 } else if (arg == QLatin1String("-keep")) {
115 keepProjectDescription = true;
116 } else if (arg == QLatin1String("-silent")) {
117 lupdateOptions << arg;
118 lprodumpOptions << arg;
119 } else if (arg == QLatin1String("-pro-debug")) {
120 lprodumpOptions << arg;
121 } else if (arg == QLatin1String("-version")) {
122 printOut(out: LU::tr(sourceText: "lupdate-pro version %1\n").arg(a: QLatin1String(QT_VERSION_STR)));
123 return 0;
124 } else if (arg == QLatin1String("-pro")) {
125 ++i;
126 if (i == argc) {
127 printErr(out: LU::tr(sourceText: "The -pro option should be followed by a filename of .pro file.\n"));
128 return 1;
129 }
130 lprodumpOptions << arg << args[i];
131 hasProFiles = true;
132 } else if (arg == QLatin1String("-pro-out")) {
133 ++i;
134 if (i == argc) {
135 printErr(out: LU::tr(sourceText: "The -pro-out option should be followed by a directory name.\n"));
136 return 1;
137 }
138 lprodumpOptions << arg << args[i];
139 } else if (isProOrPriFile(filePath: arg)) {
140 lprodumpOptions << arg;
141 hasProFiles = true;
142 } else {
143 lupdateOptions << arg;
144 }
145 } // for args
146
147 if (!hasProFiles) {
148 printErr(out: LU::tr(sourceText: "lupdate-pro: No .pro/.pri files given.\n"));
149 return 1;
150 }
151
152 std::unique_ptr<QTemporaryFile> projectDescription = createProjectDescription(args: lprodumpOptions);
153 if (keepProjectDescription)
154 projectDescription->setAutoRemove(false);
155 lupdateOptions << QStringLiteral("-project") << projectDescription->fileName();
156
157 runQtTool(QStringLiteral("lupdate"), arguments: lupdateOptions);
158 return 0;
159}
160

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