forked from qt-creator/qt-creator
Meson: Inline projecttree filepair
Change-Id: I62ba5ef90083f9bc342b4900bbc9ba57390d5e3f Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -38,8 +38,6 @@ add_qtc_plugin(MesonProjectManager
|
||||
ninjabuildstep.h
|
||||
ninjaparser.cpp
|
||||
ninjaparser.h
|
||||
projecttree.cpp
|
||||
projecttree.h
|
||||
resources_meson.qrc
|
||||
settings.cpp
|
||||
settings.h
|
||||
|
||||
@@ -55,8 +55,6 @@ Project {
|
||||
"ninjaparser.h",
|
||||
"mesonprojectnodes.cpp",
|
||||
"mesonprojectnodes.h",
|
||||
"projecttree.cpp",
|
||||
"projecttree.h",
|
||||
"resources_meson.qrc",
|
||||
"settings.cpp",
|
||||
"settings.h",
|
||||
|
||||
@@ -7,10 +7,9 @@
|
||||
#include "mesonprojectmanagertr.h"
|
||||
#include "mesonprojectnodes.h"
|
||||
#include "mesontools.h"
|
||||
#include "projecttree.h"
|
||||
|
||||
#include <coreplugin/messagemanager.h>
|
||||
#include <coreplugin/messagemanager.h>
|
||||
#include <coreplugin/progressmanager/processprogress.h>
|
||||
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
@@ -23,8 +22,6 @@
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <coreplugin/progressmanager/processprogress.h>
|
||||
|
||||
using namespace Core;
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
@@ -40,6 +37,58 @@ struct CompilerArgs
|
||||
Macros macros;
|
||||
};
|
||||
|
||||
static void buildTargetTree(std::unique_ptr<MesonProjectNode> &root, const Target &target)
|
||||
{
|
||||
const auto path = FilePath::fromString(target.definedIn);
|
||||
for (const auto &group : target.sources) {
|
||||
for (const auto &file : group.sources) {
|
||||
root->addNestedNode(std::make_unique<FileNode>(FilePath::fromString(file),
|
||||
FileType::Source));
|
||||
}
|
||||
}
|
||||
for (const auto &extraFile : target.extraFiles) {
|
||||
root->addNestedNode(std::make_unique<FileNode>(FilePath::fromString(extraFile),
|
||||
FileType::Unknown));
|
||||
}
|
||||
}
|
||||
|
||||
static void addTargetNode(std::unique_ptr<MesonProjectNode> &root, const Target &target)
|
||||
{
|
||||
root->findNode([&root, &target, path = FilePath::fromString(target.definedIn)](Node *node) {
|
||||
if (node->filePath() == path.absolutePath()) {
|
||||
auto asFolder = dynamic_cast<FolderNode *>(node);
|
||||
if (asFolder) {
|
||||
auto targetNode = std::make_unique<MesonTargetNode>(
|
||||
path.absolutePath().pathAppended(target.name),
|
||||
Target::fullName(root->path(), target));
|
||||
targetNode->setDisplayName(target.name);
|
||||
asFolder->addNode(std::move(targetNode));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
static std::unique_ptr<MesonProjectNode> buildTree(const FilePath &srcDir,
|
||||
const TargetsList &targets,
|
||||
const FilePaths &bsFiles)
|
||||
{
|
||||
std::set<FilePath> targetPaths;
|
||||
auto root = std::make_unique<MesonProjectNode>(srcDir);
|
||||
for (const Target &target : targets) {
|
||||
buildTargetTree(root, target);
|
||||
targetPaths.insert(FilePath::fromString(target.definedIn).absolutePath());
|
||||
addTargetNode(root, target);
|
||||
}
|
||||
for (FilePath bsFile : bsFiles) {
|
||||
if (!bsFile.toFileInfo().isAbsolute())
|
||||
bsFile = srcDir.pathAppended(bsFile.toString());
|
||||
root->addNestedNode(std::make_unique<FileNode>(bsFile, FileType::Project));
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
static std::optional<QString> extractValueIfMatches(const QString &arg,
|
||||
const QStringList &candidates)
|
||||
{
|
||||
@@ -196,16 +245,13 @@ QList<BuildTargetInfo> MesonProjectParser::appsTargets() const
|
||||
|
||||
bool MesonProjectParser::startParser()
|
||||
{
|
||||
m_parserFutureResult = Utils::asyncRun(
|
||||
ProjectExplorerPlugin::sharedThreadPool(),
|
||||
[processOutput = m_stdo, introType = m_introType,
|
||||
buildDir = m_buildDir, srcDir = m_srcDir] {
|
||||
m_parserFutureResult = Utils::asyncRun(ProjectExplorerPlugin::sharedThreadPool(),
|
||||
[processOutput = m_stdo, introType = m_introType, buildDir = m_buildDir, srcDir = m_srcDir] {
|
||||
if (introType == IntroDataType::file)
|
||||
return extractParserResults(srcDir, MesonInfoParser::parse(buildDir));
|
||||
else
|
||||
return extractParserResults(srcDir, MesonInfoParser::parse(processOutput));
|
||||
});
|
||||
|
||||
Utils::onFinished(m_parserFutureResult, this, &MesonProjectParser::update);
|
||||
return true;
|
||||
}
|
||||
@@ -213,9 +259,7 @@ bool MesonProjectParser::startParser()
|
||||
MesonProjectParser::ParserData *MesonProjectParser::extractParserResults(
|
||||
const FilePath &srcDir, MesonInfoParser::Result &&parserResult)
|
||||
{
|
||||
auto rootNode = ProjectTree::buildTree(srcDir,
|
||||
parserResult.targets,
|
||||
parserResult.buildSystemFiles);
|
||||
auto rootNode = buildTree(srcDir, parserResult.targets, parserResult.buildSystemFiles);
|
||||
return new ParserData{std::move(parserResult), std::move(rootNode)};
|
||||
}
|
||||
|
||||
@@ -309,7 +353,7 @@ bool MesonProjectParser::matchesKit(const KitData &kit)
|
||||
|
||||
static QVersionNumber versionNumber(const FilePath &buildDir)
|
||||
{
|
||||
const Utils::FilePath jsonFile = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INFO;
|
||||
const FilePath jsonFile = buildDir / Constants::MESON_INFO_DIR / Constants::MESON_INFO;
|
||||
auto obj = load<QJsonObject>(jsonFile.toFSPathString());
|
||||
if (!obj)
|
||||
return {};
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
// Copyright (C) 2020 Alexis Jeandet.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "projecttree.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace MesonProjectManager::Internal {
|
||||
|
||||
ProjectTree::ProjectTree() {}
|
||||
|
||||
void buildTargetTree(std::unique_ptr<MesonProjectNode> &root, const Target &target)
|
||||
{
|
||||
const auto path = Utils::FilePath::fromString(target.definedIn);
|
||||
for (const auto &group : target.sources) {
|
||||
for (const auto &file : group.sources) {
|
||||
root->addNestedNode(
|
||||
std::make_unique<ProjectExplorer::FileNode>(Utils::FilePath::fromString(file),
|
||||
ProjectExplorer::FileType::Source));
|
||||
}
|
||||
}
|
||||
for (const auto &extraFile : target.extraFiles) {
|
||||
root->addNestedNode(
|
||||
std::make_unique<ProjectExplorer::FileNode>(Utils::FilePath::fromString(extraFile),
|
||||
ProjectExplorer::FileType::Unknown));
|
||||
}
|
||||
}
|
||||
|
||||
void addTargetNode(std::unique_ptr<MesonProjectNode> &root, const Target &target)
|
||||
{
|
||||
root->findNode([&root, &target, path = Utils::FilePath::fromString(target.definedIn)](
|
||||
ProjectExplorer::Node *node) {
|
||||
if (node->filePath() == path.absolutePath()) {
|
||||
auto asFolder = dynamic_cast<ProjectExplorer::FolderNode *>(node);
|
||||
if (asFolder) {
|
||||
auto targetNode = std::make_unique<MesonTargetNode>(
|
||||
path.absolutePath().pathAppended(target.name),
|
||||
Target::fullName(root->path(), target));
|
||||
targetNode->setDisplayName(target.name);
|
||||
asFolder->addNode(std::move(targetNode));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void addOptionsFile(std::unique_ptr<MesonProjectNode> &project)
|
||||
{
|
||||
auto meson_options = project->filePath().pathAppended("meson_options.txt");
|
||||
if (meson_options.exists())
|
||||
project->addNestedNode(
|
||||
std::make_unique<ProjectExplorer::FileNode>(meson_options,
|
||||
ProjectExplorer::FileType::Project));
|
||||
}
|
||||
|
||||
std::unique_ptr<MesonProjectNode> ProjectTree::buildTree(const Utils::FilePath &srcDir,
|
||||
const TargetsList &targets,
|
||||
const Utils::FilePaths &bsFiles)
|
||||
{
|
||||
using namespace ProjectExplorer;
|
||||
std::set<Utils::FilePath> targetPaths;
|
||||
auto root = std::make_unique<MesonProjectNode>(srcDir);
|
||||
for (const Target &target : targets) {
|
||||
buildTargetTree(root, target);
|
||||
targetPaths.insert(Utils::FilePath::fromString(target.definedIn).absolutePath());
|
||||
addTargetNode(root, target);
|
||||
}
|
||||
for (Utils::FilePath bsFile : bsFiles) {
|
||||
if (!bsFile.toFileInfo().isAbsolute())
|
||||
bsFile = srcDir.pathAppended(bsFile.toString());
|
||||
root->addNestedNode(
|
||||
std::make_unique<ProjectExplorer::FileNode>(bsFile, ProjectExplorer::FileType::Project));
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
} // namespace MesonProjectManager::Internal
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright (C) 2020 Alexis Jeandet.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "mesoninfoparser.h"
|
||||
#include "mesonprojectnodes.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
namespace MesonProjectManager::Internal {
|
||||
|
||||
class ProjectTree
|
||||
{
|
||||
public:
|
||||
ProjectTree();
|
||||
static std::unique_ptr<MesonProjectNode> buildTree(const Utils::FilePath &srcDir,
|
||||
const TargetsList &targets,
|
||||
const Utils::FilePaths &bsFiles);
|
||||
};
|
||||
|
||||
} // namespace MesonProjectManager::Internal
|
||||
Reference in New Issue
Block a user