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>
(cherry picked from commit 1b52357d01)
This commit is contained in:
Knud Dollereder
2024-04-19 16:17:57 +02:00
parent 40c3c66c1f
commit 98af0cb064
2 changed files with 63 additions and 48 deletions

View File

@@ -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) {
NodePtr newNode = std::make_shared<Node>();
newNode->parent = last;
newNode->name = comp.toString();
newNode->dir = last->dir.pathAppended(comp.toString());
last->subdirs.push_back(newNode);
last = newNode;
Utils::FilePath subPath = lastNode->dir.pathAppended(comp.toString());
if (NodePtr sub = findSubDir(lastNode, subPath)) {
lastNode = sub;
continue;
}
return last;
NodePtr newNode = std::make_shared<Node>();
newNode->parent = lastNode;
newNode->name = comp.toString();
newNode->dir = subPath;
lastNode->subdirs.push_back(newNode);
lastNode = newNode;
}
return lastNode;
}
bool findFileWithGetter(const Utils::FilePath &file, const NodePtr &node, const FileGetter &getter)

View File

@@ -57,7 +57,14 @@ void CMakeWriterV1::writeRootCMakeFile(const NodePtr &node) const
writeFile(componentPath, compTemplate);
}
const Utils::FilePath sharedFile = node->dir.pathAppended("CMakeLists.txt.shared");
if (!sharedFile.exists()) {
const QString sharedTemplate = readTemplate(":/templates/cmake_shared");
writeFile(sharedFile, sharedTemplate);
}
const Utils::FilePath file = node->dir.pathAppended("CMakeLists.txt");
if (!file.exists()) {
const QString appName = parent()->projectName() + "App";
QString fileSection = "";
@@ -68,11 +75,14 @@ void CMakeWriterV1::writeRootCMakeFile(const NodePtr &node) const
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);
void CMakeWriterV1::writeModuleCMakeFile(const NodePtr &node, const NodePtr &) const
{
QTC_ASSERT(parent(), return);
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));
@@ -91,16 +101,9 @@ void CMakeWriterV1::writeRootCMakeFile(const NodePtr &node) const
"%1)");
userFileContent.append(linkLibrariesTemplate.arg(pluginNames));
writeFile(userFile, userFileContent);
}
void CMakeWriterV1::writeModuleCMakeFile(const NodePtr &node, const NodePtr &) const
{
QTC_ASSERT(parent(), return);
if (node->type == Node::Type::App)
return;
}
Utils::FilePath writeToFile = node->dir.pathAppended("CMakeLists.txt");
if (node->type == Node::Type::Folder && parent()->hasChildModule(node)) {