summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2018-03-02 12:30:44 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2018-05-04 08:47:18 +0000
commit5a79a9ea41ab1223edc39b6c594a682cb079dd18 (patch)
treec94db5fbb07fc0550fe3eed998ed54f5542569c6
parent554e44b77de8df75cfa7b9a4dc81a795509e7de9 (diff)
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 commit 58b373c9e3c0a7307e3fbafeb5ad710088b8e685)
-rw-r--r--qmake/doc/src/qmake-manual.qdoc15
-rw-r--r--qmake/library/ioutils.cpp2
-rw-r--r--qmake/library/qmakebuiltins.cpp8
-rw-r--r--tests/auto/tools/qmakelib/evaltest.cpp16
4 files changed, 32 insertions, 9 deletions
diff --git a/qmake/doc/src/qmake-manual.qdoc b/qmake/doc/src/qmake-manual.qdoc
index 75a93fd996..7208563d15 100644
--- a/qmake/doc/src/qmake-manual.qdoc
+++ b/qmake/doc/src/qmake-manual.qdoc
@@ -2833,7 +2833,8 @@
Returns the absolute path of \c path.
If \c base is not specified, uses the current directory as the base
- directory.
+ directory. If it is a relative path, it is resolved relative to the current
+ directory before use.
For example, the following call returns the string
\c {"/home/johndoe/myproject/readme.txt"}:
@@ -3072,9 +3073,15 @@
\section2 relative_path(filePath[, base])
- Returns the path to \c filePath relative to \c base. If \c base is not
- specified, it is the current project directory. This function is a wrapper
- around QDir::relativeFilePath.
+ Returns the path to \c filePath relative to \c base.
+
+ If \c base is not specified, it is the current project
+ directory. If it is relative, it is resolved relative to the
+ current project directory before use.
+
+ If \c filePath is relative, it is first resolved against the base
+ directory; in that case, this function effectively acts as
+ $$clean_path().
See also \l{absolute_path(path[, base])}{absolute_path()},
\l{clean_path(path)}{clean_path()}.
diff --git a/qmake/library/ioutils.cpp b/qmake/library/ioutils.cpp
index afd41912fe..cb4aa5e74d 100644
--- a/qmake/library/ioutils.cpp
+++ b/qmake/library/ioutils.cpp
@@ -103,7 +103,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/qmake/library/qmakebuiltins.cpp b/qmake/library/qmakebuiltins.cpp
index e4b00a6cb3..c1726aaa28 100644
--- a/qmake/library/qmakebuiltins.cpp
+++ b/qmake/library/qmakebuiltins.cpp
@@ -1174,7 +1174,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)
@@ -1188,7 +1190,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)));
diff --git a/tests/auto/tools/qmakelib/evaltest.cpp b/tests/auto/tools/qmakelib/evaltest.cpp
index cf69cc4026..a057c7e15a 100644
--- a/tests/auto/tools/qmakelib/evaltest.cpp
+++ b/tests/auto/tools/qmakelib/evaltest.cpp
@@ -1604,6 +1604,12 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir)
<< ""
<< true;
+ QTest::newRow("$$absolute_path(): relative file & relative path")
+ << "VAR = $$absolute_path(dir/file.ext, some/where)"
+ << "VAR = " + qindir + "/some/where/dir/file.ext"
+ << ""
+ << true;
+
QTest::newRow("$$absolute_path(): file & path")
<< "VAR = $$absolute_path(dir/file.ext, " EVAL_DRIVE "/root/sub)"
<< "VAR = " EVAL_DRIVE "/root/sub/dir/file.ext"
@@ -1642,6 +1648,12 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir)
<< ""
<< true;
+ QTest::newRow("$$relative_path(): relative file & relative path")
+ << "VAR = $$relative_path(dir/file.ext, some/where)"
+ << "VAR = dir/file.ext"
+ << ""
+ << true;
+
QTest::newRow("$$relative_path(): relative file to empty")
<< "VAR = $$relative_path(dir/..)"
<< "VAR = ."
@@ -2714,9 +2726,9 @@ void tst_qmakelib::proEval_data()
// Raw data leak with empty file name. Verify with Valgrind or asan.
QTest::newRow("QTBUG-54550")
- << "FULL = /there/is\n"
+ << "FULL = " EVAL_DRIVE "/there/is\n"
"VAR = $$absolute_path(, $$FULL/nothing/here/really)"
- << "VAR = /there/is/nothing/here/really"
+ << "VAR = " EVAL_DRIVE "/there/is/nothing/here/really"
<< ""
<< true;
}