Commit d67a2267 authored by Daniel Teske's avatar Daniel Teske Committed by Tobias Hunger

Qt Version Dialog: Show a error message on failing to add a qt

Task-number: QTCREATORBUG-8351
Change-Id: I1355df2f54940258b8101cfb78230f667eaba439
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 34c79839
......@@ -865,8 +865,11 @@ void BaseQtVersion::updateVersionInfo() const
m_hasQmlDebuggingLibrary = false;
m_hasQmlObserver = false;
if (!queryQMakeVariables(qmakeCommand(), qmakeRunEnvironment(), &m_versionInfo, &m_qmakeIsExecutable))
if (!queryQMakeVariables(qmakeCommand(), qmakeRunEnvironment(), &m_versionInfo)) {
m_qmakeIsExecutable = false;
return;
}
m_qmakeIsExecutable = true;
const QString qtInstallData = qmakeProperty("QT_INSTALL_DATA");
const QString qtInstallBins = qmakeProperty("QT_INSTALL_BINS");
......@@ -1181,15 +1184,8 @@ QtConfigWidget *BaseQtVersion::createConfigurationWidget() const
return 0;
}
bool BaseQtVersion::queryQMakeVariables(const FileName &binary, const Utils::Environment &env,
QHash<QString, QString> *versionInfo)
{
bool qmakeIsExecutable;
return BaseQtVersion::queryQMakeVariables(binary, env, versionInfo, &qmakeIsExecutable);
}
static QByteArray runQmakeQuery(const FileName &binary, const Environment &env,
bool *isExecutable)
QString *error)
{
const int timeOutMS = 30000; // Might be slow on some machines.
......@@ -1198,38 +1194,41 @@ static QByteArray runQmakeQuery(const FileName &binary, const Environment &env,
process.start(binary.toString(), QStringList(QLatin1String("-query")), QIODevice::ReadOnly);
if (!process.waitForStarted()) {
qWarning("Cannot start '%s': %s", qPrintable(binary.toUserOutput()), qPrintable(process.errorString()));
*isExecutable = false;
if (error)
*error = QCoreApplication::translate("QtVersion", "Cannot start '%1': %2").arg(binary.toUserOutput()).arg(process.errorString());
return QByteArray();
}
if (!process.waitForFinished(timeOutMS)) {
SynchronousProcess::stopProcess(process);
*isExecutable = true;
qWarning("Timeout running '%s' (%dms).", qPrintable(binary.toUserOutput()), timeOutMS);
if (error)
*error = QCoreApplication::translate("QtVersion", "Timeout running '%1' (%2ms).").arg(binary.toUserOutput()).arg(timeOutMS);
return QByteArray();
}
if (process.exitStatus() != QProcess::NormalExit) {
qWarning("'%s' crashed.", qPrintable(binary.toUserOutput()));
*isExecutable = false;
if (error)
*error = QCoreApplication::translate("QtVersion", "'%s' crashed.").arg(binary.toUserOutput());
return QByteArray();
}
*isExecutable = true;
if (error)
error->clear();
return process.readAllStandardOutput();
}
bool BaseQtVersion::queryQMakeVariables(const FileName &binary, const Environment &env,
QHash<QString, QString> *versionInfo, bool *qmakeIsExecutable)
QHash<QString, QString> *versionInfo, QString *error)
{
const QFileInfo qmake = binary.toFileInfo();
*qmakeIsExecutable = qmake.exists() && qmake.isExecutable() && !qmake.isDir();
if (!*qmakeIsExecutable)
if (!qmake.exists() || !qmake.isExecutable() || qmake.isDir()) {
if (error)
*error = QCoreApplication::translate("QtVersion", "qmake '%1' is not a executable").arg(binary.toUserOutput());
return false;
}
QByteArray output;
output = runQmakeQuery(binary, env, qmakeIsExecutable);
output = runQmakeQuery(binary, env, error);
if (output.isNull() && !*qmakeIsExecutable) {
if (output.isNull() && !error->isEmpty()) {
// Note: Don't rerun if we were able to execute the binary before.
// Try running qmake with all kinds of tool chains set up in the environment.
......@@ -1242,8 +1241,8 @@ bool BaseQtVersion::queryQMakeVariables(const FileName &binary, const Environmen
continue;
Environment realEnv = env;
tc->addToEnvironment(realEnv);
output = runQmakeQuery(binary, realEnv, qmakeIsExecutable);
if (*qmakeIsExecutable)
output = runQmakeQuery(binary, realEnv, error);
if (error->isEmpty())
break;
}
}
......
......@@ -187,10 +187,7 @@ public:
QList<ProjectExplorer::Task> reportIssues(const QString &proFile, const QString &buildDir) const;
static bool queryQMakeVariables(const Utils::FileName &binary, const Utils::Environment &env,
QHash<QString, QString> *versionInfo);
static bool queryQMakeVariables(const Utils::FileName &binary, const Utils::Environment &env,
QHash<QString, QString> *versionInfo,
bool *qmakeIsExecutable);
QHash<QString, QString> *versionInfo, QString *error = 0);
static Utils::FileName mkspecDirectoryFromVersionInfo(const QHash<QString, QString> &versionInfo);
static Utils::FileName mkspecFromVersionInfo(const QHash<QString, QString> &versionInfo);
......
......@@ -656,7 +656,8 @@ void QtOptionsPageWidget::addQtDir()
return;
}
version = QtVersionFactory::createQtVersionFromQMakePath(qtVersion);
QString error;
version = QtVersionFactory::createQtVersionFromQMakePath(qtVersion, false, QString(), &error);
if (version) {
m_versions.append(version);
......@@ -669,6 +670,10 @@ void QtOptionsPageWidget::addQtDir()
m_ui->qtdirList->setCurrentItem(item); // should update the rest of the ui
m_versionUi->nameEdit->setFocus();
m_versionUi->nameEdit->selectAll();
} else {
QMessageBox::warning(this, tr("Qmake not executable"),
tr("The qmake %1 could not be added: %2").arg(qtVersion.toUserOutput()).arg(error));
return;
}
updateCleanUpButton();
}
......
......@@ -56,12 +56,11 @@ bool sortByPriority(QtVersionFactory *a, QtVersionFactory *b)
return a->priority() > b->priority();
}
BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FileName &qmakePath, bool isAutoDetected, const QString &autoDetectionSource)
BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FileName &qmakePath, bool isAutoDetected, const QString &autoDetectionSource, QString *error)
{
QHash<QString, QString> versionInfo;
Utils::Environment env = Utils::Environment::systemEnvironment();
bool success = BaseQtVersion::queryQMakeVariables(qmakePath, env, &versionInfo);
if (!success)
if (!BaseQtVersion::queryQMakeVariables(qmakePath, env, &versionInfo, error))
return 0;
Utils::FileName mkspec = BaseQtVersion::mkspecFromVersionInfo(versionInfo);
......@@ -84,5 +83,7 @@ BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FileN
}
}
ProFileCacheManager::instance()->decRefCount();
if (error)
*error = tr("No factory found for qmake: '%1'").arg(qmakePath.toUserOutput());
return 0;
}
......@@ -62,7 +62,7 @@ public:
virtual int priority() const = 0;
virtual BaseQtVersion *create(const Utils::FileName &qmakePath, ProFileEvaluator *evaluator, bool isAutoDetected = false, const QString &autoDetectionSource = QString()) = 0;
static BaseQtVersion *createQtVersionFromQMakePath(const Utils::FileName &qmakePath, bool isAutoDetected = false, const QString &autoDetectionSource = QString());
static BaseQtVersion *createQtVersionFromQMakePath(const Utils::FileName &qmakePath, bool isAutoDetected = false, const QString &autoDetectionSource = QString(), QString *error = 0);
};
} // namespace QtSupport
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment