QLibraryInfo: Consider resource paths as absolute
This is what QDir::isRelativePath() does, for better or worse. We've used QDir::isRelativePath() before and we shouldn't change the behavior. Amends commit c74cba1117355a6312b1f0cc815efa4cdea4bbfa Pick-to: 6.8 Change-Id: I03e3e921977af2b9c6ff2593535d846d6ce28fe2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit dd2dc8c70d0227ff235a8c7feaca7d7c4ead9c63) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
b6d2f86695
commit
3fd08e19d4
@ -601,10 +601,24 @@ static QVariant libraryPathToValue(QLibraryInfo::LibraryPath loc)
|
||||
}
|
||||
#endif // settings
|
||||
|
||||
// TODO: There apparently are paths that are both absolute and relative for QFileSystemEntry.
|
||||
// In particular on windows.
|
||||
|
||||
static bool pathIsRelative(const QString &path)
|
||||
{
|
||||
using FromInternalPath = QFileSystemEntry::FromInternalPath;
|
||||
return !path.startsWith(':'_L1) && QFileSystemEntry(path, FromInternalPath{}).isRelative();
|
||||
}
|
||||
|
||||
static bool pathIsAbsolute(const QString &path)
|
||||
{
|
||||
using FromInternalPath = QFileSystemEntry::FromInternalPath;
|
||||
return path.startsWith(':'_L1) || QFileSystemEntry(path, FromInternalPath{}).isAbsolute();
|
||||
}
|
||||
|
||||
QStringList QLibraryInfoPrivate::paths(QLibraryInfo::LibraryPath p,
|
||||
UsageMode usageMode)
|
||||
{
|
||||
using FromInternalPath = QFileSystemEntry::FromInternalPath;
|
||||
const QLibraryInfo::LibraryPath loc = p;
|
||||
QList<QString> ret;
|
||||
bool fromConf = false;
|
||||
@ -621,8 +635,7 @@ QStringList QLibraryInfoPrivate::paths(QLibraryInfo::LibraryPath p,
|
||||
ret = QList<QString>({ std::move(value).toString()});
|
||||
for (qsizetype i = 0, end = ret.size(); i < end; ++i) {
|
||||
ret[i] = normalizePath(ret[i]);
|
||||
pathsAreAbsolute = pathsAreAbsolute
|
||||
&& QFileSystemEntry(ret[i], FromInternalPath{}).isAbsolute();
|
||||
pathsAreAbsolute = pathsAreAbsolute && pathIsAbsolute(ret[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -645,8 +658,7 @@ QStringList QLibraryInfoPrivate::paths(QLibraryInfo::LibraryPath p,
|
||||
#endif
|
||||
}
|
||||
if (!noConfResult.isEmpty()) {
|
||||
pathsAreAbsolute = pathsAreAbsolute
|
||||
&& QFileSystemEntry(noConfResult, FromInternalPath{}).isAbsolute();
|
||||
pathsAreAbsolute = pathsAreAbsolute && pathIsAbsolute(noConfResult);
|
||||
ret.push_back(std::move(noConfResult));
|
||||
}
|
||||
}
|
||||
@ -661,7 +673,7 @@ QStringList QLibraryInfoPrivate::paths(QLibraryInfo::LibraryPath p,
|
||||
baseDir = QLibraryInfoPrivate::path(QLibraryInfo::PrefixPath, usageMode);
|
||||
}
|
||||
for (qsizetype i = 0, end = ret.size(); i < end; ++i)
|
||||
if (QFileSystemEntry(ret[i], FromInternalPath{}).isRelative())
|
||||
if (pathIsRelative(ret[i]))
|
||||
ret[i] = QDir::cleanPath(baseDir + u'/' + std::move(ret[i]));
|
||||
return ret;
|
||||
}
|
||||
|
@ -1,2 +1,3 @@
|
||||
[Paths]
|
||||
Documentation = "/path/to/mydoc","/path/to/anotherdoc","relativePath"
|
||||
QmlImports = ":/a/resource/path", ":a/broken/path", "a/relative/path"
|
||||
|
@ -79,6 +79,12 @@ void tst_QLibraryInfo::paths()
|
||||
QCOMPARE(values[1], "/path/to/anotherdoc");
|
||||
QString baseDir = QCoreApplication::applicationDirPath();
|
||||
QCOMPARE(values[2], baseDir + "/relativePath");
|
||||
|
||||
const QStringList qmlImportPaths = QLibraryInfo::paths(QLibraryInfo::QmlImportsPath);
|
||||
const QStringList expected = {
|
||||
":/a/resource/path", ":a/broken/path", baseDir + "/a/relative/path"
|
||||
};
|
||||
QCOMPARE(qmlImportPaths, expected);
|
||||
}
|
||||
|
||||
void tst_QLibraryInfo::merge()
|
||||
|
Loading…
x
Reference in New Issue
Block a user