Commit f6b9c447 authored by Daniel Mensinger's avatar Daniel Mensinger Committed by Milian Wolff

meson: Watch for introspection file changes

parent b306b0f7
......@@ -38,6 +38,7 @@
#include <util/executecompositejob.h>
#include <KConfigGroup>
#include <KDirWatch>
#include <KLocalizedString>
#include <KPluginFactory>
#include <QFileDialog>
......@@ -132,7 +133,7 @@ bool MesonManager::reload(KDevelop::ProjectFolderItem* item)
}
KDevelop::ICore::self()->projectController()->projectConfigurationChanged(project);
KDevelop::ICore::self()->projectController()->reparseProject(project, true);
KDevelop::ICore::self()->projectController()->reparseProject(project);
});
}
......@@ -190,14 +191,55 @@ QList<ProjectTargetItem*> MesonManager::targets(ProjectFolderItem* item) const
return res;
}
void MesonManager::onMesonInfoChanged(QString path, QString projectName)
{
qCDebug(KDEV_Meson) << "File" << path << "changed --> reparsing project";
IProject* foundProject = ICore::self()->projectController()->findProjectByName(projectName);
if (!foundProject) {
return;
}
KJob* job = createImportJob(foundProject->projectItem());
foundProject->setReloadJob(job);
ICore::self()->runController()->registerJob(job);
connect(job, &KJob::finished, this, [foundProject](KJob* job) -> void {
if (job->error()) {
return;
}
KDevelop::ICore::self()->projectController()->projectConfigurationChanged(foundProject);
KDevelop::ICore::self()->projectController()->reparseProject(foundProject);
});
}
KJob* MesonManager::createImportJob(ProjectFolderItem* item)
{
IProject* project = item->project();
Q_ASSERT(project);
auto buildDir = Meson::currentBuildDir(project);
auto introJob
= new MesonIntrospectJob(project, buildDir, { MesonIntrospectJob::TARGETS, MesonIntrospectJob::TESTS },
MesonIntrospectJob::BUILD_DIR, this);
KDirWatchPtr watcher = m_projectWatchers[project];
if (!watcher) {
// Create a new watcher
watcher = m_projectWatchers[project] = make_shared<KDirWatch>(nullptr);
QString projectName = project->name();
connect(watcher.get(), &KDirWatch::dirty, this, [=](QString p) { onMesonInfoChanged(p, projectName); });
connect(watcher.get(), &KDirWatch::created, this, [=](QString p) { onMesonInfoChanged(p, projectName); });
}
Path watchFile = buildDir.buildDir;
watchFile.addPath(QStringLiteral("meson-info"));
watchFile.addPath(QStringLiteral("meson-info.json"));
if (!watcher->contains(watchFile.path())) {
qCDebug(KDEV_Meson) << "Start watching file" << watchFile;
watcher->addFile(watchFile.path());
}
connect(introJob, &KJob::result, this, [this, introJob, item, project]() {
auto targets = introJob->targets();
auto tests = introJob->tests();
......
......@@ -33,8 +33,11 @@ class MesonTarget;
class MesonTargets;
class MesonTargetSources;
class KDirWatch;
using MesonSourcePtr = std::shared_ptr<MesonTargetSources>;
using MesonTargetsPtr = std::shared_ptr<MesonTargets>;
using KDirWatchPtr = std::shared_ptr<KDirWatch>;
class MesonManager : public KDevelop::AbstractFileManagerPlugin, public KDevelop::IBuildSystemManager
{
......@@ -112,10 +115,14 @@ public:
KDevelop::Path compiler(KDevelop::ProjectTargetItem* p) const override;
private:
void onMesonInfoChanged(QString path, QString projectName);
private:
MesonBuilder* m_builder;
QHash<KDevelop::IProject*, MesonTargetsPtr> m_projectTargets;
QHash<KDevelop::IProject*, MesonTestSuitesPtr> m_projectTestSuites;
QHash<KDevelop::IProject*, KDirWatchPtr> m_projectWatchers;
MesonSourcePtr sourceFromItem(KDevelop::ProjectBaseItem* item) const;
void populateTargets(KDevelop::ProjectFolderItem* item, QVector<MesonTarget*> targets);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment