Commit 7a16881e authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

cmake: make use of QSharedPointer<CMakeServer> from the start

Don't start using the sharedpointer at some random point in the lifetime
of the object.
Make sure we don't parent it, as QSharedPointer will try to delete it
eventually as well.
parent b2936f50
......@@ -149,9 +149,9 @@ public:
}
void start() override {
server = new CMakeServer(project);
connect(server, &CMakeServer::connected, this, &ChooseCMakeInterfaceJob::successfulConnection);
connect(server, &CMakeServer::finished, this, &ChooseCMakeInterfaceJob::failedConnection);
server.reset(new CMakeServer(project));
connect(server.data(), &CMakeServer::connected, this, &ChooseCMakeInterfaceJob::successfulConnection);
connect(server.data(), &CMakeServer::finished, this, &ChooseCMakeInterfaceJob::failedConnection);
}
private:
......@@ -192,7 +192,7 @@ private:
ExecuteCompositeJob::start();
}
CMakeServer* server = nullptr;
QSharedPointer<CMakeServer> server;
IProject* const project;
CMakeManager* const manager;
};
......
......@@ -35,8 +35,8 @@
#include <QTemporaryFile>
#include "debug.h"
CMakeServer::CMakeServer(QObject* parent)
: QObject(parent)
CMakeServer::CMakeServer(KDevelop::IProject* project)
: QObject()
, m_localSocket(new QLocalSocket(this))
{
QString path;
......@@ -81,7 +81,7 @@ CMakeServer::CMakeServer(QObject* parent)
});
// we're called with the importing project as our parent, so we can fetch configured
// cmake executable (project-specific or kdevelop-wide) rather than the system version.
m_process.setProgram(CMake::currentCMakeExecutable(dynamic_cast<KDevelop::IProject*>(parent)).toLocalFile());
m_process.setProgram(CMake::currentCMakeExecutable(project).toLocalFile());
m_process.setArguments({QStringLiteral("-E"), QStringLiteral("server"), QStringLiteral("--experimental"), QLatin1String("--pipe=") + path});
KDevelop::ICore::self()->runtimeController()->currentRuntime()->startProcess(&m_process);
}
......
......@@ -26,11 +26,13 @@
#include <QLocalSocket>
#include "cmakecommonexport.h"
namespace KDevelop { class IProject; }
class KDEVCMAKECOMMON_EXPORT CMakeServer : public QObject
{
Q_OBJECT
public:
explicit CMakeServer(QObject* parent = nullptr);
explicit CMakeServer(KDevelop::IProject* project);
~CMakeServer() override;
bool isServerAvailable();
......
......@@ -160,7 +160,7 @@ void CMakeServerImportJob::processCodeModel(const QJsonObject &response, CMakePr
}
}
CMakeServerImportJob::CMakeServerImportJob(KDevelop::IProject* project, CMakeServer* server, QObject* parent)
CMakeServerImportJob::CMakeServerImportJob(KDevelop::IProject* project, const QSharedPointer<CMakeServer> &server, QObject* parent)
: KJob(parent)
, m_server(server)
, m_project(project)
......
......@@ -34,7 +34,7 @@ class CMakeServerImportJob : public KJob
{
Q_OBJECT
public:
CMakeServerImportJob(KDevelop::IProject* project, CMakeServer* server, QObject* parent);
CMakeServerImportJob(KDevelop::IProject* project, const QSharedPointer<CMakeServer> &server, QObject* parent);
enum Error { NoError, UnexpectedDisconnect, ErrorResponse };
......
......@@ -63,7 +63,7 @@ private Q_SLOTS:
void testRun()
{
CMakeServer server(this);
CMakeServer server(nullptr);
QSignalSpy spyConnected(&server, &CMakeServer::connected);
QVERIFY(server.isServerAvailable() || spyConnected.wait());
......
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