4#include <QtCore/qprocess.h>
5#include <QCryptographicHash>
11Q_LOGGING_CATEGORY(lcQdoc,
"qt.qdoc")
12Q_LOGGING_CATEGORY(lcQdocClang,
"qt.qdoc.clang")
15
16
17
18
22 const_cast<QLoggingCategory &>(lcQdoc()).setEnabled(QtDebugMsg, value);
23 const_cast<QLoggingCategory &>(lcQdocClang()).setEnabled(QtDebugMsg, value);
29 qCDebug(lcQdoc,
"START DEBUGGING: %ls", qUtf16Printable(message));
34 qCDebug(lcQdoc,
"STOP DEBUGGING: %ls", qUtf16Printable(message));
40 return lcQdoc().isEnabled(QtDebugMsg);
44
45
46
47
48
49
50
51
54 static QString terminator = QStringLiteral(
".");
55 if (wordPosition == numberOfWords - 1)
58 return comma(wordPosition, numberOfWords);
62
63
64
65
66
67
68
69
70
71
74 if (wordPosition == numberOfWords - 1)
76 if (numberOfWords == 2)
77 return QStringLiteral(
" and ");
78 if (wordPosition == 0 || wordPosition < numberOfWords - 2)
79 return QStringLiteral(
", ");
80 return QStringLiteral(
", and ");
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
114 auto legal_ascii = [](
const uint value) {
115 const uint start_ascii_subset{ 32 };
116 const uint end_ascii_subset{ 126 };
118 return value >= start_ascii_subset && value <= end_ascii_subset;
123 bool has_non_alnum_content{
false };
125 for (
const auto &c : str) {
126 char16_t u = c.unicode();
128 has_non_alnum_content =
true;
129 if (u >=
'A' && u <=
'Z')
131 if ((u >=
'a' && u <=
'z') || (u >=
'0' && u <=
'9')) {
132 result += QLatin1Char(u);
135 result += QLatin1Char(
'-');
139 if (result.endsWith(QLatin1Char(
'-')))
142 if (has_non_alnum_content) {
143 auto title_hash = QString::fromLocal8Bit(
144 QCryptographicHash::hash(str.toUtf8(), QCryptographicHash::Md5).toHex());
145 title_hash.truncate(8);
146 if (!result.isEmpty())
147 result.append(QLatin1Char(
'-'));
148 result.append(title_hash);
155
156
157static bool runProcess(
const QString &program,
const QStringList &arguments,
158 QByteArray *stdOutIn, QByteArray *stdErrIn)
161 process.start(program, arguments, QProcess::ReadWrite);
162 if (!process.waitForStarted()) {
163 qCDebug(lcQdoc).nospace() <<
"Unable to start " << process.program()
164 <<
": " << process.errorString();
167 process.closeWriteChannel();
168 const bool finished = process.waitForFinished();
169 const QByteArray stdErr = process.readAllStandardError();
173 *stdOutIn = process.readAllStandardOutput();
176 qCDebug(lcQdoc).nospace() << process.program() <<
" timed out: " << stdErr;
181 if (process.exitStatus() != QProcess::NormalExit) {
182 qCDebug(lcQdoc).nospace() << process.program() <<
" crashed: " << stdErr;
186 if (process.exitCode() != 0) {
187 qCDebug(lcQdoc).nospace() << process.program() <<
" exited with "
188 << process.exitCode() <<
": " << stdErr;
196
197
199 return QByteArrayLiteral(
" (framework directory)");
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
222 QStringList arguments;
223 arguments << QStringLiteral(
"-E") << QStringLiteral(
"-x") << QStringLiteral(
"c++")
224 << QStringLiteral(
"-") << QStringLiteral(
"-v");
227 if (!runProcess(compiler, arguments, &stdOut, &stdErr))
229 const QByteArrayList stdErrLines = stdErr.split(
'\n');
230 bool isIncludeDir =
false;
231 for (
const QByteArray &line : stdErrLines) {
233 if (line.startsWith(QByteArrayLiteral(
"End of search list"))) {
234 isIncludeDir =
false;
236 QByteArray prefix(
"-I");
237 QByteArray headerPath{line.trimmed()};
238 if (headerPath.endsWith(frameworkSuffix())) {
239 headerPath.truncate(headerPath.size() - frameworkSuffix().size());
240 prefix = QByteArrayLiteral(
"-F");
242 result.append(QString::fromLocal8Bit(prefix + headerPath));
244 }
else if (line.startsWith(QByteArrayLiteral(
"#include <...> search starts here"))) {
Combined button and popup list for selecting options.
This namespace holds QDoc-internal utility methods.
static void setDebugEnabled(bool value)
QStringList getInternalIncludePaths(const QString &compiler)
QString asAsciiPrintable(const QString &name)
Returns an ascii-printable representation of str.
void stopDebugging(const QString &message)
static QByteArray frameworkSuffix()
QString comma(qsizetype wordPosition, qsizetype numberOfWords)
QString separator(qsizetype wordPosition, qsizetype numberOfWords)
void startDebugging(const QString &message)
static bool runProcess(const QString &program, const QStringList &arguments, QByteArray *stdOutIn, QByteArray *stdErrIn)