| 22 | #include "debug.h" |
| 23 | |
| 24 | CMakeServer::CMakeServer(KDevelop::IProject* project) |
| 25 | : QObject() |
| 26 | , m_localSocket(new QLocalSocket(this)) |
| 27 | { |
| 28 | QString path; |
| 29 | { |
| 30 | const auto cacheLocation = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); |
| 31 | QDir::temp().mkpath(cacheLocation); |
| 32 | |
| 33 | QTemporaryFile file(cacheLocation + QLatin1String("/kdevelopcmake")); |
| 34 | file.open(); |
| 35 | file.close(); |
| 36 | path = file.fileName(); |
| 37 | Q_ASSERT(!path.isEmpty()); |
| 38 | } |
| 39 | |
| 40 | m_process.setProcessChannelMode(QProcess::ForwardedChannels); |
| 41 | |
| 42 | connect(&m_process, &QProcess::errorOccurred, |
| 43 | this, [this, path](QProcess::ProcessError error) { |
| 44 | qCWarning(CMAKE) << "cmake server error:" << error << path << m_process.readAllStandardError() << m_process.readAllStandardOutput(); |
| 45 | }); |
| 46 | connect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, [](int code){ |
| 47 | qCDebug(CMAKE) << "cmake server finished with code" << code; |
| 48 | }); |
| 49 | connect(&m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &CMakeServer::finished); |
| 50 | |
| 51 | connect(m_localSocket, &QIODevice::readyRead, this, &CMakeServer::processOutput); |
| 52 | connect(m_localSocket, &QLocalSocket::errorOccurred, this, |
| 53 | [this, path](QLocalSocket::LocalSocketError socketError) { |
| 54 | qCWarning(CMAKE) << "cmake server socket error:" << socketError << path; |
| 55 | setConnected(false); |
| 56 | }); |
| 57 | connect(m_localSocket, &QLocalSocket::connected, this, [this]() { setConnected(true); }); |
| 58 | |
| 59 | connect(&m_process, &QProcess::started, this, [this, path](){ |
| 60 | //Once the process has started, wait for the file to be created, then connect to it |
| 61 | QTimer::singleShot(1000, this, [this, path]() { |
| 62 | m_localSocket->connectToServer(path, QIODevice::ReadWrite); |
| 63 | }); |
| 64 | }); |
| 65 | // we're called with the importing project as our parent, so we can fetch configured |
| 66 | // cmake executable (project-specific or kdevelop-wide) rather than the system version. |
| 67 | m_process.setProgram(CMake::currentCMakeExecutable(project).toLocalFile()); |
| 68 | m_process.setArguments({QStringLiteral("-E"), QStringLiteral("server"), QStringLiteral("--experimental"), QLatin1String("--pipe=") + path}); |
| 69 | KDevelop::ICore::self()->runtimeController()->currentRuntime()->startProcess(&m_process); |
| 70 | } |
| 71 | |
| 72 | CMakeServer::~CMakeServer() |
| 73 | { |
nothing calls this directly
no test coverage detected