Meson: fix broken project tree on windows

Change-Id: I88d0e5b6f1547d5fa6fe832d26bafee59e535a4b
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Alexis Jeandet
2020-06-24 09:44:55 +02:00
parent 1c8b9e3d48
commit 8a2cb794b9
3 changed files with 30 additions and 28 deletions

View File

@@ -23,14 +23,21 @@
**
****************************************************************************/
#pragma once
#include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <utils/optional.h>
#include <QDir>
#include <QString>
#include <QVariant>
namespace MesonProjectManager {
namespace Internal {
inline QStringList cleanPath(QStringList &&paths)
{
return Utils::transform(paths, QDir::cleanPath);
}
struct Target
{
enum class Type {
@@ -58,8 +65,8 @@ struct Target
: language{std::move(language)}
, compiler{std::move(compiler)}
, parameters{std::move(parameters)}
, sources{std::move(sources)}
, generatedSources{std::move(generatedSources)}
, sources{cleanPath(std::move(sources))}
, generatedSources{cleanPath(std::move(generatedSources))}
{}
};
using SourceGroupList = std::vector<SourceGroup>;
@@ -71,17 +78,13 @@ struct Target
const Utils::optional<QString> subproject;
const SourceGroupList sources;
static inline QString fullName(const Target &target)
static inline QString fullName(const Utils::FilePath &srcDir, const Target &target)
{
// TODO, this is bad, might be moved in a place where src dir is known
if (target.fileName.first().startsWith("/")) {
auto fname = target.fileName.first().split('/');
auto definedIn = target.definedIn.split('/');
definedIn.pop_back();
int i = std::min(definedIn.length(), fname.length()) - 1;
for (; i >= 0 && fname[i] == definedIn[i]; --i)
;
return fname.mid(i + 1).join("/");
using namespace Utils;
if (FileUtils::isAbsolutePath(target.fileName.first())) {
const auto fname = target.fileName.first().split('/').last();
QString definedIn = FilePath::fromString(target.definedIn).absolutePath().toString();
return definedIn.remove(srcDir.toString()) + '/' + fname;
} else {
return target.fileName.first();
}
@@ -116,8 +119,8 @@ struct Target
: type{toType(type)}
, name{std::move(name)}
, id{std::move(id)}
, definedIn{std::move(definedIn)}
, fileName{std::move(fileName)}
, definedIn{QDir::cleanPath(definedIn)}
, fileName{cleanPath(std::move(fileName))}
, subproject{subproject.isNull() ? Utils::nullopt
: Utils::optional<QString>{std::move(subproject)}}
, sources{std::move(sources)}

View File

@@ -98,7 +98,7 @@ QStringList toAbsolutePath(const Utils::FilePath &refPath, QStringList &pathList
std::cend(pathList),
std::back_inserter(allAbs),
[refPath](const QString &path) {
if (path.startsWith("/"))
if (Utils::FileUtils::isAbsolutePath(path))
return path;
return refPath.pathAppended(path).toString();
});
@@ -200,11 +200,11 @@ QList<ProjectExplorer::BuildTargetInfo> MesonProjectParser::appsTargets() const
QList<ProjectExplorer::BuildTargetInfo> apps;
std::for_each(std::cbegin(m_parserResult.targets),
std::cend(m_parserResult.targets),
[&apps](const Target &target) {
[&apps, &srcDir = m_srcDir](const Target &target) {
if (target.type == Target::Type::executable) {
ProjectExplorer::BuildTargetInfo bti;
bti.displayName = target.name;
bti.buildKey = Target::fullName(target);
bti.buildKey = Target::fullName(srcDir, target);
bti.displayNameUniquifier = bti.buildKey;
bti.targetFilePath = Utils::FilePath::fromString(target.fileName.first());
bti.workingDirectory
@@ -260,10 +260,9 @@ void MesonProjectParser::update(const QFuture<MesonProjectParser::ParserData *>
m_parserResult = std::move(parserData->data);
m_rootNode = std::move(parserData->rootNode);
m_targetsNames.clear();
std::transform(std::cbegin(m_parserResult.targets),
std::cend(m_parserResult.targets),
std::back_inserter(m_targetsNames),
Target::fullName);
for (const Target &target : m_parserResult.targets) {
m_targetsNames.push_back(Target::fullName(m_srcDir, target));
}
addMissingTargets(m_targetsNames);
m_targetsNames.sort();
delete data;
@@ -278,11 +277,11 @@ ProjectExplorer::RawProjectPart MesonProjectParser::buildRawPart(
{
ProjectExplorer::RawProjectPart part;
part.setDisplayName(target.name);
part.setBuildSystemTarget(Target::fullName(target));
part.setBuildSystemTarget(Target::fullName(m_srcDir, target));
part.setFiles(sources.sources + sources.generatedSources);
auto flags = splitArgs(sources.parameters);
part.setMacros(flags.macros);
part.setIncludePaths(toAbsolutePath(this->m_buildDir, flags.includePaths));
part.setIncludePaths(toAbsolutePath(m_buildDir, flags.includePaths));
part.setProjectFileLocation(target.definedIn);
if (sources.language == "cpp")
part.setFlagsForCxx({cxxToolChain, flags.args});

View File

@@ -42,14 +42,14 @@ void buildTargetTree(std::unique_ptr<MesonProjectNode> &root, const Target &targ
void addTargetNode(std::unique_ptr<MesonProjectNode> &root, const Target &target)
{
root->findNode([&target, path = Utils::FilePath::fromString(target.definedIn)](
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(target));
auto targetNode = std::make_unique<MesonTargetNode>(
path.absolutePath().pathAppended(target.name),
Target::fullName(Utils::FilePath::fromString(root->path()), target));
targetNode->setDisplayName(target.name);
asFolder->addNode(std::move(targetNode));
}
@@ -84,7 +84,7 @@ std::unique_ptr<MesonProjectNode> ProjectTree::buildTree(const Utils::FilePath &
addTargetNode(root, target);
});
for (Utils::FilePath bsFile : bsFiles) {
if (!bsFile.startsWith("/"))
if (!bsFile.toFileInfo().isAbsolute())
bsFile = srcDir.pathAppended(bsFile.toString());
root->addNestedNode(
std::make_unique<ProjectExplorer::FileNode>(bsFile, ProjectExplorer::FileType::Project));