Autotools: Introduce AutotoolsBuildSystem

Introduce AutotoolsBuildSystem and slim down AutotoolsProject.

Change-Id: I68296152f9ecd5d14198c8d0b36a06c2d1b162ec
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Tobias Hunger
2019-08-13 12:47:11 +02:00
parent b7e4046a17
commit fb21b78444
15 changed files with 113 additions and 173 deletions

View File

@@ -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

View File

@@ -26,14 +26,12 @@
****************************************************************************/
#include "autogenstep.h"
#include "autotoolsprojectconstants.h"
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/project.h>
#include <projectexplorer/processparameters.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>
#include <QDateTime>
@@ -43,7 +41,6 @@ using namespace AutotoolsProjectManager::Internal;
using namespace ProjectExplorer;
using namespace Utils;
// AutogenStepFactory
AutogenStepFactory::AutogenStepFactory()

View File

@@ -26,14 +26,12 @@
****************************************************************************/
#include "autoreconfstep.h"
#include "autotoolsprojectconstants.h"
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/project.h>
#include <projectexplorer/processparameters.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>
using namespace AutotoolsProjectManager;

View File

@@ -27,18 +27,13 @@
#include "autotoolsbuildconfiguration.h"
#include "autotoolsproject.h"
#include "autotoolsprojectconstants.h"
#include <coreplugin/icore.h>
#include <projectexplorer/buildinfo.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/qtcassert.h>
using namespace AutotoolsProjectManager::Constants;
using namespace ProjectExplorer;

View File

@@ -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 <projectexplorer/abi.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectnodes.h>
#include <projectexplorer/target.h>
#include <projectexplorer/headerpath.h>
#include <extensionsystem/pluginmanager.h>
#include <cpptools/cppmodelmanager.h>
#include <cpptools/projectinfo.h>
#include <cpptools/cppprojectupdater.h>
#include <coreplugin/icore.h>
#include <coreplugin/icontext.h>
#include <qtsupport/baseqtversion.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/target.h>
#include <qtsupport/qtcppkitinfo.h>
#include <qtsupport/qtkitinformation.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <utils/filesystemwatcher.h>
#include <QFileInfo>
#include <QTimer>
#include <QPointer>
#include <QApplication>
#include <QCursor>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
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<Utils::FilePath> 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<ProjectNode>(projectDirectory());
auto newRoot = std::make_unique<ProjectNode>(project()->projectDirectory());
for (const QString &f : m_files) {
const Utils::FilePath path = Utils::FilePath::fromString(f);
newRoot->addNestedNode(std::make_unique<FileNode>(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);
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

View File

@@ -27,50 +27,30 @@
#pragma once
#include <projectexplorer/project.h>
#include <utils/fileutils.h>
#include <projectexplorer/buildsystem.h>
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

View File

@@ -29,10 +29,9 @@
#include <utils/pathchooser.h>
#include <QVBoxLayout>
#include <QDir>
#include <QFormLayout>
#include <QLabel>
#include <QDir>
using namespace AutotoolsProjectManager;
using namespace AutotoolsProjectManager::Internal;

View File

@@ -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\

View File

@@ -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",

View File

@@ -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 <coreplugin/icontext.h>
#include <projectexplorer/projectmanager.h>
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<AutotoolsBuildSystem>(this));
}
class AutotoolsProjectPluginPrivate
{
public:
@@ -69,5 +83,5 @@ bool AutotoolsProjectPlugin::initialize(const QStringList &arguments,
return true;
}
} // Internal
} // namespace Internal
} // AutotoolsProjectManager

View File

@@ -27,6 +27,8 @@
#pragma once
#include <projectexplorer/project.h>
#include <extensionsystem/iplugin.h>
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

View File

@@ -26,23 +26,16 @@
****************************************************************************/
#include "configurestep.h"
#include "autotoolsproject.h"
#include "autotoolsbuildconfiguration.h"
#include "autotoolsprojectconstants.h"
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/target.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/gnumakeparser.h>
#include <projectexplorer/processparameters.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/qtcprocess.h>
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>
#include <QVariantMap>
#include <QDateTime>
#include <QLineEdit>
#include <QFormLayout>
#include <QDir>
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()

View File

@@ -30,10 +30,9 @@
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <QFile>
#include <QDir>
#include <QFileInfoList>
#include <QMutexLocker>
#include <QFile>
#include <QFileInfo>
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();

View File

@@ -26,9 +26,7 @@
****************************************************************************/
#include "makestep.h"
#include "autotoolsproject.h"
#include "autotoolsprojectconstants.h"
#include "autotoolsbuildconfiguration.h"
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/projectexplorerconstants.h>

View File

@@ -232,6 +232,7 @@ public:
// FIXME: Make this private and the BuildSystem a friend
ParseGuard guardParsingRun() { return ParseGuard(this); }
void setRootProjectNode(std::unique_ptr<ProjectNode> &&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<ProjectNode> &&root); // takes ownership!
void setProjectLanguages(Core::Context language);
void addProjectLanguage(Core::Id id);
void removeProjectLanguage(Core::Id id);