forked from qt-creator/qt-creator
QtOutputFormatter: Support relative file:// links
QUrl does not have good support for relative file paths, and it seems there is little interest to change it: QTBUG-44921 Work around this by constructing the QUrl again on failure with fromLocalFile(). In this case, the "file://" scheme has to be omitted. This issue was detected because some compilers generate paths with native Windows separators, like "..\main.cpp" for the __FILE__ macro. Debugging the issue showed, that rather the relative path was the problem, as the QUrl constructor does not support it. Change-Id: I30074a3d11f9f43e05cd202f6d86c752ce184785 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
committed by
André Hartmann
parent
881f4d5f38
commit
89dda94dca
@@ -239,7 +239,11 @@ void QtOutputFormatter::handleLink(const QString &href)
|
|||||||
const QRegularExpressionMatch qmlLineMatch = qmlLineLink.match(href);
|
const QRegularExpressionMatch qmlLineMatch = qmlLineLink.match(href);
|
||||||
|
|
||||||
if (qmlLineMatch.hasMatch()) {
|
if (qmlLineMatch.hasMatch()) {
|
||||||
const QUrl fileUrl = QUrl(qmlLineMatch.captured(1));
|
const char scheme[] = "file://";
|
||||||
|
const QString filePath = qmlLineMatch.captured(1);
|
||||||
|
QUrl fileUrl = QUrl(filePath);
|
||||||
|
if (!fileUrl.isValid() && filePath.startsWith(scheme))
|
||||||
|
fileUrl = QUrl::fromLocalFile(filePath.mid(strlen(scheme)));
|
||||||
const int line = qmlLineMatch.captured(2).toInt();
|
const int line = qmlLineMatch.captured(2).toInt();
|
||||||
openEditor(getFileToOpen(fileUrl), line);
|
openEditor(getFileToOpen(fileUrl), line);
|
||||||
return;
|
return;
|
||||||
@@ -415,15 +419,27 @@ void QtSupportPlugin::testQtOutputFormatter_data()
|
|||||||
<< " Loc: [../TestProject/test.cpp(123)]"
|
<< " Loc: [../TestProject/test.cpp(123)]"
|
||||||
<< 9 << 37 << "../TestProject/test.cpp(123)"
|
<< 9 << 37 << "../TestProject/test.cpp(123)"
|
||||||
<< "../TestProject/test.cpp" << 123 << -1;
|
<< "../TestProject/test.cpp" << 123 << -1;
|
||||||
|
|
||||||
|
QTest::newRow("Unix relative file link")
|
||||||
|
<< "file://../main.cpp:157"
|
||||||
|
<< 0 << 22 << "file://../main.cpp:157"
|
||||||
|
<< "../main.cpp" << 157 << -1;
|
||||||
|
|
||||||
if (HostOsInfo::isWindowsHost()) {
|
if (HostOsInfo::isWindowsHost()) {
|
||||||
QTest::newRow("Windows failed QTest link")
|
QTest::newRow("Windows failed QTest link")
|
||||||
<< "..\\TestProject\\test.cpp(123) : failure location"
|
<< "..\\TestProject\\test.cpp(123) : failure location"
|
||||||
<< 0 << 28 << "..\\TestProject\\test.cpp(123)"
|
<< 0 << 28 << "..\\TestProject\\test.cpp(123)"
|
||||||
<< "../TestProject/test.cpp" << 123 << -1;
|
<< "../TestProject/test.cpp" << 123 << -1;
|
||||||
|
|
||||||
QTest::newRow("Windows failed QTest link with carriage return")
|
QTest::newRow("Windows failed QTest link with carriage return")
|
||||||
<< "..\\TestProject\\test.cpp(123) : failure location\r"
|
<< "..\\TestProject\\test.cpp(123) : failure location\r"
|
||||||
<< 0 << 28 << "..\\TestProject\\test.cpp(123)"
|
<< 0 << 28 << "..\\TestProject\\test.cpp(123)"
|
||||||
<< "../TestProject/test.cpp" << 123 << -1;
|
<< "../TestProject/test.cpp" << 123 << -1;
|
||||||
|
|
||||||
|
QTest::newRow("Windows relative file link with native separator")
|
||||||
|
<< "file://..\\main.cpp:157"
|
||||||
|
<< 0 << 22 << "file://..\\main.cpp:157"
|
||||||
|
<< "../main.cpp" << 157 << -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user