Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
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 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(QLibraryInfo::TranslationsPath);
67 if (translator.load("linguist_"_L1 + sysLocale, resourceDir)
68 && qtTranslator.load("qt_"_L1 + sysLocale, resourceDir)) {
69 app.installTranslator(&translator);
70 app.installTranslator(&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 == "-help"_L1 || arg == "--help"_L1 || arg == "-h"_L1) {
85 return 0;
86 } else if (arg == "-keep"_L1) {
87 keepProjectDescription = true;
88 } else if (arg == "-silent"_L1) {
89 lupdateOptions << arg;
90 lprodumpOptions << arg;
91 } else if (arg == "-pro-debug"_L1) {
92 lprodumpOptions << arg;
93 } else if (arg == "-version"_L1) {
94 printOut(QStringLiteral("lupdate-pro version %1\n").arg(QLatin1String(QT_VERSION_STR)));
95 return 0;
96 } else if (arg == "-pro"_L1) {
97 ++i;
98 if (i == argc) {
99 printErr(u"The -pro option should be followed by a filename of .pro file.\n"_s);
100 return 1;
101 }
102 lprodumpOptions << arg << args[i];
103 hasProFiles = true;
104 } else if (arg == "-pro-out"_L1) {
105 ++i;
106 if (i == argc) {
107 printErr(u"The -pro-out option should be followed by a directory name.\n"_s);
108 return 1;
109 }
110 lprodumpOptions << arg << args[i];
111 } else if (isProOrPriFile(arg)) {
112 lprodumpOptions << arg;
113 hasProFiles = true;
114 } else {
115 lupdateOptions << arg;
116 }
117 } // for args
118
119 if (!hasProFiles) {
120 printErr(u"lupdate-pro: No .pro/.pri files given.\n"_s);
121 return 1;
122 }
123
124 std::unique_ptr<QTemporaryFile> projectDescription = createProjectDescription(lprodumpOptions);
125 if (keepProjectDescription)
126 projectDescription->setAutoRemove(false);
127 lupdateOptions << QStringLiteral("-project") << projectDescription->fileName();
128
129 runQtTool(QStringLiteral("lupdate"), lupdateOptions);
130 return 0;
131}
int main(int argc, char *argv[])
[2]
Definition buffer.cpp:77
static void printUsage()
Definition main.cpp:60
static void printOut(const QString &out)
Definition main.cpp:18
static void printErr(const QString &out)
Definition main.cpp:23