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

View File

@@ -98,7 +98,7 @@ QStringList toAbsolutePath(const Utils::FilePath &refPath, QStringList &pathList
std::cend(pathList), std::cend(pathList),
std::back_inserter(allAbs), std::back_inserter(allAbs),
[refPath](const QString &path) { [refPath](const QString &path) {
if (path.startsWith("/")) if (Utils::FileUtils::isAbsolutePath(path))
return path; return path;
return refPath.pathAppended(path).toString(); return refPath.pathAppended(path).toString();
}); });
@@ -200,11 +200,11 @@ QList<ProjectExplorer::BuildTargetInfo> MesonProjectParser::appsTargets() const
QList<ProjectExplorer::BuildTargetInfo> apps; QList<ProjectExplorer::BuildTargetInfo> apps;
std::for_each(std::cbegin(m_parserResult.targets), std::for_each(std::cbegin(m_parserResult.targets),
std::cend(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) { if (target.type == Target::Type::executable) {
ProjectExplorer::BuildTargetInfo bti; ProjectExplorer::BuildTargetInfo bti;
bti.displayName = target.name; bti.displayName = target.name;
bti.buildKey = Target::fullName(target); bti.buildKey = Target::fullName(srcDir, target);
bti.displayNameUniquifier = bti.buildKey; bti.displayNameUniquifier = bti.buildKey;
bti.targetFilePath = Utils::FilePath::fromString(target.fileName.first()); bti.targetFilePath = Utils::FilePath::fromString(target.fileName.first());
bti.workingDirectory bti.workingDirectory
@@ -260,10 +260,9 @@ void MesonProjectParser::update(const QFuture<MesonProjectParser::ParserData *>
m_parserResult = std::move(parserData->data); m_parserResult = std::move(parserData->data);
m_rootNode = std::move(parserData->rootNode); m_rootNode = std::move(parserData->rootNode);
m_targetsNames.clear(); m_targetsNames.clear();
std::transform(std::cbegin(m_parserResult.targets), for (const Target &target : m_parserResult.targets) {
std::cend(m_parserResult.targets), m_targetsNames.push_back(Target::fullName(m_srcDir, target));
std::back_inserter(m_targetsNames), }
Target::fullName);
addMissingTargets(m_targetsNames); addMissingTargets(m_targetsNames);
m_targetsNames.sort(); m_targetsNames.sort();
delete data; delete data;
@@ -278,11 +277,11 @@ ProjectExplorer::RawProjectPart MesonProjectParser::buildRawPart(
{ {
ProjectExplorer::RawProjectPart part; ProjectExplorer::RawProjectPart part;
part.setDisplayName(target.name); part.setDisplayName(target.name);
part.setBuildSystemTarget(Target::fullName(target)); part.setBuildSystemTarget(Target::fullName(m_srcDir, target));
part.setFiles(sources.sources + sources.generatedSources); part.setFiles(sources.sources + sources.generatedSources);
auto flags = splitArgs(sources.parameters); auto flags = splitArgs(sources.parameters);
part.setMacros(flags.macros); part.setMacros(flags.macros);
part.setIncludePaths(toAbsolutePath(this->m_buildDir, flags.includePaths)); part.setIncludePaths(toAbsolutePath(m_buildDir, flags.includePaths));
part.setProjectFileLocation(target.definedIn); part.setProjectFileLocation(target.definedIn);
if (sources.language == "cpp") if (sources.language == "cpp")
part.setFlagsForCxx({cxxToolChain, flags.args}); 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) 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) { ProjectExplorer::Node *node) {
if (node->filePath() == path.absolutePath()) { if (node->filePath() == path.absolutePath()) {
auto asFolder = dynamic_cast<ProjectExplorer::FolderNode *>(node); auto asFolder = dynamic_cast<ProjectExplorer::FolderNode *>(node);
if (asFolder) { if (asFolder) {
auto targetNode = std::make_unique<MesonTargetNode>(path.absolutePath().pathAppended( auto targetNode = std::make_unique<MesonTargetNode>(
target.name), path.absolutePath().pathAppended(target.name),
Target::fullName(target)); Target::fullName(Utils::FilePath::fromString(root->path()), target));
targetNode->setDisplayName(target.name); targetNode->setDisplayName(target.name);
asFolder->addNode(std::move(targetNode)); asFolder->addNode(std::move(targetNode));
} }
@@ -84,7 +84,7 @@ std::unique_ptr<MesonProjectNode> ProjectTree::buildTree(const Utils::FilePath &
addTargetNode(root, target); addTargetNode(root, target);
}); });
for (Utils::FilePath bsFile : bsFiles) { for (Utils::FilePath bsFile : bsFiles) {
if (!bsFile.startsWith("/")) if (!bsFile.toFileInfo().isAbsolute())
bsFile = srcDir.pathAppended(bsFile.toString()); bsFile = srcDir.pathAppended(bsFile.toString());
root->addNestedNode( root->addNestedNode(
std::make_unique<ProjectExplorer::FileNode>(bsFile, ProjectExplorer::FileType::Project)); std::make_unique<ProjectExplorer::FileNode>(bsFile, ProjectExplorer::FileType::Project));