forked from qt-creator/qt-creator
CMakePM: Parse the CMake file before adding new / existing files
This way the functionality would work even if autorun CMake is disabled. Change-Id: I54ab47d72664cb42486b260b895f58d37a885cce Reviewed-by: hjk <hjk@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -271,10 +271,19 @@ bool CMakeBuildSystem::addFiles(Node *context, const FilePaths &filePaths, FileP
|
|||||||
const FilePath targetCMakeFile = target.backtrace.last().path;
|
const FilePath targetCMakeFile = target.backtrace.last().path;
|
||||||
const int targetDefinitionLine = target.backtrace.last().line;
|
const int targetDefinitionLine = target.backtrace.last().line;
|
||||||
|
|
||||||
auto cmakeListFile
|
// Have a fresh look at the CMake file, not relying on a cached value
|
||||||
= Utils::findOrDefault(m_cmakeFiles, [targetCMakeFile](const CMakeFileInfo &info) {
|
expected_str<QByteArray> fileContent = targetCMakeFile.fileContents();
|
||||||
return info.path == targetCMakeFile;
|
cmListFile cmakeListFile;
|
||||||
}).cmakeListFile;
|
std::string errorString;
|
||||||
|
if (fileContent) {
|
||||||
|
fileContent = fileContent->replace("\r\n", "\n");
|
||||||
|
if (!cmakeListFile.ParseString(fileContent->toStdString(),
|
||||||
|
targetCMakeFile.fileName().toStdString(),
|
||||||
|
errorString)) {
|
||||||
|
*notAdded = filePaths;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto function = std::find_if(cmakeListFile.Functions.begin(),
|
auto function = std::find_if(cmakeListFile.Functions.begin(),
|
||||||
cmakeListFile.Functions.end(),
|
cmakeListFile.Functions.end(),
|
||||||
@@ -360,7 +369,8 @@ bool CMakeBuildSystem::addFiles(Node *context, const FilePaths &filePaths, FileP
|
|||||||
|
|
||||||
editor->insert(snippet);
|
editor->insert(snippet);
|
||||||
editor->editorWidget()->autoIndent();
|
editor->editorWidget()->autoIndent();
|
||||||
Core::DocumentManager::saveDocument(editor->document());
|
if (!Core::DocumentManager::saveDocument(editor->document()))
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user