| 154 | } |
| 155 | |
| 156 | bool TeXRenderer::executeLatexProcess(const QString engine, |
| 157 | const QString& baseName, |
| 158 | const QTemporaryFile& file, |
| 159 | const QString& resultFileExtension, |
| 160 | Result* res) { |
| 161 | // latex: produce the DVI file |
| 162 | const QString engineFullPath = safeExecutableName(engine); |
| 163 | if (engineFullPath.isEmpty()) { |
| 164 | res->successful = false; |
| 165 | res->errorMessage = i18n("%1 not found").arg(engine); |
| 166 | WARN(QStringLiteral("%1 not found").arg(engine).toStdString()); |
| 167 | return {}; |
| 168 | } |
| 169 | |
| 170 | WARN(QStringLiteral("Engine fullpath: %1").arg(engineFullPath).toStdString()); |
| 171 | |
| 172 | QProcess latexProcess; |
| 173 | startHostProcess(latexProcess, engineFullPath, QStringList() << QStringLiteral("-interaction=batchmode") << file.fileName()); |
| 174 | |
| 175 | WARN(QStringLiteral("Workdir: %1").arg(QDir::currentPath()).toStdString()); |
| 176 | |
| 177 | bool finished = latexProcess.waitForFinished(); |
| 178 | if (!finished || latexProcess.exitCode() != 0) { |
| 179 | QFile logFile(baseName + QStringLiteral(".log")); |
| 180 | QString errorLogs; |
| 181 | WARN(QStringLiteral("executeLatexProcess: logfile: %1").arg(QFileInfo(logFile).absoluteFilePath()).toStdString()); |
| 182 | if (logFile.open(QIODevice::ReadOnly)) { |
| 183 | // really slow, but texrenderer is running asynchronous so it is not a problem |
| 184 | while (!logFile.atEnd()) { |
| 185 | const auto line = logFile.readLine(); |
| 186 | if (line.length() > 0 && line.at(0) == '!') { |
| 187 | errorLogs += QLatin1String(line); |
| 188 | break; // only first error message is enough |
| 189 | } |
| 190 | } |
| 191 | logFile.close(); |
| 192 | } else |
| 193 | WARN(QStringLiteral("Unable to open logfile").toStdString()); |
| 194 | |
| 195 | WARN(latexProcess.readAllStandardOutput().toStdString()); |
| 196 | WARN(latexProcess.readAllStandardError().toStdString()); |
| 197 | |
| 198 | QString err; |
| 199 | if (errorLogs.isEmpty()) { |
| 200 | if (!finished) { |
| 201 | err = i18n("Timeout: Unable to generate latex file"); |
| 202 | WARN(QStringLiteral("Timeout: Unable to generate latex file").toStdString()); |
| 203 | } else { |
| 204 | err = QStringLiteral("latex ") + i18n("process failed, exit code =") + QStringLiteral(" ") + QString::number(latexProcess.exitCode()) |
| 205 | + QStringLiteral("\n"); |
| 206 | WARN(QStringLiteral("latex process failed, exit code = %1").arg(latexProcess.exitCode()).toStdString()); |
| 207 | } |
| 208 | } else { |
| 209 | err = errorLogs; |
| 210 | WARN(err.toStdString()); |
| 211 | } |
| 212 | |
| 213 | res->successful = false; |
nothing calls this directly
no test coverage detected