QtSupport: Add support to register Qt versions via qtpaths

qmake is a "build tool", and it is also a "query tool" when called with
parameter "-query". Qt Creator, so far, assumes that building and
querying with a Qt installation are done with one and the same tool:
qmake. This change adds the ability to register a Qt version vie either
qmake or qtpaths and still build with qmake, if that is installed (which
is not anymore mandatory from Qt 6 on).

1) Distinguish between Qt query tool and qmake build tool:
Add QtVersion::queryToolFilePath() to the existing
QtVersion::qmakeFilePath(), and use queryToolFilePath in most "query"
related code, and qmakeFilePath when building with qmake (e.g. in
QmakeProjectManager).
Also, a couple of functions and variables were renamed from *qmake* to
*queryTool* in order to express that the affected code is about
querying/managing Qt versions rather than about building with qmake.

2) Support manual Qt Version adding by qtpaths via file dialog
This change adds qtpaths to the "Add" Qt Version file picker filter.
After selection, "qtpaths -query" is executed for testing purposes. If
that fails, (e.g. because it is an older Qt version), qmake is instead
chosen, silently.

Task-number: QTCREATORBUG-22175
Task-number: QTCREATORBUG-25546
Change-Id: I4d9c1e7eec7d5ae7c5a8d2e1a1ed95addff69966
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Alessandro Portale
2022-05-11 13:26:57 +02:00
parent 79236605fd
commit 72aa77ced7
28 changed files with 338 additions and 267 deletions

View File

@@ -265,7 +265,8 @@ void QtVersionManager::updateFromInstaller(bool emitSignal)
if (log().isDebugEnabled()) {
qCDebug(log) << "======= Existing Qt versions =======";
for (QtVersion *version : qAsConst(m_versions)) {
qCDebug(log) << version->qmakeFilePath().toUserOutput() << "id:"<<version->uniqueId();
qCDebug(log) << version->queryToolFilePath().toUserOutput()
<< "id:" <<version->uniqueId();
qCDebug(log) << " autodetection source:" << version->detectionSource();
qCDebug(log) << "";
}
@@ -341,7 +342,8 @@ void QtVersionManager::updateFromInstaller(bool emitSignal)
if (log().isDebugEnabled()) {
qCDebug(log) << "======= Before removing outdated sdk versions =======";
for (QtVersion *version : qAsConst(m_versions)) {
qCDebug(log) << version->qmakeFilePath().toUserOutput() << "id:" << version->uniqueId();
qCDebug(log) << version->queryToolFilePath().toUserOutput()
<< "id:" << version->uniqueId();
qCDebug(log) << " autodetection source:" << version->detectionSource();
qCDebug(log) << "";
}
@@ -360,7 +362,8 @@ void QtVersionManager::updateFromInstaller(bool emitSignal)
if (log().isDebugEnabled()) {
qCDebug(log)<< "======= End result =======";
for (QtVersion *version : qAsConst(m_versions)) {
qCDebug(log) << version->qmakeFilePath().toUserOutput() << "id:" << version->uniqueId();
qCDebug(log) << version->queryToolFilePath().toUserOutput()
<< "id:" << version->uniqueId();
qCDebug(log) << " autodetection source:" << version->detectionSource();
qCDebug(log) << "";
}
@@ -401,14 +404,20 @@ static QList<QByteArray> runQtChooser(const QString &qtchooser, const QStringLis
}
// Asks qtchooser for the qmake path of a given version
// TODO: Extend to qtpaths if qtchooser is also used for Qt 6
static QString qmakePath(const QString &qtchooser, const QString &version)
{
const QList<QByteArray> outputs = runQtChooser(qtchooser,
{QStringLiteral("-qt=%1").arg(version),
QStringLiteral("-print-env")});
// Exemplary output of "qtchooser -qt=qt5-x86_64-linux-gnu -print-env":
// QT_SELECT="qt5-x86_64-linux-gnu"
// QTTOOLDIR="/usr/lib/qt5/bin"
// QTLIBDIR="/usr/lib/x86_64-linux-gnu"
const QByteArray qtToolDirPrefix("QTTOOLDIR=\"");
for (const QByteArray &output : outputs) {
if (output.startsWith("QTTOOLDIR=\"")) {
QByteArray withoutVarName = output.mid(11); // remove QTTOOLDIR="
if (output.startsWith(qtToolDirPrefix)) {
QByteArray withoutVarName = output.mid(qtToolDirPrefix.size()); // remove QTTOOLDIR="
withoutVarName.chop(1); // remove trailing quote
return QStandardPaths::findExecutable(QStringLiteral("qmake"), QStringList()
<< QString::fromLocal8Bit(withoutVarName));
@@ -424,6 +433,15 @@ static FilePaths gatherQmakePathsFromQtChooser()
return FilePaths();
const QList<QByteArray> versions = runQtChooser(qtchooser, QStringList("-l"));
// Exemplary output of "qtchooser -l":
// 4
// 5
// default
// qt4-x86_64-linux-gnu
// qt4
// qt5-x86_64-linux-gnu
// qt5
// ""
QSet<FilePath> foundQMakes;
for (const QByteArray &version : versions) {
FilePath possibleQMake = FilePath::fromString(
@@ -436,19 +454,20 @@ static FilePaths gatherQmakePathsFromQtChooser()
static void findSystemQt()
{
FilePaths systemQMakes
FilePaths systemQueryTools
= BuildableHelperLibrary::findQtsInEnvironment(Environment::systemEnvironment());
systemQMakes.append(gatherQmakePathsFromQtChooser());
for (const FilePath &qmakePath : qAsConst(systemQMakes)) {
if (BuildableHelperLibrary::isQtChooser(qmakePath))
systemQueryTools.append(gatherQmakePathsFromQtChooser());
for (const FilePath &queryToolPath : qAsConst(systemQueryTools)) {
if (BuildableHelperLibrary::isQtChooser(queryToolPath))
continue;
const auto isSameQmake = [qmakePath](const QtVersion *version) {
const auto isSameQueryTool = [queryToolPath](const QtVersion *version) {
return Environment::systemEnvironment().
isSameExecutable(qmakePath.toString(), version->qmakeFilePath().toString());
isSameExecutable(queryToolPath.toString(),
version->queryToolFilePath().toString());
};
if (contains(m_versions, isSameQmake))
if (contains(m_versions, isSameQueryTool))
continue;
QtVersion *version = QtVersionFactory::createQtVersionFromQMakePath(qmakePath,
QtVersion *version = QtVersionFactory::createQtVersionFromQueryToolPath(queryToolPath,
false,
"PATH");
if (version)