work save

This commit is contained in:
royqh1979 2021-09-13 07:49:36 +08:00
parent fdafe622f1
commit e03f537a4e
10 changed files with 104 additions and 32 deletions

View File

@ -20,6 +20,7 @@ SOURCES += \
codeformatter.cpp \
codetemplate.cpp \
colorscheme.cpp \
compiler/projectcompiler.cpp \
platform.cpp \
compiler/compiler.cpp \
compiler/compilermanager.cpp \
@ -105,6 +106,7 @@ HEADERS += \
compiler/compilermanager.h \
compiler/executablerunner.h \
compiler/filecompiler.h \
compiler/projectcompiler.h \
compiler/stdincompiler.h \
cpprefacter.h \
parser/cppparser.h \

View File

@ -32,32 +32,36 @@ Compiler::Compiler(const QString &filename, bool silent, bool onlyCheckSyntax):
void Compiler::run()
{
emit compileStarted();
auto action = finally([this]{
emit compileFinished();
});
try {
if (!prepareForCompile()){
return;
}
if (mRebuild && !prepareForRebuild()) {
throw CompileError(tr("Clean before rebuild failed."));
}
if (prepareForCompile()){
mErrorCount = 0;
mWarningCount = 0;
QElapsedTimer timer;
timer.start();
runCommand(mCompiler, mArguments, QFileInfo(mCompiler).absolutePath(), pipedText());
log("");
log(tr("Compile Result:"));
log("------------------");
log(tr("- Errors: %1").arg(mErrorCount));
log(tr("- Warnings: %1").arg(mWarningCount));
if (!mOutputFile.isEmpty()) {
log(tr("- Output Filename: %1").arg(mOutputFile));
QLocale locale = QLocale::system();
log(tr("- Output Size: %1").arg(locale.formattedDataSize(QFileInfo(mOutputFile).size())));
}
log(tr("- Compilation Time: %1 secs").arg(timer.elapsed() / 1000.0));
mErrorCount = 0;
mWarningCount = 0;
QElapsedTimer timer;
timer.start();
runCommand(mCompiler, mArguments, QFileInfo(mCompiler).absolutePath(), pipedText());
log("");
log(tr("Compile Result:"));
log("------------------");
log(tr("- Errors: %1").arg(mErrorCount));
log(tr("- Warnings: %1").arg(mWarningCount));
if (!mOutputFile.isEmpty()) {
log(tr("- Output Filename: %1").arg(mOutputFile));
QLocale locale = QLocale::system();
log(tr("- Output Size: %1").arg(locale.formattedDataSize(QFileInfo(mOutputFile).size())));
}
log(tr("- Compilation Time: %1 secs").arg(timer.elapsed() / 1000.0));
} catch (CompileError e) {
emit compileErrorOccured(e.reason());
}
emit compileFinished();
}
QString Compiler::getFileNameFromOutputLine(QString &line) {
@ -150,6 +154,11 @@ CompileIssueType Compiler::getIssueTypeFromOutputLine(QString &line)
return result;
}
Settings::PCompilerSet Compiler::compilerSet()
{
return pSettings->compilerSets().defaultSet();
}
void Compiler::processOutput(QString &line)
{
if (line == COMPILE_PROCESS_END) {

View File

@ -44,7 +44,7 @@ protected:
virtual CompileIssueType getIssueTypeFromOutputLine(QString &line);
protected:
virtual Settings::PCompilerSet compilerSet() = 0;
virtual Settings::PCompilerSet compilerSet();
virtual bool prepareForCompile() = 0;
virtual QString pipedText() = 0;
virtual bool prepareForRebuild() = 0;

View File

@ -15,11 +15,6 @@ FileCompiler::FileCompiler(const QString &filename, const QByteArray &encoding,b
}
Settings::PCompilerSet FileCompiler::compilerSet()
{
return pSettings->compilerSets().defaultSet();
}
bool FileCompiler::prepareForCompile()
{
log(tr("Compiling single file..."));

View File

@ -11,7 +11,6 @@ public:
// Compiler interface
protected:
Settings::PCompilerSet compilerSet() override;
bool prepareForCompile() override;
private:

View File

@ -0,0 +1,48 @@
#include "projectcompiler.h"
#include "project.h"
ProjectCompiler::ProjectCompiler(std::shared_ptr<Project> project, bool silent, bool onlyCheckSyntax):
Compiler("",silent,onlyCheckSyntax)
{
setProject(project);
}
void ProjectCompiler::buildMakeFile()
{
if (mProject->options().useCustomMakefile)
mMakefileName = mProject->options().customMakefile;
return;
switch(mProject->options().type) {
case ProjectType::StaticLib:
createStaticMakeFile();
break;
case ProjectType::DynamicLib:
createDynamicMakeFile();
break;
default:
createStandardMakeFile();
}
}
QString ProjectCompiler::pipedText()
{
return QString();
}
bool ProjectCompiler::prepareForCompile()
{
if (!mProject)
return false;
//initProgressForm();
log(tr("Compiling project changes..."));
log("--------");
log(tr("- Project Filename: %1").arg(mProject->filename()));
log(tr("- Compiler Set Name: %1").arg(compilerSet()->name()));
log("");
buildMakeFile();
mCompiler = QString("%1 -f \"%2\" all").arg(compilerSet()->make(),
mMakefileName);
}

View File

@ -0,0 +1,25 @@
#ifndef PROJECTCOMPILER_H
#define PROJECTCOMPILER_H
#include "compiler.h"
#include <QObject>
class Project;
class ProjectCompiler : public Compiler
{
Q_OBJECT
public:
ProjectCompiler(std::shared_ptr<Project> project, bool silent,bool onlyCheckSyntax);
private:
void buildMakeFile();
// Compiler interface
protected:
bool prepareForCompile() override;
QString pipedText() override;
bool prepareForRebuild() override;
private:
QString mMakefileName;
};
#endif // PROJECTCOMPILER_H

View File

@ -12,11 +12,6 @@ StdinCompiler::StdinCompiler(const QString &filename, const QString& content,boo
}
Settings::PCompilerSet StdinCompiler::compilerSet()
{
return pSettings->compilerSets().defaultSet();
}
bool StdinCompiler::prepareForCompile()
{
log(tr("Checking file syntax..."));

View File

@ -12,7 +12,6 @@ public:
// Compiler interface
protected:
Settings::PCompilerSet compilerSet() override;
bool prepareForCompile() override;
private:

View File

@ -12,7 +12,7 @@
#define MAKE_PROGRAM "mingw32-make.exe"
#define WINDRES_PROGRAM "windres.exe"
#define GPROF_PROGRAM "gprof.exe"
#define CLEAN_PROGRAM "rm.exe"
#define CLEAN_PROGRAM "del /q"
#define CPP_PROGRAM "cpp.exe"
#else
#error "Only support windows now!"