2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-04-20 22:24:33 +08:00
|
|
|
#include "compilermanager.h"
|
|
|
|
#include "filecompiler.h"
|
2021-06-24 20:43:09 +08:00
|
|
|
#include "stdincompiler.h"
|
2021-04-20 22:24:33 +08:00
|
|
|
#include "../mainwindow.h"
|
2021-04-21 18:58:35 +08:00
|
|
|
#include "executablerunner.h"
|
2021-11-01 09:18:23 +08:00
|
|
|
#include "ojproblemcasesrunner.h"
|
2021-04-21 18:58:35 +08:00
|
|
|
#include "utils.h"
|
2022-12-30 09:06:39 +08:00
|
|
|
#include "../systemconsts.h"
|
2021-07-01 19:44:38 +08:00
|
|
|
#include "../settings.h"
|
2021-07-26 22:29:47 +08:00
|
|
|
#include <QMessageBox>
|
2022-03-16 20:08:39 +08:00
|
|
|
#include <QUuid>
|
2021-09-13 22:45:50 +08:00
|
|
|
#include "projectcompiler.h"
|
2021-04-20 22:24:33 +08:00
|
|
|
|
2021-10-25 09:16:00 +08:00
|
|
|
enum RunProgramFlag {
|
|
|
|
RPF_PAUSE_CONSOLE = 0x0001,
|
|
|
|
RPF_REDIRECT_INPUT = 0x0002
|
|
|
|
};
|
|
|
|
|
2022-01-04 16:50:54 +08:00
|
|
|
CompilerManager::CompilerManager(QObject *parent) : QObject(parent),
|
2022-11-10 09:05:34 +08:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
|
|
|
mCompileMutex(),
|
|
|
|
mBackgroundSyntaxCheckMutex(),
|
|
|
|
mRunnerMutex()
|
|
|
|
#else
|
2022-01-04 16:50:54 +08:00
|
|
|
mCompileMutex(QMutex::Recursive),
|
|
|
|
mBackgroundSyntaxCheckMutex(QMutex::Recursive),
|
|
|
|
mRunnerMutex(QMutex::Recursive)
|
2022-11-10 09:05:34 +08:00
|
|
|
#endif
|
2021-04-20 22:24:33 +08:00
|
|
|
{
|
|
|
|
mCompiler = nullptr;
|
|
|
|
mBackgroundSyntaxChecker = nullptr;
|
2021-04-21 18:58:35 +08:00
|
|
|
mRunner = nullptr;
|
2021-06-23 22:38:02 +08:00
|
|
|
mSyntaxCheckErrorCount = 0;
|
2021-10-23 16:18:02 +08:00
|
|
|
mSyntaxCheckIssueCount = 0;
|
2021-06-23 22:38:02 +08:00
|
|
|
mCompileErrorCount = 0;
|
2021-10-23 16:18:02 +08:00
|
|
|
mCompileIssueCount = 0;
|
|
|
|
mSyntaxCheckErrorCount = 0;
|
2021-04-20 22:24:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CompilerManager::compiling()
|
|
|
|
{
|
2021-06-25 12:40:11 +08:00
|
|
|
QMutexLocker locker(&mCompileMutex);
|
2021-04-20 22:24:33 +08:00
|
|
|
return mCompiler!=nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CompilerManager::backgroundSyntaxChecking()
|
|
|
|
{
|
2021-06-25 12:40:11 +08:00
|
|
|
QMutexLocker locker(&mBackgroundSyntaxCheckMutex);
|
2021-04-20 22:24:33 +08:00
|
|
|
return mBackgroundSyntaxChecker!=nullptr;
|
|
|
|
}
|
|
|
|
|
2021-06-25 12:40:11 +08:00
|
|
|
bool CompilerManager::running()
|
2021-04-20 22:24:33 +08:00
|
|
|
{
|
2021-06-25 12:40:11 +08:00
|
|
|
QMutexLocker locker(&mRunnerMutex);
|
2021-12-23 17:07:27 +08:00
|
|
|
return (mRunner!=nullptr && !mRunner->pausing());
|
2021-06-25 12:40:11 +08:00
|
|
|
}
|
|
|
|
|
2022-12-01 22:10:44 +08:00
|
|
|
void CompilerManager::compile(const QString& filename, const QByteArray& encoding, bool rebuild, CppCompileType compileType)
|
2021-06-25 12:40:11 +08:00
|
|
|
{
|
2021-07-26 22:29:47 +08:00
|
|
|
if (!pSettings->compilerSets().defaultSet()) {
|
|
|
|
QMessageBox::critical(pMainWindow,
|
|
|
|
tr("No compiler set"),
|
|
|
|
tr("No compiler set is configured.")+tr("Can't start debugging."));
|
2021-04-21 18:58:35 +08:00
|
|
|
return;
|
2021-04-20 22:24:33 +08:00
|
|
|
}
|
2021-07-26 22:29:47 +08:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&mCompileMutex);
|
|
|
|
if (mCompiler!=nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mCompileErrorCount = 0;
|
2021-10-23 16:18:02 +08:00
|
|
|
mCompileIssueCount = 0;
|
2022-10-10 18:05:18 +08:00
|
|
|
//deleted when thread finished
|
2022-12-01 22:10:44 +08:00
|
|
|
mCompiler = new FileCompiler(filename,encoding,compileType,false,false);
|
2021-07-26 22:29:47 +08:00
|
|
|
mCompiler->setRebuild(rebuild);
|
2021-10-09 11:33:23 +08:00
|
|
|
connect(mCompiler, &Compiler::finished, mCompiler, &QObject::deleteLater);
|
|
|
|
connect(mCompiler, &Compiler::compileFinished, this, &CompilerManager::onCompileFinished);
|
2021-07-26 22:29:47 +08:00
|
|
|
connect(mCompiler, &Compiler::compileIssue, this, &CompilerManager::onCompileIssue);
|
2021-09-19 14:28:30 +08:00
|
|
|
connect(mCompiler, &Compiler::compileStarted, pMainWindow, &MainWindow::onCompileStarted);
|
2022-10-10 07:11:59 +08:00
|
|
|
connect(mCompiler, &Compiler::compileStarted, pMainWindow, &MainWindow::clearToolsOutput);
|
2021-10-09 11:33:23 +08:00
|
|
|
|
2022-02-10 12:03:56 +08:00
|
|
|
connect(mCompiler, &Compiler::compileOutput, pMainWindow, &MainWindow::logToolsOutput);
|
2021-09-13 22:45:50 +08:00
|
|
|
connect(mCompiler, &Compiler::compileIssue, pMainWindow, &MainWindow::onCompileIssue);
|
|
|
|
connect(mCompiler, &Compiler::compileErrorOccured, pMainWindow, &MainWindow::onCompileErrorOccured);
|
|
|
|
mCompiler->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 22:10:44 +08:00
|
|
|
void CompilerManager::compileProject(std::shared_ptr<Project> project, bool rebuild)
|
2021-09-13 22:45:50 +08:00
|
|
|
{
|
|
|
|
if (!pSettings->compilerSets().defaultSet()) {
|
|
|
|
QMessageBox::critical(pMainWindow,
|
|
|
|
tr("No compiler set"),
|
|
|
|
tr("No compiler set is configured.")+tr("Can't start debugging."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&mCompileMutex);
|
|
|
|
if (mCompiler!=nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mCompileErrorCount = 0;
|
2021-10-23 16:18:02 +08:00
|
|
|
mCompileIssueCount = 0;
|
2022-10-10 18:05:18 +08:00
|
|
|
//deleted when thread finished
|
2022-12-01 22:10:44 +08:00
|
|
|
mCompiler = new ProjectCompiler(project,false,false);
|
2021-09-13 22:45:50 +08:00
|
|
|
mCompiler->setRebuild(rebuild);
|
2021-10-09 11:33:23 +08:00
|
|
|
connect(mCompiler, &Compiler::finished, mCompiler, &QObject::deleteLater);
|
|
|
|
connect(mCompiler, &Compiler::compileFinished, this, &CompilerManager::onCompileFinished);
|
|
|
|
|
2021-09-13 22:45:50 +08:00
|
|
|
connect(mCompiler, &Compiler::compileIssue, this, &CompilerManager::onCompileIssue);
|
2023-02-24 12:17:30 +08:00
|
|
|
connect(mCompiler, &Compiler::compileStarted, pMainWindow, &MainWindow::onProjectCompileStarted);
|
2022-10-10 07:11:59 +08:00
|
|
|
connect(mCompiler, &Compiler::compileStarted, pMainWindow, &MainWindow::clearToolsOutput);
|
2021-10-09 11:33:23 +08:00
|
|
|
|
2022-02-10 12:03:56 +08:00
|
|
|
connect(mCompiler, &Compiler::compileOutput, pMainWindow, &MainWindow::logToolsOutput);
|
2021-07-26 22:29:47 +08:00
|
|
|
connect(mCompiler, &Compiler::compileIssue, pMainWindow, &MainWindow::onCompileIssue);
|
|
|
|
connect(mCompiler, &Compiler::compileErrorOccured, pMainWindow, &MainWindow::onCompileErrorOccured);
|
|
|
|
mCompiler->start();
|
|
|
|
}
|
2021-04-21 18:58:35 +08:00
|
|
|
}
|
|
|
|
|
2021-09-17 21:33:19 +08:00
|
|
|
void CompilerManager::cleanProject(std::shared_ptr<Project> project)
|
|
|
|
{
|
|
|
|
if (!pSettings->compilerSets().defaultSet()) {
|
|
|
|
QMessageBox::critical(pMainWindow,
|
|
|
|
tr("No compiler set"),
|
|
|
|
tr("No compiler set is configured.")+tr("Can't start debugging."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&mCompileMutex);
|
|
|
|
if (mCompiler!=nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mCompileErrorCount = 0;
|
2021-10-23 16:18:02 +08:00
|
|
|
mCompileIssueCount = 0;
|
2022-10-10 18:05:18 +08:00
|
|
|
//deleted when thread finished
|
2021-09-17 21:33:19 +08:00
|
|
|
ProjectCompiler* compiler = new ProjectCompiler(project,false,false);
|
|
|
|
compiler->setOnlyClean(true);
|
|
|
|
mCompiler = compiler;
|
2021-11-23 10:32:33 +08:00
|
|
|
mCompiler->setRebuild(false);
|
2021-10-09 11:33:23 +08:00
|
|
|
connect(mCompiler, &Compiler::finished, mCompiler, &QObject::deleteLater);
|
|
|
|
connect(mCompiler, &Compiler::compileFinished, this, &CompilerManager::onCompileFinished);
|
|
|
|
|
2021-09-17 21:33:19 +08:00
|
|
|
connect(mCompiler, &Compiler::compileIssue, this, &CompilerManager::onCompileIssue);
|
2023-02-24 12:17:30 +08:00
|
|
|
connect(mCompiler, &Compiler::compileStarted, pMainWindow, &MainWindow::onProjectCompileStarted);
|
2022-10-10 07:11:59 +08:00
|
|
|
connect(mCompiler, &Compiler::compileStarted, pMainWindow, &MainWindow::clearToolsOutput);
|
2021-10-09 11:33:23 +08:00
|
|
|
|
2022-02-10 12:03:56 +08:00
|
|
|
connect(mCompiler, &Compiler::compileOutput, pMainWindow, &MainWindow::logToolsOutput);
|
2021-09-17 21:33:19 +08:00
|
|
|
connect(mCompiler, &Compiler::compileIssue, pMainWindow, &MainWindow::onCompileIssue);
|
|
|
|
connect(mCompiler, &Compiler::compileErrorOccured, pMainWindow, &MainWindow::onCompileErrorOccured);
|
|
|
|
mCompiler->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-17 19:58:37 +08:00
|
|
|
void CompilerManager::buildProjectMakefile(std::shared_ptr<Project> project)
|
|
|
|
{
|
|
|
|
if (!pSettings->compilerSets().defaultSet()) {
|
|
|
|
QMessageBox::critical(pMainWindow,
|
|
|
|
tr("No compiler set"),
|
|
|
|
tr("No compiler set is configured.")+tr("Can't start debugging."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&mCompileMutex);
|
|
|
|
if (mCompiler!=nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ProjectCompiler compiler(project,false,false);
|
|
|
|
compiler.buildMakeFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-03-27 11:44:52 +08:00
|
|
|
void CompilerManager::checkSyntax(const QString &filename, const QByteArray& encoding, const QString &content, std::shared_ptr<Project> project)
|
2021-06-24 20:43:09 +08:00
|
|
|
{
|
2021-07-26 22:29:47 +08:00
|
|
|
if (!pSettings->compilerSets().defaultSet()) {
|
|
|
|
QMessageBox::critical(pMainWindow,
|
|
|
|
tr("No compiler set"),
|
|
|
|
tr("No compiler set is configured.")+tr("Can't start debugging."));
|
2021-06-24 20:43:09 +08:00
|
|
|
return;
|
|
|
|
}
|
2021-07-26 22:29:47 +08:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&mBackgroundSyntaxCheckMutex);
|
|
|
|
if (mBackgroundSyntaxChecker!=nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSyntaxCheckErrorCount = 0;
|
2021-10-23 16:18:02 +08:00
|
|
|
mSyntaxCheckIssueCount = 0;
|
2022-10-10 18:05:18 +08:00
|
|
|
|
|
|
|
//deleted when thread finished
|
2022-12-25 12:00:09 +08:00
|
|
|
mBackgroundSyntaxChecker = new StdinCompiler(filename,encoding, content,true,true);
|
2021-09-12 22:45:00 +08:00
|
|
|
mBackgroundSyntaxChecker->setProject(project);
|
2021-10-09 11:33:23 +08:00
|
|
|
connect(mBackgroundSyntaxChecker, &Compiler::finished, mBackgroundSyntaxChecker, &QThread::deleteLater);
|
2021-07-26 22:29:47 +08:00
|
|
|
connect(mBackgroundSyntaxChecker, &Compiler::compileIssue, this, &CompilerManager::onSyntaxCheckIssue);
|
2023-02-24 12:17:30 +08:00
|
|
|
connect(mBackgroundSyntaxChecker, &Compiler::compileStarted, pMainWindow, &MainWindow::onSyntaxCheckStarted);
|
2021-10-09 11:33:23 +08:00
|
|
|
connect(mBackgroundSyntaxChecker, &Compiler::compileFinished, this, &CompilerManager::onSyntaxCheckFinished);
|
2022-10-10 07:11:59 +08:00
|
|
|
//connect(mBackgroundSyntaxChecker, &Compiler::compileOutput, pMainWindow, &MainWindow::logToolsOutput);
|
2021-07-26 22:29:47 +08:00
|
|
|
connect(mBackgroundSyntaxChecker, &Compiler::compileIssue, pMainWindow, &MainWindow::onCompileIssue);
|
|
|
|
connect(mBackgroundSyntaxChecker, &Compiler::compileErrorOccured, pMainWindow, &MainWindow::onCompileErrorOccured);
|
|
|
|
mBackgroundSyntaxChecker->start();
|
|
|
|
}
|
2021-06-24 20:43:09 +08:00
|
|
|
}
|
|
|
|
|
2022-06-16 21:34:31 +08:00
|
|
|
void CompilerManager::run(
|
|
|
|
const QString &filename,
|
|
|
|
const QString &arguments,
|
|
|
|
const QString &workDir,
|
|
|
|
const QStringList& binDirs)
|
2021-04-21 18:58:35 +08:00
|
|
|
{
|
2021-06-25 12:40:11 +08:00
|
|
|
QMutexLocker locker(&mRunnerMutex);
|
2021-12-23 17:07:27 +08:00
|
|
|
if (mRunner!=nullptr && !mRunner->pausing()) {
|
2021-04-21 18:58:35 +08:00
|
|
|
return;
|
|
|
|
}
|
2021-10-24 23:13:00 +08:00
|
|
|
QString redirectInputFilename;
|
|
|
|
bool redirectInput=false;
|
|
|
|
if (pSettings->executor().redirectInput()
|
|
|
|
&& !pSettings->executor().inputFilename().isEmpty()) {
|
|
|
|
redirectInput =true;
|
|
|
|
redirectInputFilename = pSettings->executor().inputFilename();
|
|
|
|
}
|
2021-11-01 09:18:23 +08:00
|
|
|
ExecutableRunner * execRunner;
|
2021-10-25 09:16:00 +08:00
|
|
|
if (programHasConsole(filename)) {
|
|
|
|
int consoleFlag=0;
|
|
|
|
if (redirectInput)
|
|
|
|
consoleFlag |= RPF_REDIRECT_INPUT;
|
|
|
|
if (pSettings->executor().pauseConsole())
|
|
|
|
consoleFlag |= RPF_PAUSE_CONSOLE;
|
2021-12-29 13:16:03 +08:00
|
|
|
#ifdef Q_OS_WIN
|
2021-11-07 19:54:48 +08:00
|
|
|
if (consoleFlag!=0) {
|
2022-03-16 20:08:39 +08:00
|
|
|
QString sharedMemoryId = QUuid::createUuid().toString();
|
|
|
|
QString newArguments = QString(" %1 %2 \"%3\" %4")
|
2021-11-07 19:54:48 +08:00
|
|
|
.arg(consoleFlag)
|
2022-03-16 20:08:39 +08:00
|
|
|
.arg(sharedMemoryId,localizePath(filename)).arg(arguments);
|
2022-10-10 18:05:18 +08:00
|
|
|
|
|
|
|
//delete when thread finished
|
2022-12-30 09:06:39 +08:00
|
|
|
execRunner = new ExecutableRunner(includeTrailingPathDelimiter(pSettings->dirs().appDir())+CONSOLE_PAUSER,newArguments,workDir);
|
2022-03-16 20:08:39 +08:00
|
|
|
execRunner->setShareMemoryId(sharedMemoryId);
|
2021-11-07 19:54:48 +08:00
|
|
|
} else {
|
2022-10-10 18:05:18 +08:00
|
|
|
//delete when thread finished
|
2021-11-07 19:54:48 +08:00
|
|
|
execRunner = new ExecutableRunner(filename,arguments,workDir);
|
|
|
|
}
|
2021-12-25 08:23:52 +08:00
|
|
|
#else
|
2021-12-29 13:16:03 +08:00
|
|
|
QString newArguments;
|
2022-03-16 20:39:11 +08:00
|
|
|
QString sharedMemoryId = "/r"+QUuid::createUuid().toString(QUuid::StringFormat::Id128);
|
2021-12-29 13:16:03 +08:00
|
|
|
if (consoleFlag!=0) {
|
2022-01-20 00:12:50 +08:00
|
|
|
QString consolePauserPath=includeTrailingPathDelimiter(pSettings->dirs().appLibexecDir())+"consolepauser";
|
|
|
|
if (!fileExists(consolePauserPath)) {
|
|
|
|
QMessageBox::critical(pMainWindow,
|
|
|
|
tr("Can't find Console Pauser"),
|
|
|
|
tr("Console Pauser \"%1\" doesn't exists!")
|
|
|
|
.arg(consolePauserPath));
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
2021-12-29 19:15:50 +08:00
|
|
|
if (redirectInput) {
|
2022-03-16 20:08:39 +08:00
|
|
|
newArguments = QString(" -e \"%1\" %2 %3 \"%4\" \"%5\" %6")
|
2022-01-20 00:12:50 +08:00
|
|
|
.arg(consolePauserPath)
|
2021-12-29 19:15:50 +08:00
|
|
|
.arg(consoleFlag)
|
2022-03-16 20:08:39 +08:00
|
|
|
.arg(sharedMemoryId)
|
2022-10-29 17:21:38 +08:00
|
|
|
.arg(escapeSpacesInString(redirectInputFilename))
|
|
|
|
.arg(localizePath(escapeSpacesInString(filename)))
|
2021-12-29 19:15:50 +08:00
|
|
|
.arg(arguments);
|
|
|
|
} else {
|
2022-03-16 20:08:39 +08:00
|
|
|
newArguments = QString(" -e \"%1\" %2 %3 \"%4\" %5")
|
2022-01-20 00:12:50 +08:00
|
|
|
.arg(consolePauserPath)
|
2021-12-29 13:16:03 +08:00
|
|
|
.arg(consoleFlag)
|
2022-10-29 17:21:38 +08:00
|
|
|
.arg(sharedMemoryId,localizePath(escapeSpacesInString(filename))).arg(arguments);
|
2021-12-29 19:15:50 +08:00
|
|
|
}
|
2021-12-29 13:16:03 +08:00
|
|
|
} else {
|
|
|
|
newArguments = QString(" -e \"%1\" %2")
|
2022-10-29 17:21:38 +08:00
|
|
|
.arg(localizePath(escapeSpacesInString(filename))).arg(arguments);
|
2021-12-29 13:16:03 +08:00
|
|
|
}
|
2023-03-04 18:44:39 +08:00
|
|
|
execRunner = new ExecutableRunner(pSettings->environment().terminalPathForExec(),newArguments,workDir);
|
2022-03-16 20:39:11 +08:00
|
|
|
execRunner->setShareMemoryId(sharedMemoryId);
|
2021-12-25 08:23:52 +08:00
|
|
|
#endif
|
2021-11-01 09:18:23 +08:00
|
|
|
execRunner->setStartConsole(true);
|
2021-04-21 18:58:35 +08:00
|
|
|
} else {
|
2022-10-10 18:05:18 +08:00
|
|
|
//delete when thread finished
|
2021-11-01 09:18:23 +08:00
|
|
|
execRunner = new ExecutableRunner(filename,arguments,workDir);
|
2021-12-29 19:15:50 +08:00
|
|
|
}
|
2021-10-25 09:16:00 +08:00
|
|
|
if (redirectInput) {
|
2021-11-01 09:18:23 +08:00
|
|
|
execRunner->setRedirectInput(true);
|
|
|
|
execRunner->setRedirectInputFilename(redirectInputFilename);
|
2021-10-25 09:16:00 +08:00
|
|
|
}
|
2022-06-16 21:34:31 +08:00
|
|
|
execRunner->addBinDirs(binDirs);
|
|
|
|
|
|
|
|
execRunner->addBinDir(pSettings->dirs().appDir());
|
|
|
|
|
2021-11-01 09:18:23 +08:00
|
|
|
mRunner = execRunner;
|
2022-06-16 21:34:31 +08:00
|
|
|
|
2021-11-01 09:18:23 +08:00
|
|
|
connect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated);
|
2021-12-23 17:07:27 +08:00
|
|
|
connect(mRunner, &Runner::finished, mRunner ,&Runner::deleteLater);
|
2021-11-01 09:18:23 +08:00
|
|
|
connect(mRunner, &Runner::finished, pMainWindow ,&MainWindow::onRunFinished);
|
2021-12-23 17:07:27 +08:00
|
|
|
connect(mRunner, &Runner::pausingForFinish, pMainWindow ,&MainWindow::onRunPausingForFinish);
|
2021-12-29 22:03:18 +08:00
|
|
|
connect(mRunner, &Runner::pausingForFinish, this ,&CompilerManager::onRunnerPausing);
|
2021-11-01 09:18:23 +08:00
|
|
|
connect(mRunner, &Runner::runErrorOccurred, pMainWindow ,&MainWindow::onRunErrorOccured);
|
|
|
|
mRunner->start();
|
|
|
|
}
|
|
|
|
|
2022-05-26 21:22:07 +08:00
|
|
|
|
2022-12-13 08:49:20 +08:00
|
|
|
void CompilerManager::runProblem(const QString &filename, const QString &arguments, const QString &workDir, POJProblemCase problemCase,
|
|
|
|
const POJProblem& problem
|
|
|
|
)
|
2021-11-01 09:18:23 +08:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&mRunnerMutex);
|
2022-12-13 08:49:20 +08:00
|
|
|
doRunProblem(filename, arguments, workDir, QVector<POJProblemCase> {problemCase}, problem);
|
2021-12-15 19:12:16 +08:00
|
|
|
|
2021-11-01 09:18:23 +08:00
|
|
|
}
|
|
|
|
|
2022-12-13 08:49:20 +08:00
|
|
|
void CompilerManager::runProblem(const QString &filename, const QString &arguments, const QString &workDir, const QVector<POJProblemCase>& problemCases,
|
|
|
|
const POJProblem& problem
|
|
|
|
)
|
2021-11-01 09:18:23 +08:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&mRunnerMutex);
|
2022-12-13 08:49:20 +08:00
|
|
|
doRunProblem(filename, arguments, workDir, problemCases, problem);
|
2022-05-26 21:22:07 +08:00
|
|
|
}
|
2022-12-13 08:49:20 +08:00
|
|
|
void CompilerManager::doRunProblem(const QString &filename, const QString &arguments, const QString &workDir, const QVector<POJProblemCase>& problemCases,
|
|
|
|
const POJProblem& problem)
|
2022-05-26 21:22:07 +08:00
|
|
|
{
|
2021-11-01 09:18:23 +08:00
|
|
|
if (mRunner!=nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
OJProblemCasesRunner * execRunner = new OJProblemCasesRunner(filename,arguments,workDir,problemCases);
|
|
|
|
mRunner = execRunner;
|
2022-12-13 08:49:20 +08:00
|
|
|
if (pSettings->executor().enableCaseLimit()) {
|
2022-05-21 10:44:39 +08:00
|
|
|
execRunner->setExecTimeout(pSettings->executor().caseTimeout());
|
2022-12-13 08:49:20 +08:00
|
|
|
execRunner->setMemoryLimit(pSettings->executor().caseMemoryLimit()*1024); //convert kb to bytes
|
|
|
|
}
|
|
|
|
size_t timeLimit = problem->getTimeLimit();
|
|
|
|
size_t memoryLimit = problem->getMemoryLimit();
|
|
|
|
if (timeLimit>0)
|
|
|
|
execRunner->setExecTimeout(timeLimit);
|
|
|
|
if (memoryLimit)
|
|
|
|
execRunner->setMemoryLimit(memoryLimit);
|
2021-11-01 09:18:23 +08:00
|
|
|
connect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated);
|
2022-05-26 21:22:07 +08:00
|
|
|
connect(mRunner, &Runner::finished, mRunner ,&Runner::deleteLater);
|
2021-11-01 20:44:08 +08:00
|
|
|
connect(mRunner, &Runner::finished, pMainWindow ,&MainWindow::onRunProblemFinished);
|
2021-11-01 09:18:23 +08:00
|
|
|
connect(mRunner, &Runner::runErrorOccurred, pMainWindow ,&MainWindow::onRunErrorOccured);
|
2021-11-01 20:44:08 +08:00
|
|
|
connect(execRunner, &OJProblemCasesRunner::caseStarted, pMainWindow, &MainWindow::onOJProblemCaseStarted);
|
2021-11-01 23:14:17 +08:00
|
|
|
connect(execRunner, &OJProblemCasesRunner::caseFinished, pMainWindow, &MainWindow::onOJProblemCaseFinished);
|
2022-01-28 00:31:11 +08:00
|
|
|
connect(execRunner, &OJProblemCasesRunner::newOutputGetted, pMainWindow, &MainWindow::onOJProblemCaseNewOutputGetted);
|
2022-03-27 11:44:52 +08:00
|
|
|
connect(execRunner, &OJProblemCasesRunner::resetOutput, pMainWindow, &MainWindow::onOJProblemCaseResetOutput);
|
2023-07-12 12:08:26 +08:00
|
|
|
if (pSettings->executor().redirectStderrToToolLog()) {
|
|
|
|
connect(execRunner, &OJProblemCasesRunner::logStderrOutput, pMainWindow, &MainWindow::logToolsOutput);
|
|
|
|
}
|
2021-04-21 18:58:35 +08:00
|
|
|
mRunner->start();
|
|
|
|
}
|
|
|
|
|
2021-06-25 12:40:11 +08:00
|
|
|
void CompilerManager::stopRun()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&mRunnerMutex);
|
2021-12-23 17:07:27 +08:00
|
|
|
if (mRunner!=nullptr) {
|
2021-06-25 12:40:11 +08:00
|
|
|
mRunner->stop();
|
2021-12-23 17:07:27 +08:00
|
|
|
disconnect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated);
|
|
|
|
mRunner=nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-29 22:03:18 +08:00
|
|
|
void CompilerManager::stopAllRunners()
|
|
|
|
{
|
|
|
|
emit signalStopAllRunners();
|
|
|
|
}
|
|
|
|
|
2021-12-23 17:07:27 +08:00
|
|
|
void CompilerManager::stopPausing()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&mRunnerMutex);
|
|
|
|
if (mRunner!=nullptr && mRunner->pausing()) {
|
|
|
|
disconnect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated);
|
|
|
|
mRunner->stop();
|
|
|
|
mRunner=nullptr;
|
|
|
|
}
|
2021-06-25 12:40:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompilerManager::stopCompile()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&mCompileMutex);
|
|
|
|
if (mCompiler!=nullptr)
|
|
|
|
mCompiler->stopCompile();
|
|
|
|
}
|
|
|
|
|
2021-09-26 19:40:52 +08:00
|
|
|
void CompilerManager::stopCheckSyntax()
|
|
|
|
{
|
2021-10-09 11:33:23 +08:00
|
|
|
QMutexLocker locker(&mBackgroundSyntaxCheckMutex);
|
2021-09-26 19:40:52 +08:00
|
|
|
if (mBackgroundSyntaxChecker!=nullptr)
|
|
|
|
mBackgroundSyntaxChecker->stopCompile();
|
|
|
|
}
|
|
|
|
|
2021-10-20 18:05:43 +08:00
|
|
|
bool CompilerManager::canCompile(const QString &)
|
2021-04-21 18:58:35 +08:00
|
|
|
{
|
|
|
|
return !compiling();
|
2021-04-20 22:24:33 +08:00
|
|
|
}
|
|
|
|
|
2022-12-25 12:00:09 +08:00
|
|
|
void CompilerManager::onCompileFinished(QString filename)
|
2021-04-20 22:24:33 +08:00
|
|
|
{
|
2021-06-25 12:40:11 +08:00
|
|
|
QMutexLocker locker(&mCompileMutex);
|
2021-06-24 16:05:19 +08:00
|
|
|
mCompiler=nullptr;
|
2022-12-25 12:00:09 +08:00
|
|
|
pMainWindow->onCompileFinished(filename,false);
|
2021-04-20 22:24:33 +08:00
|
|
|
}
|
|
|
|
|
2021-04-21 18:58:35 +08:00
|
|
|
void CompilerManager::onRunnerTerminated()
|
|
|
|
{
|
2021-06-25 12:40:11 +08:00
|
|
|
QMutexLocker locker(&mRunnerMutex);
|
2021-04-21 18:58:35 +08:00
|
|
|
mRunner=nullptr;
|
|
|
|
}
|
|
|
|
|
2021-12-29 22:03:18 +08:00
|
|
|
void CompilerManager::onRunnerPausing()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&mRunnerMutex);
|
|
|
|
disconnect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated);
|
|
|
|
disconnect(mRunner, &Runner::finished, pMainWindow ,&MainWindow::onRunFinished);
|
|
|
|
disconnect(mRunner, &Runner::runErrorOccurred, pMainWindow ,&MainWindow::onRunErrorOccured);
|
|
|
|
connect(this, &CompilerManager::signalStopAllRunners, mRunner, &Runner::stop);
|
|
|
|
mRunner=nullptr;
|
|
|
|
}
|
|
|
|
|
2021-09-26 22:52:19 +08:00
|
|
|
void CompilerManager::onCompileIssue(PCompileIssue issue)
|
2021-06-24 16:05:19 +08:00
|
|
|
{
|
2021-09-26 22:52:19 +08:00
|
|
|
if (issue->type == CompileIssueType::Error)
|
|
|
|
mCompileErrorCount++;
|
|
|
|
mCompileIssueCount++;
|
2021-06-24 16:05:19 +08:00
|
|
|
}
|
|
|
|
|
2022-12-25 12:00:09 +08:00
|
|
|
void CompilerManager::onSyntaxCheckFinished(QString filename)
|
2021-06-24 20:43:09 +08:00
|
|
|
{
|
2021-06-25 12:40:11 +08:00
|
|
|
QMutexLocker locker(&mBackgroundSyntaxCheckMutex);
|
2021-06-24 20:43:09 +08:00
|
|
|
mBackgroundSyntaxChecker=nullptr;
|
2022-12-25 12:00:09 +08:00
|
|
|
pMainWindow->onCompileFinished(filename, true);
|
2021-06-24 20:43:09 +08:00
|
|
|
}
|
|
|
|
|
2021-09-26 22:52:19 +08:00
|
|
|
void CompilerManager::onSyntaxCheckIssue(PCompileIssue issue)
|
2021-06-24 20:43:09 +08:00
|
|
|
{
|
2021-09-26 22:52:19 +08:00
|
|
|
if (issue->type == CompileIssueType::Error)
|
|
|
|
mSyntaxCheckErrorCount++;
|
2021-11-22 18:42:58 +08:00
|
|
|
if (issue->type == CompileIssueType::Error ||
|
|
|
|
issue->type == CompileIssueType::Warning)
|
|
|
|
mSyntaxCheckIssueCount++;
|
2021-09-26 22:52:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int CompilerManager::syntaxCheckIssueCount() const
|
|
|
|
{
|
|
|
|
return mSyntaxCheckIssueCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CompilerManager::compileIssueCount() const
|
|
|
|
{
|
|
|
|
return mCompileIssueCount;
|
2021-06-24 20:43:09 +08:00
|
|
|
}
|
|
|
|
|
2021-06-23 22:38:02 +08:00
|
|
|
int CompilerManager::syntaxCheckErrorCount() const
|
|
|
|
{
|
|
|
|
return mSyntaxCheckErrorCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CompilerManager::compileErrorCount() const
|
|
|
|
{
|
|
|
|
return mCompileErrorCount;
|
|
|
|
}
|
|
|
|
|
2021-06-21 11:21:26 +08:00
|
|
|
CompileError::CompileError(const QString &reason):BaseError(reason)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|