| 267 | } |
| 268 | |
| 269 | CMakeFile CMakeManager::fileInformation(KDevelop::ProjectBaseItem* item) const |
| 270 | { |
| 271 | const auto projectData = m_projects.constFind(item->project()); |
| 272 | if (projectData == m_projects.cend()) { |
| 273 | return {}; |
| 274 | } |
| 275 | const auto& data = projectData->data.compilationData; |
| 276 | |
| 277 | const auto itemPath = item->path(); |
| 278 | if (!data.isValid || data.missingFiles.contains(itemPath)) { |
| 279 | return {}; |
| 280 | } |
| 281 | |
| 282 | auto toCanonicalPath = [](const Path &path) -> Path { |
| 283 | // if the path contains a symlink, then we will not find it in the lookup table |
| 284 | // as that only only stores canonicalized paths. Thus, we fallback to |
| 285 | // to the canonicalized path and see if that brings up any matches |
| 286 | const auto localPath = path.toLocalFile(); |
| 287 | const auto canonicalPath = QFileInfo(localPath).canonicalFilePath(); |
| 288 | return (localPath == canonicalPath) ? path : Path(canonicalPath); |
| 289 | }; |
| 290 | |
| 291 | auto path = itemPath; |
| 292 | if (!item->folder()) { |
| 293 | // try to look for file meta data directly |
| 294 | auto it = data.files.find(path); |
| 295 | if (it == data.files.end()) { |
| 296 | // fallback to canonical path lookup |
| 297 | auto canonical = toCanonicalPath(path); |
| 298 | if (canonical != path) { |
| 299 | it = data.files.find(canonical); |
| 300 | } |
| 301 | } |
| 302 | if (it != data.files.end()) { |
| 303 | return *it; |
| 304 | } |
| 305 | // else look for a file in the parent folder |
| 306 | path = path.parent(); |
| 307 | } |
| 308 | |
| 309 | while (true) { |
| 310 | // try to look for a file in the current folder path |
| 311 | auto it = data.fileForFolder.find(path); |
| 312 | if (it == data.fileForFolder.end()) { |
| 313 | // fallback to canonical path lookup |
| 314 | auto canonical = toCanonicalPath(path); |
| 315 | if (canonical != path) { |
| 316 | it = data.fileForFolder.find(canonical); |
| 317 | } |
| 318 | } |
| 319 | if (it != data.fileForFolder.end()) { |
| 320 | return data.files[it.value()]; |
| 321 | } |
| 322 | if (!path.hasParent()) { |
| 323 | break; |
| 324 | } |
| 325 | path = path.parent(); |
| 326 | } |
nothing calls this directly
no test coverage detected