2021-04-20 22:24:33 +08:00
|
|
|
#include "compilermanager.h"
|
|
|
|
#include "filecompiler.h"
|
|
|
|
#include <QDebug>
|
|
|
|
#include "../mainwindow.h"
|
2021-04-21 18:58:35 +08:00
|
|
|
#include "executablerunner.h"
|
|
|
|
#include "utils.h"
|
2021-04-20 22:24:33 +08:00
|
|
|
|
|
|
|
CompilerManager::CompilerManager(QObject *parent) : QObject(parent)
|
|
|
|
{
|
|
|
|
mCompiler = nullptr;
|
|
|
|
mBackgroundSyntaxChecker = nullptr;
|
2021-04-21 18:58:35 +08:00
|
|
|
mRunner = nullptr;
|
2021-06-23 22:38:02 +08:00
|
|
|
mSyntaxCheckErrorCount = 0;
|
|
|
|
mCompileErrorCount = 0;
|
2021-04-20 22:24:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CompilerManager::compiling()
|
|
|
|
{
|
|
|
|
return mCompiler!=nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CompilerManager::backgroundSyntaxChecking()
|
|
|
|
{
|
|
|
|
return mBackgroundSyntaxChecker!=nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompilerManager::compile(const QString& filename, const QByteArray& encoding, bool silent, bool onlyCheckSyntax)
|
|
|
|
{
|
2021-04-21 18:58:35 +08:00
|
|
|
QMutexLocker locker(&compileMutex);
|
|
|
|
if (mCompiler!=nullptr) {
|
|
|
|
return;
|
2021-04-20 22:24:33 +08:00
|
|
|
}
|
2021-06-23 22:38:02 +08:00
|
|
|
mCompileErrorCount = 0;
|
2021-04-21 18:58:35 +08:00
|
|
|
mCompiler = new FileCompiler(filename,encoding,silent,onlyCheckSyntax);
|
|
|
|
connect(mCompiler, &Compiler::compileFinished, this ,&CompilerManager::onCompileFinished);
|
2021-06-24 16:05:19 +08:00
|
|
|
connect(mCompiler, &Compiler::compileIssue, this, &CompilerManager::onCompileIssue);
|
2021-06-23 22:38:02 +08:00
|
|
|
connect(mCompiler, &Compiler::compileFinished, pMainWindow, &MainWindow::onCompileFinished);
|
2021-04-21 18:58:35 +08:00
|
|
|
connect(mCompiler, &Compiler::compileOutput, pMainWindow, &MainWindow::onCompileLog);
|
2021-04-24 15:57:45 +08:00
|
|
|
connect(mCompiler, &Compiler::compileIssue, pMainWindow, &MainWindow::onCompileIssue);
|
2021-06-21 11:21:26 +08:00
|
|
|
connect(mCompiler, &Compiler::compileErrorOccured, pMainWindow, &MainWindow::onCompileErrorOccured);
|
2021-04-21 18:58:35 +08:00
|
|
|
mCompiler->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompilerManager::run(const QString &filename, const QString &arguments, const QString &workDir)
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&runnerMutex);
|
|
|
|
if (mRunner!=nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (programHasConsole(filename)) {
|
|
|
|
QString newArguments = QString(" 0 \"%1\" %2").arg(toLocalPath(filename)).arg(arguments);
|
|
|
|
mRunner = new ExecutableRunner(includeTrailingPathDelimiter(pSettings->dirs().app())+"ConsolePauser.exe",newArguments,workDir);
|
|
|
|
} else {
|
|
|
|
mRunner = new ExecutableRunner(filename,arguments,workDir);
|
|
|
|
}
|
|
|
|
connect(mRunner, &ExecutableRunner::terminated, this ,&CompilerManager::onRunnerTerminated);
|
|
|
|
mRunner->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CompilerManager::canCompile(const QString &filename)
|
|
|
|
{
|
|
|
|
return !compiling();
|
2021-04-20 22:24:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompilerManager::onCompileFinished()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&compileMutex);
|
2021-04-24 15:57:45 +08:00
|
|
|
delete mCompiler;
|
2021-06-24 16:05:19 +08:00
|
|
|
mCompiler=nullptr;
|
2021-04-20 22:24:33 +08:00
|
|
|
}
|
|
|
|
|
2021-04-21 18:58:35 +08:00
|
|
|
void CompilerManager::onRunnerTerminated()
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&runnerMutex);
|
|
|
|
qDebug() << "Runner Terminated";
|
|
|
|
mRunner=nullptr;
|
|
|
|
}
|
|
|
|
|
2021-06-24 16:05:19 +08:00
|
|
|
void CompilerManager::onCompileIssue(PCompileIssue)
|
|
|
|
{
|
|
|
|
mCompileErrorCount ++;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|