diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2018-03-02 12:30:44 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2018-09-14 13:50:07 +0000 |
commit | f2cd5788c83f42a14353ca4e38352f4a996d91b5 (patch) | |
tree | a04d00763b474e642011a7519d7def4a1cbfddab | |
parent | 5d07aae8dcc57954ebe99feef35a95580c405657 (diff) | |
download | qttools-f2cd5788c83f42a14353ca4e38352f4a996d91b5.tar.gz |
Make sure $$relative_path() uses an absolute path as its first arg
Thanks to QTBUG-61373, this qmake function was called with
/usr/local/5.10.1 as baseDir, which isn't absolute, leading to an
assertion failure. We could raise the error within qmake but it
proved easier to simply resolve any non-absolute baseDir using PWD,
before trying to use it as an absolute path.
Did the same for $$absolute_path(). Documented both. Adjusted the
assert that caught this to report any non-absolute path that upsets
it. Added simple tests, fixed an existing test.
Task-number: QTBUG-66156
Change-Id: Icfef2e2f5b236e071177c9beffa38d71bf404292
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
(cherry picked from qtbase/58b373c9e3c0a7307e3fbafeb5ad710088b8e685)
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r-- | src/linguist/shared/ioutils.cpp | 2 | ||||
-rw-r--r-- | src/linguist/shared/qmakebuiltins.cpp | 8 |
2 files changed, 7 insertions, 3 deletions
diff --git a/src/linguist/shared/ioutils.cpp b/src/linguist/shared/ioutils.cpp index 4de87fd3d..733f4a6bd 100644 --- a/src/linguist/shared/ioutils.cpp +++ b/src/linguist/shared/ioutils.cpp @@ -104,7 +104,7 @@ QString IoUtils::resolvePath(const QString &baseDir, const QString &fileName) return QDir::cleanPath(fileName); #ifdef Q_OS_WIN // Add drive to otherwise-absolute path: if (fileName.at(0).unicode() == '/' || fileName.at(0).unicode() == '\\') { - Q_ASSERT(isAbsolutePath(baseDir)); + Q_ASSERT_X(isAbsolutePath(baseDir), "IoUtils::resolvePath", qUtf8Printable(baseDir)); return QDir::cleanPath(baseDir.left(2) + fileName); } #endif // Q_OS_WIN diff --git a/src/linguist/shared/qmakebuiltins.cpp b/src/linguist/shared/qmakebuiltins.cpp index 55b15c66b..e1af8878a 100644 --- a/src/linguist/shared/qmakebuiltins.cpp +++ b/src/linguist/shared/qmakebuiltins.cpp @@ -1178,7 +1178,9 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand( evalError(fL1S("absolute_path(path[, base]) requires one or two arguments.")); } else { QString arg = args.at(0).toQString(m_tmp1); - QString baseDir = args.count() > 1 ? args.at(1).toQString(m_tmp2) : currentDirectory(); + QString baseDir = args.count() > 1 + ? IoUtils::resolvePath(currentDirectory(), args.at(1).toQString(m_tmp2)) + : currentDirectory(); QString rstr = arg.isEmpty() ? baseDir : IoUtils::resolvePath(baseDir, arg); ret << (rstr.isSharedWith(m_tmp1) ? args.at(0) @@ -1192,7 +1194,9 @@ QMakeEvaluator::VisitReturn QMakeEvaluator::evaluateBuiltinExpand( evalError(fL1S("relative_path(path[, base]) requires one or two arguments.")); } else { QString arg = args.at(0).toQString(m_tmp1); - QString baseDir = args.count() > 1 ? args.at(1).toQString(m_tmp2) : currentDirectory(); + QString baseDir = args.count() > 1 + ? IoUtils::resolvePath(currentDirectory(), args.at(1).toQString(m_tmp2)) + : currentDirectory(); QString absArg = arg.isEmpty() ? baseDir : IoUtils::resolvePath(baseDir, arg); QString rstr = QDir(baseDir).relativeFilePath(absArg); ret << (rstr.isSharedWith(m_tmp1) ? args.at(0) : ProString(rstr).setSource(args.at(0))); |