From 78ea33d1521af7576192eac23551389d6ad053b0 Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Fri, 17 Sep 2021 19:58:37 +0800 Subject: [PATCH] - done: view makefile --- RedPandaIDE/compiler/compilermanager.cpp | 19 ++++++++++++++ RedPandaIDE/compiler/compilermanager.h | 1 + RedPandaIDE/compiler/projectcompiler.cpp | 32 ++++++++++++++++-------- RedPandaIDE/compiler/projectcompiler.h | 2 +- RedPandaIDE/editorlist.cpp | 3 --- RedPandaIDE/mainwindow.cpp | 25 ++++++++++++++++-- RedPandaIDE/mainwindow.h | 2 ++ RedPandaIDE/mainwindow.ui | 7 ++++-- RedPandaIDE/project.cpp | 10 ++++++-- RedPandaIDE/project.h | 2 +- 10 files changed, 81 insertions(+), 22 deletions(-) diff --git a/RedPandaIDE/compiler/compilermanager.cpp b/RedPandaIDE/compiler/compilermanager.cpp index 070e8755..26aa8ce3 100644 --- a/RedPandaIDE/compiler/compilermanager.cpp +++ b/RedPandaIDE/compiler/compilermanager.cpp @@ -88,6 +88,25 @@ void CompilerManager::compileProject(std::shared_ptr project, bool rebu } } +void CompilerManager::buildProjectMakefile(std::shared_ptr 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(); + } + +} + void CompilerManager::checkSyntax(const QString &filename, const QString &content, bool isAscii, std::shared_ptr project) { if (!pSettings->compilerSets().defaultSet()) { diff --git a/RedPandaIDE/compiler/compilermanager.h b/RedPandaIDE/compiler/compilermanager.h index 2327a3ed..d6abc577 100644 --- a/RedPandaIDE/compiler/compilermanager.h +++ b/RedPandaIDE/compiler/compilermanager.h @@ -21,6 +21,7 @@ public: void compile(const QString& filename, const QByteArray& encoding, bool rebuild, bool silent=false,bool onlyCheckSyntax=false); void compileProject(std::shared_ptr project, bool rebuild, bool silent=false,bool onlyCheckSyntax=false); + void buildProjectMakefile(std::shared_ptr project); void checkSyntax(const QString&filename, const QString& content, bool isAscii, std::shared_ptr project); void run(const QString& filename, const QString& arguments, const QString& workDir); void stopRun(); diff --git a/RedPandaIDE/compiler/projectcompiler.cpp b/RedPandaIDE/compiler/projectcompiler.cpp index fdecb826..6fd2e535 100644 --- a/RedPandaIDE/compiler/projectcompiler.cpp +++ b/RedPandaIDE/compiler/projectcompiler.cpp @@ -121,6 +121,7 @@ void ProjectCompiler::writeMakeDefines(QFile &file) // Get list of object files QString Objects; QString LinkObjects; + QString cleanObjects; // Create a list of object files for (int i=0;iunits().count();i++) { @@ -134,15 +135,19 @@ void ProjectCompiler::writeMakeDefines(QFile &file) if (fileType == FileType::CSource || fileType == FileType::CppSource) { if (!mProject->options().objectOutput.isEmpty()) { // ofile = C:\MyProgram\obj\main.o - QString ObjFile = includeTrailingPathDelimiter(mProject->options().objectOutput) + QString fullObjFile = includeTrailingPathDelimiter(mProject->options().objectOutput) + extractFileName(unit->fileName()); - ObjFile = genMakePath1(extractRelativePath(mProject->directory(), changeFileExt(ObjFile, OBJ_EXT))); + QString relativeObjFile = extractRelativePath(mProject->directory(), changeFileExt(fullObjFile, OBJ_EXT)); + QString ObjFile = genMakePath2(relativeObjFile); Objects += ' ' + ObjFile; - if (unit->link()) - LinkObjects += ' ' + ObjFile; + cleanObjects += ' ' + genMakePath1(relativeObjFile); + if (unit->link()) { + LinkObjects += ' ' + genMakePath1(relativeObjFile); + } } else { - Objects += ' ' + genMakePath1(changeFileExt(RelativeName, OBJ_EXT)); + Objects += ' ' + genMakePath2(changeFileExt(RelativeName, OBJ_EXT)); + cleanObjects += ' ' + genMakePath1(changeFileExt(RelativeName, OBJ_EXT)); if (unit->link()) LinkObjects = LinkObjects + ' ' + genMakePath1(changeFileExt(RelativeName, OBJ_EXT)); } @@ -187,9 +192,11 @@ void ProjectCompiler::writeMakeDefines(QFile &file) writeln(file,"RES = " + genMakePath1(ObjResFile)); writeln(file,"OBJ = " + Objects + " $(RES)"); writeln(file,"LINKOBJ = " + LinkObjects + " $(RES)"); + writeln(file,"CLEANOBJ = " + cleanObjects + " $(RES)"); } else { writeln(file,"OBJ = " + Objects); writeln(file,"LINKOBJ = " + LinkObjects); + writeln(file,"CLEANOBJ = " + cleanObjects); }; libraryArguments.replace('\\', '/'); writeln(file,"LIBS = " + libraryArguments); @@ -256,9 +263,9 @@ void ProjectCompiler::writeMakeClean(QFile &file) { writeln(file, "clean: clean-custom"); if (mProject->options().type == ProjectType::DynamicLib) - writeln(file, "\t${RM} $(OBJ) $(BIN) $(DEF) $(STATIC)"); + writeln(file, "\t${RM} $(CLEANOBJ) $(BIN) $(DEF) $(STATIC)"); else - writeln(file, "\t${RM} $(OBJ) $(BIN)"); + writeln(file, "\t${RM} $(CLEANOBJ) $(BIN)"); writeln(file); } @@ -299,15 +306,18 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file) } } QString ObjFileName; + QString ObjFileName2; if (!mProject->options().objectOutput.isEmpty()) { ObjFileName = includeTrailingPathDelimiter(mProject->options().objectOutput) + extractFileName(unit->fileName()); - ObjFileName = genMakePath1(extractRelativePath(mProject->makeFileName(), changeFileExt(ObjFileName, OBJ_EXT))); + ObjFileName = genMakePath2(extractRelativePath(mProject->makeFileName(), changeFileExt(ObjFileName, OBJ_EXT))); + ObjFileName2 = genMakePath1(extractRelativePath(mProject->makeFileName(), changeFileExt(ObjFileName, OBJ_EXT))); if (!extractFileDir(ObjFileName).isEmpty()) { objStr = genMakePath2(includeTrailingPathDelimiter(extractFileDir(ObjFileName))) + objStr; } } else { - ObjFileName = genMakePath1(changeFileExt(shortFileName, OBJ_EXT)); + ObjFileName = genMakePath2(changeFileExt(shortFileName, OBJ_EXT)); + ObjFileName2 = genMakePath1(changeFileExt(shortFileName, OBJ_EXT)); } objStr = ObjFileName + ": "+objStr+precompileStr; @@ -343,9 +353,9 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file) writeln(file, "\t(CC) -c " + genMakePath1(shortFileName) + " $(CFLAGS) " + encodingStr); } else { if (unit->compileCpp()) - writeln(file, "\t$(CPP) -c " + genMakePath1(shortFileName) + " -o " + ObjFileName + " $(CXXFLAGS) " + encodingStr); + writeln(file, "\t$(CPP) -c " + genMakePath1(shortFileName) + " -o " + ObjFileName2 + " $(CXXFLAGS) " + encodingStr); else - writeln(file, "\t$(CC) -c " + genMakePath1(shortFileName) + " -o " + ObjFileName + " $(CFLAGS) " + encodingStr); + writeln(file, "\t$(CC) -c " + genMakePath1(shortFileName) + " -o " + ObjFileName2 + " $(CFLAGS) " + encodingStr); } } } diff --git a/RedPandaIDE/compiler/projectcompiler.h b/RedPandaIDE/compiler/projectcompiler.h index cf7e47d8..779d726f 100644 --- a/RedPandaIDE/compiler/projectcompiler.h +++ b/RedPandaIDE/compiler/projectcompiler.h @@ -10,9 +10,9 @@ class ProjectCompiler : public Compiler Q_OBJECT public: ProjectCompiler(std::shared_ptr project, bool silent,bool onlyCheckSyntax); + void buildMakeFile(); private: - void buildMakeFile(); void createStandardMakeFile(); void createStaticMakeFile(); void createDynamicMakeFile(); diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index 32705b6d..d8d47023 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include "settings.h" #include "project.h" @@ -322,8 +321,6 @@ void EditorList::getVisibleEditors(Editor *&left, Editor *&right) void EditorList::updateLayout() { - qDebug()<count(); - qDebug()<count(); if (mLeftPageWidget->count() ==0 && mRightPageWidget->count() == 0) showLayout(LayoutShowType::lstNone); else if (mLeftPageWidget->count() > 0 && mRightPageWidget->count() == 0) diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index e7b0ea71..8d2f4278 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1463,7 +1463,7 @@ void MainWindow::openShell(const QString &folder, const QString &shellCommand) } pathAdded.append(pSettings->dirs().app()); if (!path.isEmpty()) { - path+= PATH_SEPARATOR + pathAdded.join(PATH_SEPARATOR); + path= pathAdded.join(PATH_SEPARATOR) + PATH_SEPARATOR + path; } else { path = pathAdded.join(PATH_SEPARATOR); } @@ -1926,6 +1926,7 @@ void MainWindow::onCompilerSetChanged(int index) void MainWindow::onCompileLog(const QString &msg) { ui->txtCompilerOutput->appendPlainText(msg); + ui->txtCompilerOutput->ensureCursorVisible(); } void MainWindow::onCompileIssue(PCompileIssue issue) @@ -3061,7 +3062,7 @@ void MainWindow::on_actionRemove_from_project_triggered() continue; FolderNode * node = static_cast(index.internalPointer()); PFolderNode folderNode = mProject->pointerToNode(node); - if (folderNode) + if (!folderNode) continue; selected.insert(folderNode->unitIndex); }; @@ -3075,3 +3076,23 @@ void MainWindow::on_actionRemove_from_project_triggered() updateProjectView(); } + +void MainWindow::on_actionView_Makefile_triggered() +{ + if (!mProject) + return; + if (!mProject->saveUnits()) + return; + // Check if saves have been succesful + for (int i=0; ipageCount();i++) { + Editor * e= (*(mEditorList))[i]; + if (e->inProject() && e->modified()) + return; + } + mProject->buildPrivateResource(); + mCompilerManager->buildProjectMakefile(mProject); + + openFile(mProject->makeFileName()); + +} + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 347f34ea..506c8eb4 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -320,6 +320,8 @@ private slots: void on_actionRemove_from_project_triggered(); + void on_actionView_Makefile_triggered(); + private: Ui::MainWindow *ui; EditorList *mEditorList; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index dd9e6dd8..74c2da38 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -110,7 +110,10 @@ - QAbstractItemView::MultiSelection + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::SelectRows false @@ -279,7 +282,7 @@ QTabWidget::South - 3 + 1 diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index e34eee8c..3dfb0f92 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -581,11 +581,17 @@ void Project::updateNodeIndexes() mUnits[idx]->node()->unitIndex = idx; } -PFolderNode Project::pointerToNode(FolderNode *p) +PFolderNode Project::pointerToNode(FolderNode *p, PFolderNode parent) { - foreach (const PFolderNode& node , mFolderNodes) { + if (!parent) { + parent = mNode; + } + foreach (const PFolderNode& node , parent->children) { if (node.get()==p) return node; + PFolderNode result = pointerToNode(p,node); + if (result) + return result; } return PFolderNode(); } diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index 36654b32..1facf114 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -151,7 +151,7 @@ public: void sortUnitsByAlpha(); void updateFolders(); void updateNodeIndexes(); - PFolderNode pointerToNode(FolderNode * p); + PFolderNode pointerToNode(FolderNode * p, PFolderNode parent=PFolderNode()); //void showOptions(); bool assignTemplate(const std::shared_ptr aTemplate);