diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp index febb130a0ac..32464ad8f84 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp @@ -281,8 +281,11 @@ bool CMakeBuildSystem::addFiles(Node *context, const FilePaths &filePaths, FileP return target.title == targetName; }); - if (target.backtrace.isEmpty()) + if (target.backtrace.isEmpty()) { + qCCritical(cmakeBuildSystemLog) << "target.backtrace for" << targetName << "is empty. " + << "The location where to add the files is unknown."; return false; + } const FilePath targetCMakeFile = target.backtrace.last().path; const int targetDefinitionLine = target.backtrace.last().line; @@ -298,6 +301,8 @@ bool CMakeBuildSystem::addFiles(Node *context, const FilePaths &filePaths, FileP if (!cmakeListFile.ParseString(fileContent->toStdString(), targetCMakeFile.fileName().toStdString(), errorString)) { + qCCritical(cmakeBuildSystemLog).noquote() + << targetCMakeFile.path() << "failed to parse! Error:" << errorString; return false; } } @@ -308,8 +313,11 @@ bool CMakeBuildSystem::addFiles(Node *context, const FilePaths &filePaths, FileP return func.Line() == targetDefinitionLine; }); - if (function == cmakeListFile.Functions.end()) + if (function == cmakeListFile.Functions.end()) { + qCCritical(cmakeBuildSystemLog) << "Function that defined the target" << targetName + << "could not be found at" << targetDefinitionLine; return false; + } // Special case: when qt_add_executable and qt_add_qml_module use the same target name // then qt_add_qml_module function should be used @@ -383,13 +391,20 @@ bool CMakeBuildSystem::addFiles(Node *context, const FilePaths &filePaths, FileP Core::EditorManager::openEditorAt({targetCMakeFile, line, column + extraChars}, Constants::CMAKE_EDITOR_ID, Core::EditorManager::DoNotMakeVisible)); - if (!editor) + if (!editor) { + qCCritical(cmakeBuildSystemLog).noquote() + << "BaseTextEditor cannot be obtained for" << targetCMakeFile.path() << line + << int(column + extraChars); return false; + } editor->insert(snippet); editor->editorWidget()->autoIndent(); - if (!Core::DocumentManager::saveDocument(editor->document())) + if (!Core::DocumentManager::saveDocument(editor->document())) { + qCCritical(cmakeBuildSystemLog).noquote() + << "Changes to" << targetCMakeFile.path() << "could not be saved."; return false; + } if (notAdded) notAdded->clear(); @@ -536,6 +551,9 @@ RemovedFilesFromProject CMakeBuildSystem::removeFiles(Node *context, if (filePos) { if (!filePos.value().cmakeFile.exists()) { badFiles << file; + + qCCritical(cmakeBuildSystemLog).noquote() + << "File" << filePos.value().cmakeFile.path() << "does not exist."; continue; } @@ -548,6 +566,11 @@ RemovedFilesFromProject CMakeBuildSystem::removeFiles(Node *context, Core::EditorManager::DoNotMakeVisible)); if (!editor) { badFiles << file; + + qCCritical(cmakeBuildSystemLog).noquote() + << "BaseTextEditor cannot be obtained for" + << filePos.value().cmakeFile.path() << filePos.value().argumentPosition.Line + << int(filePos.value().argumentPosition.Column - 1); continue; } @@ -562,6 +585,10 @@ RemovedFilesFromProject CMakeBuildSystem::removeFiles(Node *context, editor->editorWidget()->autoIndent(); if (!Core::DocumentManager::saveDocument(editor->document())) { badFiles << file; + + qCCritical(cmakeBuildSystemLog).noquote() + << "Changes to" << filePos.value().cmakeFile.path() + << "could not be saved."; continue; } } else { @@ -625,8 +652,11 @@ bool CMakeBuildSystem::renameFile(Node *context, ";"); auto fileToRename = m_filesToBeRenamed.take(key); - if (!fileToRename.cmakeFile.exists()) + if (!fileToRename.cmakeFile.exists()) { + qCCritical(cmakeBuildSystemLog).noquote() + << "File" << fileToRename.cmakeFile.path() << "does not exist."; return false; + } BaseTextEditor *editor = qobject_cast( Core::EditorManager::openEditorAt({fileToRename.cmakeFile, @@ -635,8 +665,12 @@ bool CMakeBuildSystem::renameFile(Node *context, - 1)}, Constants::CMAKE_EDITOR_ID, Core::EditorManager::DoNotMakeVisible)); - if (!editor) + if (!editor) { + qCCritical(cmakeBuildSystemLog).noquote() + << "BaseTextEditor cannot be obtained for" << fileToRename.cmakeFile.path() + << fileToRename.argumentPosition.Line << int(fileToRename.argumentPosition.Column); return false; + } // If quotes were used for the source file, skip the starting quote if (fileToRename.argumentPosition.Delim == cmListFileArgument::Quoted) @@ -646,8 +680,11 @@ bool CMakeBuildSystem::renameFile(Node *context, editor->replace(fileToRename.relativeFileName.length(), newRelPathName); editor->editorWidget()->autoIndent(); - if (!Core::DocumentManager::saveDocument(editor->document())) + if (!Core::DocumentManager::saveDocument(editor->document())) { + qCCritical(cmakeBuildSystemLog).noquote() + << "Changes to" << fileToRename.cmakeFile.path() << "could not be saved."; return false; + } return true; }