CMake: Collect also remote filenames from generateBuildTargets()

QDir::cleanPath(...) doesn't do the right thing on stringified
Utils::FilePaths. Use FilePath functions instead.

Change-Id: Ied66f38dd30a15694bce12ed57d37411bb87f680
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-06-09 17:05:50 +02:00
parent 0e6a4e757c
commit e35235ea72
3 changed files with 16 additions and 13 deletions

View File

@@ -997,6 +997,13 @@ FilePath FilePath::absoluteFilePath() const
return result; return result;
} }
FilePath FilePath::absoluteFilePath(const FilePath &tail) const
{
if (FileUtils::isRelativePath(tail.m_data))
return pathAppended(tail.m_data);
return tail;
}
/// Constructs an absolute FilePath from this path which /// Constructs an absolute FilePath from this path which
/// is interpreted as being relative to \a anchor. /// is interpreted as being relative to \a anchor.
FilePath FilePath::absoluteFromRelativePath(const FilePath &anchor) const FilePath FilePath::absoluteFromRelativePath(const FilePath &anchor) const

View File

@@ -137,6 +137,7 @@ public:
FilePath parentDir() const; FilePath parentDir() const;
FilePath absolutePath() const; FilePath absolutePath() const;
FilePath absoluteFilePath() const; FilePath absoluteFilePath() const;
FilePath absoluteFilePath(const FilePath &tail) const;
FilePath absoluteFromRelativePath(const FilePath &anchor) const; FilePath absoluteFromRelativePath(const FilePath &anchor) const;
bool operator==(const FilePath &other) const; bool operator==(const FilePath &other) const;

View File

@@ -192,18 +192,15 @@ QList<CMakeBuildTarget> generateBuildTargets(const PreprocessedData &input,
const FilePath &buildDirectory) const FilePath &buildDirectory)
{ {
QDir sourceDir(sourceDirectory.toString()); QDir sourceDir(sourceDirectory.toString());
QDir buildDir(buildDirectory.toString());
const QList<CMakeBuildTarget> result = transform<QList>( const QList<CMakeBuildTarget> result = transform<QList>(input.targetDetails,
input.targetDetails, [&sourceDir, &buildDir](const TargetDetails &t) -> CMakeBuildTarget { [&sourceDir, &sourceDirectory, &buildDirectory](const TargetDetails &t) {
const auto currentBuildDir = QDir(buildDir.absoluteFilePath(t.buildDir.toString())); const FilePath currentBuildDir = buildDirectory.absoluteFilePath(t.buildDir);
CMakeBuildTarget ct; CMakeBuildTarget ct;
ct.title = t.name; ct.title = t.name;
ct.executable = t.artifacts.isEmpty() if (!t.artifacts.isEmpty())
? FilePath() ct.executable = buildDirectory.absoluteFilePath(t.artifacts.at(0));
: FilePath::fromString(QDir::cleanPath(
buildDir.absoluteFilePath(t.artifacts.at(0).toString())));
TargetType type = UtilityType; TargetType type = UtilityType;
if (t.type == "EXECUTABLE") if (t.type == "EXECUTABLE")
type = ExecutableType; type = ExecutableType;
@@ -217,10 +214,9 @@ QList<CMakeBuildTarget> generateBuildTargets(const PreprocessedData &input,
type = UtilityType; type = UtilityType;
ct.targetType = type; ct.targetType = type;
ct.workingDirectory = ct.executable.isEmpty() ct.workingDirectory = ct.executable.isEmpty()
? FilePath::fromString(currentBuildDir.absolutePath()) ? currentBuildDir.absolutePath()
: ct.executable.parentDir(); : ct.executable.parentDir();
ct.sourceDirectory = FilePath::fromString( ct.sourceDirectory = sourceDirectory.absoluteFilePath(t.sourceDir);
QDir::cleanPath(sourceDir.absoluteFilePath(t.sourceDir.toString())));
ct.backtrace = extractBacktraceInformation(t.backtraceGraph, sourceDir, t.backtrace, 0); ct.backtrace = extractBacktraceInformation(t.backtraceGraph, sourceDir, t.backtrace, 0);
@@ -271,8 +267,7 @@ QList<CMakeBuildTarget> generateBuildTargets(const PreprocessedData &input,
if (part.startsWith("-")) if (part.startsWith("-"))
continue; continue;
FilePath tmp = FilePath::fromString( FilePath tmp = currentBuildDir.absoluteFilePath(FilePath::fromUserInput(part));
currentBuildDir.absoluteFilePath(QDir::fromNativeSeparators(part)));
if (f.role == "libraries") if (f.role == "libraries")
tmp = tmp.parentDir(); tmp = tmp.parentDir();