From fb21b78444fa2ff18fecaf45db36bd72b3dfe734 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 13 Aug 2019 12:47:11 +0200 Subject: [PATCH] Autotools: Introduce AutotoolsBuildSystem Introduce AutotoolsBuildSystem and slim down AutotoolsProject. Change-Id: I68296152f9ecd5d14198c8d0b36a06c2d1b162ec Reviewed-by: Christian Kandeler --- .../autotoolsprojectmanager/CMakeLists.txt | 2 +- .../autotoolsprojectmanager/autogenstep.cpp | 7 +- .../autoreconfstep.cpp | 6 +- .../autotoolsbuildconfiguration.cpp | 7 +- ...lsproject.cpp => autotoolsbuildsystem.cpp} | 148 ++++++------------ ...otoolsproject.h => autotoolsbuildsystem.h} | 32 +--- .../autotoolsopenprojectwizard.cpp | 3 +- .../autotoolsprojectmanager.pro | 8 +- .../autotoolsprojectmanager.qbs | 4 +- .../autotoolsprojectplugin.cpp | 24 ++- .../autotoolsprojectplugin.h | 16 ++ .../autotoolsprojectmanager/configurestep.cpp | 18 +-- .../makefileparser.cpp | 7 +- .../autotoolsprojectmanager/makestep.cpp | 2 - src/plugins/projectexplorer/project.h | 2 +- 15 files changed, 113 insertions(+), 173 deletions(-) rename src/plugins/autotoolsprojectmanager/{autotoolsproject.cpp => autotoolsbuildsystem.cpp} (59%) rename src/plugins/autotoolsprojectmanager/{autotoolsproject.h => autotoolsbuildsystem.h} (70%) diff --git a/src/plugins/autotoolsprojectmanager/CMakeLists.txt b/src/plugins/autotoolsprojectmanager/CMakeLists.txt index ca8765cba91..ac341c3eafb 100644 --- a/src/plugins/autotoolsprojectmanager/CMakeLists.txt +++ b/src/plugins/autotoolsprojectmanager/CMakeLists.txt @@ -4,8 +4,8 @@ add_qtc_plugin(AutotoolsProjectManager autogenstep.cpp autogenstep.h autoreconfstep.cpp autoreconfstep.h autotoolsbuildconfiguration.cpp autotoolsbuildconfiguration.h + autotoolsbuildsystem.cpp autotoolsbuildsystem.h autotoolsopenprojectwizard.cpp autotoolsopenprojectwizard.h - autotoolsproject.cpp autotoolsproject.h autotoolsprojectconstants.h autotoolsprojectplugin.cpp autotoolsprojectplugin.h configurestep.cpp configurestep.h diff --git a/src/plugins/autotoolsprojectmanager/autogenstep.cpp b/src/plugins/autotoolsprojectmanager/autogenstep.cpp index 1fe6520c3bb..2541c1169c0 100644 --- a/src/plugins/autotoolsprojectmanager/autogenstep.cpp +++ b/src/plugins/autotoolsprojectmanager/autogenstep.cpp @@ -26,14 +26,12 @@ ****************************************************************************/ #include "autogenstep.h" + #include "autotoolsprojectconstants.h" #include -#include -#include #include -#include -#include +#include #include #include @@ -43,7 +41,6 @@ using namespace AutotoolsProjectManager::Internal; using namespace ProjectExplorer; using namespace Utils; - // AutogenStepFactory AutogenStepFactory::AutogenStepFactory() diff --git a/src/plugins/autotoolsprojectmanager/autoreconfstep.cpp b/src/plugins/autotoolsprojectmanager/autoreconfstep.cpp index fa15515078b..eeb3da11187 100644 --- a/src/plugins/autotoolsprojectmanager/autoreconfstep.cpp +++ b/src/plugins/autotoolsprojectmanager/autoreconfstep.cpp @@ -26,14 +26,12 @@ ****************************************************************************/ #include "autoreconfstep.h" + #include "autotoolsprojectconstants.h" #include -#include -#include #include -#include -#include +#include #include using namespace AutotoolsProjectManager; diff --git a/src/plugins/autotoolsprojectmanager/autotoolsbuildconfiguration.cpp b/src/plugins/autotoolsprojectmanager/autotoolsbuildconfiguration.cpp index 64f31d6642c..42f665b0e63 100644 --- a/src/plugins/autotoolsprojectmanager/autotoolsbuildconfiguration.cpp +++ b/src/plugins/autotoolsprojectmanager/autotoolsbuildconfiguration.cpp @@ -27,18 +27,13 @@ #include "autotoolsbuildconfiguration.h" -#include "autotoolsproject.h" #include "autotoolsprojectconstants.h" -#include #include #include -#include +#include #include #include -#include -#include -#include using namespace AutotoolsProjectManager::Constants; using namespace ProjectExplorer; diff --git a/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp b/src/plugins/autotoolsprojectmanager/autotoolsbuildsystem.cpp similarity index 59% rename from src/plugins/autotoolsprojectmanager/autotoolsproject.cpp rename to src/plugins/autotoolsprojectmanager/autotoolsbuildsystem.cpp index 6487d424da3..1adf9e003dc 100644 --- a/src/plugins/autotoolsprojectmanager/autotoolsproject.cpp +++ b/src/plugins/autotoolsprojectmanager/autotoolsbuildsystem.cpp @@ -25,67 +25,36 @@ ** ****************************************************************************/ -#include "autotoolsproject.h" -#include "autotoolsbuildconfiguration.h" -#include "autotoolsprojectconstants.h" -#include "autotoolsopenprojectwizard.h" -#include "makestep.h" -#include "makefileparserthread.h" +#include "autotoolsbuildsystem.h" + +#include "makefileparserthread.h" +#include "makestep.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include +#include +#include #include -#include -#include -#include + #include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace AutotoolsProjectManager; -using namespace AutotoolsProjectManager::Internal; using namespace ProjectExplorer; -AutotoolsProject::AutotoolsProject(const Utils::FilePath &fileName) - : Project(Constants::MAKEFILE_MIMETYPE, fileName) +namespace AutotoolsProjectManager { +namespace Internal { + +AutotoolsBuildSystem::AutotoolsBuildSystem(Project *project) + : BuildSystem(project) , m_cppCodeModelUpdater(new CppTools::CppProjectUpdater) { - setId(Constants::AUTOTOOLS_PROJECT_ID); - setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID)); - setDisplayName(projectDirectory().fileName()); + connect(project, &Project::activeBuildConfigurationChanged, this, [this]() { requestParse(); }); - setHasMakeInstallEquivalent(true); - - connect(this, &AutotoolsProject::projectFileIsDirty, this, &AutotoolsProject::loadProjectTree); + connect(project, &Project::projectFileIsDirty, this, [this]() { requestParse(); }); } -AutotoolsProject::~AutotoolsProject() +AutotoolsBuildSystem::~AutotoolsBuildSystem() { delete m_cppCodeModelUpdater; - setRootProjectNode(nullptr); - if (m_makefileParserThread) { m_makefileParserThread->wait(); delete m_makefileParserThread; @@ -93,65 +62,42 @@ AutotoolsProject::~AutotoolsProject() } } -// This function, is called at the very beginning, to -// restore the settings if there are some stored. -Project::RestoreResult AutotoolsProject::fromMap(const QVariantMap &map, QString *errorMessage) -{ - RestoreResult result = Project::fromMap(map, errorMessage); - if (result != RestoreResult::Ok) - return result; - - // Load the project tree structure. - loadProjectTree(); - - if (!activeTarget()) - addTargetForDefaultKit(); - - return RestoreResult::Ok; -} - -void AutotoolsProject::loadProjectTree() +void AutotoolsBuildSystem::parseProject(BuildSystem::ParsingContext &&ctx) { if (m_makefileParserThread) { - // The thread is still busy parsing a previus configuration. + // The thread is still busy parsing a previous configuration. // Wait until the thread has been finished and delete it. // TODO: Discuss whether blocking is acceptable. - disconnect(m_makefileParserThread, &QThread::finished, - this, &AutotoolsProject::makefileParsingFinished); + disconnect(m_makefileParserThread, + &QThread::finished, + this, + &AutotoolsBuildSystem::makefileParsingFinished); m_makefileParserThread->wait(); delete m_makefileParserThread; m_makefileParserThread = nullptr; } // Parse the makefile asynchronously in a thread - m_makefileParserThread = new MakefileParserThread(projectFilePath().toString(), - guardParsingRun()); + m_makefileParserThread = new MakefileParserThread(project()->projectFilePath().toString(), + std::move(ctx.guard)); - connect(m_makefileParserThread, &MakefileParserThread::started, - this, &AutotoolsProject::makefileParsingStarted); - - connect(m_makefileParserThread, &MakefileParserThread::finished, - this, &AutotoolsProject::makefileParsingFinished); + connect(m_makefileParserThread, + &MakefileParserThread::finished, + this, + &AutotoolsBuildSystem::makefileParsingFinished); m_makefileParserThread->start(); } -void AutotoolsProject::makefileParsingStarted() -{ - QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); -} - -void AutotoolsProject::makefileParsingFinished() +void AutotoolsBuildSystem::makefileParsingFinished() { // The finished() signal is from a previous makefile-parser-thread // and can be skipped. This can happen, if the thread has emitted the - // finished() signal during the execution of AutotoolsProject::loadProjectTree(). + // finished() signal during the execution of AutotoolsBuildSystem::loadProjectTree(). // In this case the signal is in the message queue already and deleting // the thread of course does not remove the signal again. if (sender() != m_makefileParserThread) return; - QApplication::restoreOverrideCursor(); - if (m_makefileParserThread->isCanceled()) { // The parsing has been cancelled by the user. Don't show any // project data at all. @@ -167,8 +113,8 @@ void AutotoolsProject::makefileParsingFinished() QVector filesToWatch; - // Apply sources to m_files, which are returned at AutotoolsProject::files() - const QFileInfo fileInfo = projectFilePath().toFileInfo(); + // Apply sources to m_files, which are returned at AutotoolsBuildSystem::files() + const QFileInfo fileInfo = project()->projectFilePath().toFileInfo(); const QDir dir = fileInfo.absoluteDir(); const QStringList files = m_makefileParserThread->sources(); foreach (const QString& file, files) @@ -195,14 +141,14 @@ void AutotoolsProject::makefileParsingFinished() filesToWatch.append(Utils::FilePath::fromString(absConfigureAc)); } - auto newRoot = std::make_unique(projectDirectory()); + auto newRoot = std::make_unique(project()->projectDirectory()); for (const QString &f : m_files) { const Utils::FilePath path = Utils::FilePath::fromString(f); newRoot->addNestedNode(std::make_unique(path, FileNode::fileTypeForFileName(path))); } - setRootProjectNode(std::move(newRoot)); - setExtraProjectFiles(filesToWatch); + project()->setRootProjectNode(std::move(newRoot)); + project()->setExtraProjectFiles(filesToWatch); updateCppCodeModel(); @@ -228,14 +174,16 @@ static QStringList filterIncludes(const QString &absSrc, const QString &absBuild return result; } -void AutotoolsProject::updateCppCodeModel() +void AutotoolsBuildSystem::updateCppCodeModel() { - QtSupport::CppKitInfo kitInfo(this); - QTC_ASSERT(kitInfo.isValid(), return); + QtSupport::CppKitInfo kitInfo(project()); + QTC_ASSERT(kitInfo.isValid(), return ); + + const Utils::FilePath projectFilePath = project()->projectFilePath(); CppTools::RawProjectPart rpp; - rpp.setDisplayName(displayName()); - rpp.setProjectFileLocation(projectFilePath().toString()); + rpp.setDisplayName(project()->displayName()); + rpp.setProjectFileLocation(projectFilePath.toString()); rpp.setQtVersion(kitInfo.projectPartQtVersion); const QStringList cflags = m_makefileParserThread->cflags(); QStringList cxxflags = m_makefileParserThread->cxxflags(); @@ -244,14 +192,18 @@ void AutotoolsProject::updateCppCodeModel() rpp.setFlagsForC({kitInfo.cToolChain, cflags}); rpp.setFlagsForCxx({kitInfo.cxxToolChain, cxxflags}); - const QString absSrc = projectDirectory().toString(); - const Target *target = activeTarget(); - const QString absBuild = (target && target->activeBuildConfiguration()) - ? target->activeBuildConfiguration()->buildDirectory().toString() : QString(); + const QString absSrc = project()->projectDirectory().toString(); + const Target *target = project()->activeTarget(); + BuildConfiguration *bc = target ? target->activeBuildConfiguration() : nullptr; + + const QString absBuild = bc ? bc->buildDirectory().toString() : QString(); rpp.setIncludePaths(filterIncludes(absSrc, absBuild, m_makefileParserThread->includePaths())); rpp.setMacros(m_makefileParserThread->macros()); rpp.setFiles(m_files); - m_cppCodeModelUpdater->update({this, kitInfo, activeParseEnvironment(), {rpp}}); + m_cppCodeModelUpdater->update({project(), kitInfo, project()->activeParseEnvironment(), {rpp}}); } + +} // namespace Internal +} // namespace AutotoolsProjectManager diff --git a/src/plugins/autotoolsprojectmanager/autotoolsproject.h b/src/plugins/autotoolsprojectmanager/autotoolsbuildsystem.h similarity index 70% rename from src/plugins/autotoolsprojectmanager/autotoolsproject.h rename to src/plugins/autotoolsprojectmanager/autotoolsbuildsystem.h index 44e5d816572..8bbad6a580b 100644 --- a/src/plugins/autotoolsprojectmanager/autotoolsproject.h +++ b/src/plugins/autotoolsprojectmanager/autotoolsbuildsystem.h @@ -27,50 +27,30 @@ #pragma once -#include - -#include +#include namespace Utils { class FileSystemWatcher; } namespace CppTools { class CppProjectUpdater; } namespace AutotoolsProjectManager { + namespace Internal { class MakefileParserThread; -/** - * @brief Implementation of the ProjectExplorer::Project interface. - * - * Loads the autotools project and embeds it into the QtCreator project tree. - * The class AutotoolsProject is the core of the autotools project plugin. - * It is responsible to parse the Makefile.am files and do trigger project - * updates if a Makefile.am file or a configure.ac file has been changed. - */ -class AutotoolsProject : public ProjectExplorer::Project +class AutotoolsBuildSystem : public ProjectExplorer::BuildSystem { Q_OBJECT public: - explicit AutotoolsProject(const Utils::FilePath &fileName); - ~AutotoolsProject() override; + explicit AutotoolsBuildSystem(ProjectExplorer::Project *project); + ~AutotoolsBuildSystem() override; protected: - RestoreResult fromMap(const QVariantMap &map, QString *errorMessage) override; + void parseProject(ParsingContext &&ctx) final; private: - /** - * Loads the project tree by parsing the makefiles. - */ - void loadProjectTree(); - - /** - * Is invoked when the makefile parsing by m_makefileParserThread has - * been started. Turns the mouse cursor into a busy cursor. - */ - void makefileParsingStarted(); - /** * Is invoked when the makefile parsing by m_makefileParserThread has * been finished. Adds all sources and files into the project tree and diff --git a/src/plugins/autotoolsprojectmanager/autotoolsopenprojectwizard.cpp b/src/plugins/autotoolsprojectmanager/autotoolsopenprojectwizard.cpp index cbfbe47173b..ef57ca24ea5 100644 --- a/src/plugins/autotoolsprojectmanager/autotoolsopenprojectwizard.cpp +++ b/src/plugins/autotoolsprojectmanager/autotoolsopenprojectwizard.cpp @@ -29,10 +29,9 @@ #include -#include +#include #include #include -#include using namespace AutotoolsProjectManager; using namespace AutotoolsProjectManager::Internal; diff --git a/src/plugins/autotoolsprojectmanager/autotoolsprojectmanager.pro b/src/plugins/autotoolsprojectmanager/autotoolsprojectmanager.pro index 92b6dd8e7d9..37dce96bbb6 100644 --- a/src/plugins/autotoolsprojectmanager/autotoolsprojectmanager.pro +++ b/src/plugins/autotoolsprojectmanager/autotoolsprojectmanager.pro @@ -1,8 +1,8 @@ include(../../qtcreatorplugin.pri) -HEADERS = autotoolsprojectplugin.h\ +HEADERS = autotoolsbuildsystem.h \ + autotoolsprojectplugin.h\ autotoolsopenprojectwizard.h\ - autotoolsproject.h\ autotoolsbuildconfiguration.h\ autotoolsprojectconstants.h\ makestep.h\ @@ -12,9 +12,9 @@ HEADERS = autotoolsprojectplugin.h\ makefileparserthread.h\ makefileparser.h -SOURCES = autotoolsprojectplugin.cpp\ +SOURCES = autotoolsbuildsystem.cpp \ + autotoolsprojectplugin.cpp\ autotoolsopenprojectwizard.cpp\ - autotoolsproject.cpp\ autotoolsbuildconfiguration.cpp\ makestep.cpp\ autogenstep.cpp\ diff --git a/src/plugins/autotoolsprojectmanager/autotoolsprojectmanager.qbs b/src/plugins/autotoolsprojectmanager/autotoolsprojectmanager.qbs index a6e4a2721b0..75f81d09b74 100644 --- a/src/plugins/autotoolsprojectmanager/autotoolsprojectmanager.qbs +++ b/src/plugins/autotoolsprojectmanager/autotoolsprojectmanager.qbs @@ -18,10 +18,10 @@ QtcPlugin { "autoreconfstep.h", "autotoolsbuildconfiguration.cpp", "autotoolsbuildconfiguration.h", + "autotoolsbuildsystem.cpp", + "autotoolsbuildsystem.h", "autotoolsopenprojectwizard.cpp", "autotoolsopenprojectwizard.h", - "autotoolsproject.cpp", - "autotoolsproject.h", "autotoolsprojectconstants.h", "autotoolsprojectplugin.cpp", "autotoolsprojectplugin.h", diff --git a/src/plugins/autotoolsprojectmanager/autotoolsprojectplugin.cpp b/src/plugins/autotoolsprojectmanager/autotoolsprojectplugin.cpp index 5b3643dcd33..e3cd87f0ce5 100644 --- a/src/plugins/autotoolsprojectmanager/autotoolsprojectplugin.cpp +++ b/src/plugins/autotoolsprojectmanager/autotoolsprojectplugin.cpp @@ -26,19 +26,33 @@ ****************************************************************************/ #include "autotoolsprojectplugin.h" -#include "autotoolsproject.h" -#include "autotoolsprojectconstants.h" -#include "autotoolsbuildconfiguration.h" -#include "makestep.h" + #include "autogenstep.h" #include "autoreconfstep.h" +#include "autotoolsbuildconfiguration.h" +#include "autotoolsbuildsystem.h" +#include "autotoolsprojectconstants.h" #include "configurestep.h" +#include "makestep.h" +#include #include namespace AutotoolsProjectManager { namespace Internal { +AutotoolsProject::AutotoolsProject(const Utils::FilePath &fileName) + : Project(Constants::MAKEFILE_MIMETYPE, fileName) +{ + setId(Constants::AUTOTOOLS_PROJECT_ID); + setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID)); + setDisplayName(projectDirectory().fileName()); + + setHasMakeInstallEquivalent(true); + + setBuildSystem(std::make_unique(this)); +} + class AutotoolsProjectPluginPrivate { public: @@ -69,5 +83,5 @@ bool AutotoolsProjectPlugin::initialize(const QStringList &arguments, return true; } -} // Internal +} // namespace Internal } // AutotoolsProjectManager diff --git a/src/plugins/autotoolsprojectmanager/autotoolsprojectplugin.h b/src/plugins/autotoolsprojectmanager/autotoolsprojectplugin.h index dd08cbd1c82..bdf319150fd 100644 --- a/src/plugins/autotoolsprojectmanager/autotoolsprojectplugin.h +++ b/src/plugins/autotoolsprojectmanager/autotoolsprojectplugin.h @@ -27,6 +27,8 @@ #pragma once +#include + #include namespace AutotoolsProjectManager { @@ -73,5 +75,19 @@ class AutotoolsProjectPlugin : public ExtensionSystem::IPlugin class AutotoolsProjectPluginPrivate *d; }; +/** + * @brief Implementation of the ProjectExplorer::Project interface. + * + * Loads the autotools project and embeds it into the QtCreator project tree. + * The class AutotoolsProject is the core of the autotools project plugin. + * It is responsible to parse the Makefile.am files and do trigger project + * updates if a Makefile.am file or a configure.ac file has been changed. + */ +class AutotoolsProject : public ProjectExplorer::Project +{ +public: + explicit AutotoolsProject(const Utils::FilePath &fileName); +}; + } // namespace Internal } // namespace AutotoolsProjectManager diff --git a/src/plugins/autotoolsprojectmanager/configurestep.cpp b/src/plugins/autotoolsprojectmanager/configurestep.cpp index 53f4c71a3e5..c722aa3a9fa 100644 --- a/src/plugins/autotoolsprojectmanager/configurestep.cpp +++ b/src/plugins/autotoolsprojectmanager/configurestep.cpp @@ -26,23 +26,16 @@ ****************************************************************************/ #include "configurestep.h" -#include "autotoolsproject.h" + #include "autotoolsbuildconfiguration.h" #include "autotoolsprojectconstants.h" -#include -#include -#include -#include #include -#include -#include -#include +#include +#include -#include #include -#include -#include +#include using namespace AutotoolsProjectManager; using namespace AutotoolsProjectManager::Internal; @@ -55,7 +48,7 @@ using namespace Utils; static QString projectDirRelativeToBuildDir(BuildConfiguration *bc) { const QDir buildDir(bc->buildDirectory().toString()); QString projDirToBuildDir = buildDir.relativeFilePath( - bc->target()->project()->projectDirectory().toString()); + bc->project()->projectDirectory().toString()); if (projDirToBuildDir.isEmpty()) return QString("./"); if (!projDirToBuildDir.endsWith('/')) @@ -106,7 +99,6 @@ ConfigureStep::ConfigureStep(BuildStepList *bsl) return param.summaryInWorkdir(displayName()); }); - } bool ConfigureStep::init() diff --git a/src/plugins/autotoolsprojectmanager/makefileparser.cpp b/src/plugins/autotoolsprojectmanager/makefileparser.cpp index 39596a724e8..8c379ee8231 100644 --- a/src/plugins/autotoolsprojectmanager/makefileparser.cpp +++ b/src/plugins/autotoolsprojectmanager/makefileparser.cpp @@ -30,10 +30,9 @@ #include #include -#include #include -#include -#include +#include +#include using namespace AutotoolsProjectManager::Internal; @@ -49,7 +48,7 @@ bool MakefileParser::parse() { m_mutex.lock(); m_cancel = false; - m_mutex.unlock(), + m_mutex.unlock(); m_success = true; m_executable.clear(); diff --git a/src/plugins/autotoolsprojectmanager/makestep.cpp b/src/plugins/autotoolsprojectmanager/makestep.cpp index 14b58c8368f..7a7fbbddb3f 100644 --- a/src/plugins/autotoolsprojectmanager/makestep.cpp +++ b/src/plugins/autotoolsprojectmanager/makestep.cpp @@ -26,9 +26,7 @@ ****************************************************************************/ #include "makestep.h" -#include "autotoolsproject.h" #include "autotoolsprojectconstants.h" -#include "autotoolsbuildconfiguration.h" #include #include diff --git a/src/plugins/projectexplorer/project.h b/src/plugins/projectexplorer/project.h index c4f29f0d1a8..9c4f38fecbe 100644 --- a/src/plugins/projectexplorer/project.h +++ b/src/plugins/projectexplorer/project.h @@ -232,6 +232,7 @@ public: // FIXME: Make this private and the BuildSystem a friend ParseGuard guardParsingRun() { return ParseGuard(this); } + void setRootProjectNode(std::unique_ptr &&root); // Set project files that will be watched and trigger the same callback // as the main project file. @@ -285,7 +286,6 @@ protected: void setCanBuildProducts(); void setId(Core::Id id); - void setRootProjectNode(std::unique_ptr &&root); // takes ownership! void setProjectLanguages(Core::Context language); void addProjectLanguage(Core::Id id); void removeProjectLanguage(Core::Id id);