MCPcopy Create free account
hub / github.com/KDE/kdevelop / handshake

Method handshake

plugins/cmake/cmakeserver.cpp:141–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141void CMakeServer::handshake(const KDevelop::Path& source, const KDevelop::Path& build)
142{
143 Q_ASSERT(!source.isEmpty());
144
145 const QString generatorVariable = QStringLiteral("CMAKE_GENERATOR");
146 const QString homeDirectoryVariable = QStringLiteral("CMAKE_HOME_DIRECTORY");
147 const QString cacheFileDirectoryVariable = QStringLiteral("CMAKE_CACHEFILE_DIR");
148 const auto cacheValues = CMake::readCacheValues(KDevelop::Path(build, QStringLiteral("CMakeCache.txt")),
149 {generatorVariable, homeDirectoryVariable, cacheFileDirectoryVariable});
150
151 QString generator = cacheValues.value(generatorVariable);
152 if (generator.isEmpty()) {
153 generator = CMake::defaultGenerator();
154 }
155
156 // prefer pre-existing source directory, see also: https://gitlab.kitware.com/cmake/cmake/issues/16736
157 QString sourceDirectory = cacheValues.value(homeDirectoryVariable);
158 if (sourceDirectory.isEmpty()) {
159 sourceDirectory = source.toLocalFile();
160 } else if (QFileInfo(sourceDirectory).canonicalFilePath() != QFileInfo(source.toLocalFile()).canonicalFilePath()) {
161 qCWarning(CMAKE) << "Build directory is configured for another source directory:"
162 << homeDirectoryVariable << sourceDirectory
163 << "wanted to open" << source << "in" << build;
164 }
165
166 // prefer to reuse the exact same build dir path to prevent useless recompilation
167 // when we open a symlinked project path
168 QString buildDirectory = cacheValues.value(cacheFileDirectoryVariable);
169 if (buildDirectory.isEmpty()) {
170 buildDirectory = build.toLocalFile();
171 } else if (QFileInfo(buildDirectory).canonicalFilePath() != QFileInfo(build.toLocalFile()).canonicalFilePath()) {
172 qCWarning(CMAKE) << "Build directory mismatch:"
173 << cacheFileDirectoryVariable << buildDirectory
174 << "wanted to open" << build;
175 buildDirectory = build.toLocalFile();
176 }
177
178 qCDebug(CMAKE) << "Using generator" << generator << "for project"
179 << sourceDirectory << "aka" << source
180 << "in" << buildDirectory << "aka" << build;
181
182 sendCommand({
183 {QStringLiteral("cookie"), {}},
184 {QStringLiteral("type"), QStringLiteral("handshake")},
185 {QStringLiteral("major"), 1},
186 {QStringLiteral("protocolVersion"), QJsonObject{{QStringLiteral("major"), 1}} },
187 {QStringLiteral("sourceDirectory"), sourceDirectory},
188 {QStringLiteral("buildDirectory"), buildDirectory},
189 {QStringLiteral("generator"), generator}
190 });
191}
192
193void CMakeServer::configure(const QStringList& args)
194{

Callers 2

doStartMethod · 0.80
testRunMethod · 0.80

Calls 7

readCacheValuesFunction · 0.85
defaultGeneratorFunction · 0.85
toLocalFileMethod · 0.80
PathClass · 0.70
QFileInfoClass · 0.50
isEmptyMethod · 0.45
valueMethod · 0.45

Tested by 1

testRunMethod · 0.64