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/algorithm.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
@@ -395,31 +396,19 @@ void addProjects(const QHash<Utils::FilePath, ProjectNode *> &cmakeListsNodes,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<FolderNode *> addSourceGroups(ProjectNode *targetRoot,
|
std::unique_ptr<FolderNode> createSourceGroupNode(const QString &sourceGroupName,
|
||||||
const TargetDetails &td,
|
|
||||||
const FilePath &sourceDirectory)
|
const FilePath &sourceDirectory)
|
||||||
{
|
{
|
||||||
QVector<FolderNode *> sourceGroupNodes;
|
if (sourceGroupName.isEmpty())
|
||||||
if (td.sourceGroups.size() == 1) {
|
return {};
|
||||||
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,
|
auto sgNode = createCMakeVFolder(sourceDirectory,
|
||||||
Node::DefaultFolderPriority + 5,
|
Node::DefaultFolderPriority + 5,
|
||||||
sg);
|
sourceGroupName);
|
||||||
|
|
||||||
sgNode->setListInProject(false);
|
sgNode->setListInProject(false);
|
||||||
|
sgNode->setIcon(QIcon::fromTheme("edit-copy", ::Utils::Icons::COPY.icon()));
|
||||||
sourceGroupNodes.append(sgNode.get());
|
return sgNode;
|
||||||
targetRoot->addNode(std::move(sgNode));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sourceGroupNodes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void addCompileGroups(ProjectNode *targetRoot,
|
void addCompileGroups(ProjectNode *targetRoot,
|
||||||
@@ -439,11 +428,11 @@ void addCompileGroups(ProjectNode *targetRoot,
|
|||||||
targetRoot->forEachGenericNode(
|
targetRoot->forEachGenericNode(
|
||||||
[&alreadyListed](const Node *n) { alreadyListed.insert(n->filePath()); });
|
[&alreadyListed](const Node *n) { alreadyListed.insert(n->filePath()); });
|
||||||
|
|
||||||
QVector<FolderNode *> sourceGroupNodes = addSourceGroups(targetRoot, td, sourceDirectory);
|
|
||||||
const QDir topSourceDir(topSourceDirectory.toString());
|
const QDir topSourceDir(topSourceDirectory.toString());
|
||||||
|
|
||||||
std::vector<std::unique_ptr<FileNode>> buildFileNodes;
|
std::vector<std::unique_ptr<FileNode>> buildFileNodes;
|
||||||
std::vector<std::unique_ptr<FileNode>> otherFileNodes;
|
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) {
|
for (const SourceInfo &si : td.sources) {
|
||||||
const FilePath sourcePath = FilePath::fromString(
|
const FilePath sourcePath = FilePath::fromString(
|
||||||
@@ -467,12 +456,34 @@ void addCompileGroups(ProjectNode *targetRoot,
|
|||||||
if (sourcePath.isChildOf(buildDirectory) && !inSourceBuild) {
|
if (sourcePath.isChildOf(buildDirectory) && !inSourceBuild) {
|
||||||
buildFileNodes.emplace_back(std::move(node));
|
buildFileNodes.emplace_back(std::move(node));
|
||||||
} else if (sourcePath.isChildOf(sourceDirectory)) {
|
} else if (sourcePath.isChildOf(sourceDirectory)) {
|
||||||
sourceGroupNodes[si.sourceGroup]->addNestedNode(std::move(node));
|
sourceGroupFileNodes[si.sourceGroup].emplace_back(std::move(node));
|
||||||
} else {
|
} else {
|
||||||
otherFileNodes.emplace_back(std::move(node));
|
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,
|
addCMakeVFolder(targetRoot,
|
||||||
buildDirectory,
|
buildDirectory,
|
||||||
100,
|
100,
|
||||||
|
|||||||
Reference in New Issue
Block a user