forked from qt-creator/qt-creator
Gather Qt versions from qtchooser on first run
Change-Id: I33ae062c3225fb3d7b7d1a62e0e287d326bb4276 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Adam Majer <adamm@zombino.com> Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
7bc1af275d
commit
7b0c8b160a
@@ -54,6 +54,7 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QStandardPaths>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@@ -397,17 +398,67 @@ static void saveQtVersions()
|
|||||||
m_writer->save(data, Core::ICore::mainWindow());
|
m_writer->save(data, Core::ICore::mainWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Executes qtchooser with arguments in a process and returns its output
|
||||||
|
static QList<QByteArray> runQtChooser(const QString &qtchooser, const QStringList &arguments)
|
||||||
|
{
|
||||||
|
QProcess p;
|
||||||
|
p.start(qtchooser, arguments);
|
||||||
|
p.waitForFinished();
|
||||||
|
const bool success = p.exitCode() == 0;
|
||||||
|
return success ? p.readAllStandardOutput().split('\n') : QList<QByteArray>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asks qtchooser for the qmake path of a given version
|
||||||
|
static QString qmakePath(const QString &qtchooser, const QString &version)
|
||||||
|
{
|
||||||
|
QList<QByteArray> outputs = runQtChooser(qtchooser, QStringList()
|
||||||
|
<< QStringLiteral("-qt=%1").arg(version)
|
||||||
|
<< QStringLiteral("-print-env"));
|
||||||
|
foreach (const QByteArray &output, outputs) {
|
||||||
|
if (output.startsWith("QTTOOLDIR=\"")) {
|
||||||
|
QByteArray withoutVarName = output.mid(11); // remove QTTOOLDIR="
|
||||||
|
withoutVarName.chop(1); // remove trailing quote
|
||||||
|
return QStandardPaths::findExecutable(QStringLiteral("qmake"), QStringList()
|
||||||
|
<< QString::fromLocal8Bit(withoutVarName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
static FileNameList gatherQmakePathsFromQtChooser()
|
||||||
|
{
|
||||||
|
const QString qtchooser = QStandardPaths::findExecutable(QStringLiteral("qtchooser"));
|
||||||
|
if (qtchooser.isEmpty())
|
||||||
|
return FileNameList();
|
||||||
|
|
||||||
|
QList<QByteArray> versions = runQtChooser(qtchooser, QStringList() << QStringLiteral("-l"));
|
||||||
|
QSet<FileName> foundQMakes;
|
||||||
|
foreach (const QByteArray &version, versions) {
|
||||||
|
FileName possibleQMake = FileName::fromString(
|
||||||
|
qmakePath(qtchooser, QString::fromLocal8Bit(version)));
|
||||||
|
if (!possibleQMake.isEmpty())
|
||||||
|
foundQMakes << possibleQMake;
|
||||||
|
}
|
||||||
|
return foundQMakes.toList();
|
||||||
|
}
|
||||||
|
|
||||||
static void findSystemQt()
|
static void findSystemQt()
|
||||||
{
|
{
|
||||||
|
FileNameList systemQMakes;
|
||||||
FileName systemQMakePath = BuildableHelperLibrary::findSystemQt(Environment::systemEnvironment());
|
FileName systemQMakePath = BuildableHelperLibrary::findSystemQt(Environment::systemEnvironment());
|
||||||
if (systemQMakePath.isNull())
|
if (!systemQMakePath.isEmpty())
|
||||||
return;
|
systemQMakes << systemQMakePath;
|
||||||
|
|
||||||
BaseQtVersion *version
|
systemQMakes.append(gatherQmakePathsFromQtChooser());
|
||||||
= QtVersionFactory::createQtVersionFromQMakePath(systemQMakePath, false, QLatin1String("PATH"));
|
systemQMakes.removeDuplicates();
|
||||||
if (version) {
|
|
||||||
version->setUnexpandedDisplayName(BaseQtVersion::defaultUnexpandedDisplayName(systemQMakePath, true));
|
foreach (const FileName &qmakePath, systemQMakes) {
|
||||||
m_versions.insert(version->uniqueId(), version);
|
BaseQtVersion *version
|
||||||
|
= QtVersionFactory::createQtVersionFromQMakePath(qmakePath, false, QLatin1String("PATH"));
|
||||||
|
if (version) {
|
||||||
|
version->setUnexpandedDisplayName(BaseQtVersion::defaultUnexpandedDisplayName(qmakePath, true));
|
||||||
|
m_versions.insert(version->uniqueId(), version);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user