forked from qt-creator/qt-creator
CMake: Improve handling of source_groups
* Use a special icon for source groups, so that those can get destinguished from folders * Simplify folder structure below source groups to not include common paths elements Task-number: QTCREATORBUG-23372 Change-Id: Ifcb35af9b35805a6272f27b0801c2fe7dfce95ae Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
@@ -395,31 +396,19 @@ void addProjects(const QHash<Utils::FilePath, ProjectNode *> &cmakeListsNodes,
|
||||
}
|
||||
}
|
||||
|
||||
QVector<FolderNode *> addSourceGroups(ProjectNode *targetRoot,
|
||||
const TargetDetails &td,
|
||||
const FilePath &sourceDirectory)
|
||||
std::unique_ptr<FolderNode> createSourceGroupNode(const QString &sourceGroupName,
|
||||
const FilePath &sourceDirectory)
|
||||
{
|
||||
QVector<FolderNode *> sourceGroupNodes;
|
||||
if (td.sourceGroups.size() == 1) {
|
||||
sourceGroupNodes.append(
|
||||
targetRoot); // Only one source group, so do not bother to display any:-)
|
||||
} else {
|
||||
for (const QString &sg : td.sourceGroups) {
|
||||
if (sg.isEmpty()) {
|
||||
sourceGroupNodes.append(targetRoot);
|
||||
} else {
|
||||
auto sgNode = createCMakeVFolder(sourceDirectory,
|
||||
Node::DefaultFolderPriority + 5,
|
||||
sg);
|
||||
sgNode->setListInProject(false);
|
||||
if (sourceGroupName.isEmpty())
|
||||
return {};
|
||||
|
||||
sourceGroupNodes.append(sgNode.get());
|
||||
targetRoot->addNode(std::move(sgNode));
|
||||
}
|
||||
}
|
||||
}
|
||||
auto sgNode = createCMakeVFolder(sourceDirectory,
|
||||
Node::DefaultFolderPriority + 5,
|
||||
sourceGroupName);
|
||||
|
||||
return sourceGroupNodes;
|
||||
sgNode->setListInProject(false);
|
||||
sgNode->setIcon(QIcon::fromTheme("edit-copy", ::Utils::Icons::COPY.icon()));
|
||||
return sgNode;
|
||||
}
|
||||
|
||||
void addCompileGroups(ProjectNode *targetRoot,
|
||||
@@ -439,11 +428,11 @@ void addCompileGroups(ProjectNode *targetRoot,
|
||||
targetRoot->forEachGenericNode(
|
||||
[&alreadyListed](const Node *n) { alreadyListed.insert(n->filePath()); });
|
||||
|
||||
QVector<FolderNode *> sourceGroupNodes = addSourceGroups(targetRoot, td, sourceDirectory);
|
||||
const QDir topSourceDir(topSourceDirectory.toString());
|
||||
|
||||
std::vector<std::unique_ptr<FileNode>> buildFileNodes;
|
||||
std::vector<std::unique_ptr<FileNode>> otherFileNodes;
|
||||
std::vector<std::vector<std::unique_ptr<FileNode>>> sourceGroupFileNodes{td.sourceGroups.size()};
|
||||
|
||||
for (const SourceInfo &si : td.sources) {
|
||||
const FilePath sourcePath = FilePath::fromString(
|
||||
@@ -467,12 +456,34 @@ void addCompileGroups(ProjectNode *targetRoot,
|
||||
if (sourcePath.isChildOf(buildDirectory) && !inSourceBuild) {
|
||||
buildFileNodes.emplace_back(std::move(node));
|
||||
} else if (sourcePath.isChildOf(sourceDirectory)) {
|
||||
sourceGroupNodes[si.sourceGroup]->addNestedNode(std::move(node));
|
||||
sourceGroupFileNodes[si.sourceGroup].emplace_back(std::move(node));
|
||||
} else {
|
||||
otherFileNodes.emplace_back(std::move(node));
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate base directory for source groups:
|
||||
for (size_t i = 0; i < sourceGroupFileNodes.size(); ++i) {
|
||||
std::vector<std::unique_ptr<FileNode>> ¤t = sourceGroupFileNodes[i];
|
||||
FilePath baseDirectory;
|
||||
// All the sourceGroupFileNodes are below sourceDirectory, so this is safe:
|
||||
for (const std::unique_ptr<FileNode> &fn : current) {
|
||||
if (baseDirectory.isEmpty()) {
|
||||
baseDirectory = fn->filePath().parentDir();
|
||||
} else {
|
||||
baseDirectory = Utils::FileUtils::commonPath(baseDirectory, fn->filePath());
|
||||
}
|
||||
}
|
||||
|
||||
FolderNode *insertNode = targetRoot;
|
||||
if (auto sgNode = createSourceGroupNode(td.sourceGroups[i], baseDirectory)) {
|
||||
insertNode = sgNode.get();
|
||||
targetRoot->addNode(std::move(sgNode));
|
||||
}
|
||||
|
||||
insertNode->addNestedNodes(std::move(sourceGroupFileNodes[i]));
|
||||
}
|
||||
|
||||
addCMakeVFolder(targetRoot,
|
||||
buildDirectory,
|
||||
100,
|
||||
|
||||
Reference in New Issue
Block a user