Ensure that target name is relative to build dir and without leading '/'

Fixes: QTCREATORBUG-29349
Change-Id: I7471242cd422a68a2652ff23741d0615380e2e8d
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Alexis Jeandet
2023-07-10 13:05:52 +02:00
parent 3745394fde
commit d4260dab85
2 changed files with 11 additions and 9 deletions

View File

@@ -183,7 +183,7 @@ QList<ProjectExplorer::BuildTargetInfo> MesonProjectParser::appsTargets() const
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(m_srcDir, target); bti.buildKey = Target::fullName(m_buildDir, 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 = Utils::FilePath::fromString(target.fileName.first()).absolutePath(); bti.workingDirectory = Utils::FilePath::fromString(target.fileName.first()).absolutePath();
@@ -237,7 +237,7 @@ void MesonProjectParser::update(const QFuture<MesonProjectParser::ParserData *>
m_rootNode = std::move(parserData->rootNode); m_rootNode = std::move(parserData->rootNode);
m_targetsNames.clear(); m_targetsNames.clear();
for (const Target &target : m_parserResult.targets) { for (const Target &target : m_parserResult.targets) {
m_targetsNames.push_back(Target::fullName(m_srcDir, target)); m_targetsNames.push_back(Target::fullName(m_buildDir, target));
} }
addMissingTargets(m_targetsNames); addMissingTargets(m_targetsNames);
m_targetsNames.sort(); m_targetsNames.sort();
@@ -253,7 +253,7 @@ ProjectExplorer::RawProjectPart MesonProjectParser::buildRawPart(
{ {
ProjectExplorer::RawProjectPart part; ProjectExplorer::RawProjectPart part;
part.setDisplayName(target.name); part.setDisplayName(target.name);
part.setBuildSystemTarget(Target::fullName(m_srcDir, target)); part.setBuildSystemTarget(Target::fullName(m_buildDir, 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);

View File

@@ -60,15 +60,17 @@ struct Target
const std::optional<QString> subproject; const std::optional<QString> subproject;
const SourceGroupList sources; const SourceGroupList sources;
static inline QString fullName(const Utils::FilePath &srcDir, const Target &target) static inline QString fullName(const Utils::FilePath &buildDir, const Target &target)
{ {
using namespace Utils; using namespace Utils;
if (FilePath::fromString((target.fileName.first())).isAbsolutePath()) { auto fname = target.fileName.first();
const auto fname = target.fileName.first().split('/').last(); if (FilePath::fromString(fname).isAbsolutePath()) {
QString definedIn = FilePath::fromString(target.definedIn).absolutePath().toString(); fname.remove(buildDir.toString());
return definedIn.remove(srcDir.toString()) + '/' + fname; if (fname.startsWith('/'))
fname.removeFirst();
return fname;
} else { } else {
return target.fileName.first(); return fname;
} }
} }