diff options
author | Knud Dollereder <knud.dollereder@qt.io> | 2024-04-19 16:17:57 +0200 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2024-04-21 19:47:14 +0000 |
commit | 1b52357d0197a2ab071c781edefb2632340f9e71 (patch) | |
tree | ec38f3b395365ba5c3bfb78921ab7a36d41d0835 /src | |
parent | 5a49c1669437ef2d4e1c2e284c912cb774495999 (diff) |
QmlProjectManager: Fix cmake generator update issues
Fixes: QDS-12518
Change-Id: I27d45213100e42117b130bcbbceb5e115ed68445
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/qmlprojectmanager/cmakegen/cmakegenerator.cpp | 44 | ||||
-rw-r--r-- | src/plugins/qmlprojectmanager/cmakegen/cmakewriterv1.cpp | 67 |
2 files changed, 63 insertions, 48 deletions
diff --git a/src/plugins/qmlprojectmanager/cmakegen/cmakegenerator.cpp b/src/plugins/qmlprojectmanager/cmakegen/cmakegenerator.cpp index 8e77cde4f7..659c544ebd 100644 --- a/src/plugins/qmlprojectmanager/cmakegen/cmakegenerator.cpp +++ b/src/plugins/qmlprojectmanager/cmakegen/cmakegenerator.cpp @@ -154,10 +154,10 @@ void CMakeGenerator::initialize(QmlProject *project) parseNodeTree(m_root, rootProjectNode); parseSourceTree(); - compareWithFileSystem(m_root); - createCMakeFiles(m_root); createSourceFiles(); + + compareWithFileSystem(m_root); } void CMakeGenerator::update(const QSet<QString> &added, const QSet<QString> &removed) @@ -170,7 +170,7 @@ void CMakeGenerator::update(const QSet<QString> &added, const QSet<QString> &rem std::set<NodePtr> dirtyModules; for (const QString &add : added) { const Utils::FilePath path = Utils::FilePath::fromString(add); - if (auto node = findOrCreateNode(m_root, path)) { + if (auto node = findOrCreateNode(m_root, path.parentDir())) { insertFile(node, path); if (auto module = findModuleFor(node)) dirtyModules.insert(module); @@ -182,15 +182,15 @@ void CMakeGenerator::update(const QSet<QString> &added, const QSet<QString> &rem for (const QString &remove : removed) { const Utils::FilePath path = Utils::FilePath::fromString(remove); - if (auto node = findNode(m_root, path)) { + if (auto node = findNode(m_root, path.parentDir())) { removeFile(node, path); if (auto module = findModuleFor(node)) dirtyModules.insert(module); } } - for (auto module : dirtyModules) - m_writer->writeModuleCMakeFile(module, m_root); + createCMakeFiles(m_root); + createSourceFiles(); } bool CMakeGenerator::isQml(const Utils::FilePath &path) const @@ -282,9 +282,8 @@ NodePtr CMakeGenerator::findModuleFor(const NodePtr &node) const NodePtr CMakeGenerator::findNode(NodePtr &node, const Utils::FilePath &path) const { - const Utils::FilePath parentDir = path.parentDir(); for (NodePtr &child : node->subdirs) { - if (child->dir == parentDir) + if (child->dir == path) return child; if (path.isChildOf(child->dir)) return findNode(child, path); @@ -300,21 +299,34 @@ NodePtr CMakeGenerator::findOrCreateNode(NodePtr &node, const Utils::FilePath &p if (!path.isChildOf(node->dir)) return nullptr; - const Utils::FilePath parentDir = path.parentDir(); - const Utils::FilePath relative = parentDir.relativeChildPath(node->dir); + auto findSubDir = [](NodePtr &node, const Utils::FilePath &path) -> NodePtr { + for (NodePtr child : node->subdirs) { + if (child->dir == path) + return child; + } + return nullptr; + }; + + const Utils::FilePath relative = path.relativeChildPath(node->dir); const QChar separator = relative.pathComponentSeparator(); const QList<QStringView> components = relative.pathView().split(separator); - NodePtr last = node; + NodePtr lastNode = node; for (const auto &comp : components) { + + Utils::FilePath subPath = lastNode->dir.pathAppended(comp.toString()); + if (NodePtr sub = findSubDir(lastNode, subPath)) { + lastNode = sub; + continue; + } NodePtr newNode = std::make_shared<Node>(); - newNode->parent = last; + newNode->parent = lastNode; newNode->name = comp.toString(); - newNode->dir = last->dir.pathAppended(comp.toString()); - last->subdirs.push_back(newNode); - last = newNode; + newNode->dir = subPath; + lastNode->subdirs.push_back(newNode); + lastNode = newNode; } - return last; + return lastNode; } bool findFileWithGetter(const Utils::FilePath &file, const NodePtr &node, const FileGetter &getter) diff --git a/src/plugins/qmlprojectmanager/cmakegen/cmakewriterv1.cpp b/src/plugins/qmlprojectmanager/cmakegen/cmakewriterv1.cpp index 220d8622bf..6d2d93a76b 100644 --- a/src/plugins/qmlprojectmanager/cmakegen/cmakewriterv1.cpp +++ b/src/plugins/qmlprojectmanager/cmakegen/cmakewriterv1.cpp @@ -57,50 +57,53 @@ void CMakeWriterV1::writeRootCMakeFile(const NodePtr &node) const writeFile(componentPath, compTemplate); } - const Utils::FilePath file = node->dir.pathAppended("CMakeLists.txt"); - const QString appName = parent()->projectName() + "App"; - - QString fileSection = ""; - const QString configFile = getEnvironmentVariable(ENV_VARIABLE_CONTROLCONF); - if (!configFile.isEmpty()) - fileSection = QString("\t\t%1").arg(configFile); - - const QString fileTemplate = readTemplate(":/templates/cmakeroot_v1"); - const QString fileContent = fileTemplate.arg(appName, fileSection); - writeFile(file, fileContent); - const Utils::FilePath sharedFile = node->dir.pathAppended("CMakeLists.txt.shared"); - const QString sharedTemplate = readTemplate(":/templates/cmake_shared"); - writeFile(sharedFile, sharedTemplate); - - const Utils::FilePath userFile = node->dir.pathAppended("qds.cmake"); - QString userFileContent(DO_NOT_EDIT_FILE); - userFileContent.append(makeSubdirectoriesBlock(node)); - userFileContent.append("\n"); - - QString pluginNames; - std::vector<QString> plugs = plugins(node); - for (size_t i = 0; i < plugs.size(); ++i) { - pluginNames.append("\t" + plugs[i] + "plugin"); - if (i != plugs.size() - 1) - pluginNames.append("\n"); + if (!sharedFile.exists()) { + const QString sharedTemplate = readTemplate(":/templates/cmake_shared"); + writeFile(sharedFile, sharedTemplate); } - QString linkLibrariesTemplate( - "target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE\n" - "%1)"); + const Utils::FilePath file = node->dir.pathAppended("CMakeLists.txt"); + if (!file.exists()) { + const QString appName = parent()->projectName() + "App"; - userFileContent.append(linkLibrariesTemplate.arg(pluginNames)); + QString fileSection = ""; + const QString configFile = getEnvironmentVariable(ENV_VARIABLE_CONTROLCONF); + if (!configFile.isEmpty()) + fileSection = QString("\t\t%1").arg(configFile); - writeFile(userFile, userFileContent); + const QString fileTemplate = readTemplate(":/templates/cmakeroot_v1"); + const QString fileContent = fileTemplate.arg(appName, fileSection); + writeFile(file, fileContent); + } } void CMakeWriterV1::writeModuleCMakeFile(const NodePtr &node, const NodePtr &) const { QTC_ASSERT(parent(), return); - if (node->type == Node::Type::App) + if (node->type == Node::Type::App) { + const Utils::FilePath userFile = node->dir.pathAppended("qds.cmake"); + QString userFileContent(DO_NOT_EDIT_FILE); + userFileContent.append(makeSubdirectoriesBlock(node)); + userFileContent.append("\n"); + + QString pluginNames; + std::vector<QString> plugs = plugins(node); + for (size_t i = 0; i < plugs.size(); ++i) { + pluginNames.append("\t" + plugs[i] + "plugin"); + if (i != plugs.size() - 1) + pluginNames.append("\n"); + } + + QString linkLibrariesTemplate( + "target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE\n" + "%1)"); + + userFileContent.append(linkLibrariesTemplate.arg(pluginNames)); + writeFile(userFile, userFileContent); return; + } Utils::FilePath writeToFile = node->dir.pathAppended("CMakeLists.txt"); if (node->type == Node::Type::Folder && parent()->hasChildModule(node)) { |