Commit 5bd251e8 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Win: Do fail less often when adding mingw Qt versions



Task-number: QTCREATORBUG-8225

Change-Id: I7b5db59ef7967a074e07ae87deff90235190aaa9
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@digia.com>
parent 4930fbcc
......@@ -1185,49 +1185,69 @@ bool BaseQtVersion::queryQMakeVariables(const Utils::FileName &binary, QHash<QSt
return BaseQtVersion::queryQMakeVariables(binary, versionInfo, &qmakeIsExecutable);
}
bool BaseQtVersion::queryQMakeVariables(const Utils::FileName &binary, QHash<QString, QString> *versionInfo,
bool *qmakeIsExecutable)
static QByteArray runQmakeQuery(const Utils::FileName &binary, const Utils::Environment &env,
bool *isExecutable)
{
const int timeOutMS = 30000; // Might be slow on some machines.
const QFileInfo qmake = binary.toFileInfo();
*qmakeIsExecutable = qmake.exists() && qmake.isExecutable() && !qmake.isDir();
if (!*qmakeIsExecutable)
return false;
QProcess process;
Utils::Environment env = Utils::Environment::systemEnvironment();
#ifdef Q_OS_WIN
// Add tool chain environment. This is necessary for non-static qmakes e.g. using mingw on windows
// We can not just add all the environments of all tool chains since that will make PATH too long
// which in turn will trigger a crash when parsing the results of vcvars.bat of MSVC.
QList<ProjectExplorer::Abi> abiList = ProjectExplorer::Abi::abisOfBinary(binary);
QList<ProjectExplorer::ToolChain *> tcList = ProjectExplorer::ToolChainManager::instance()->toolChains();
foreach (ProjectExplorer::ToolChain *tc, tcList) {
if (abiList.contains(tc->targetAbi()))
tc->addToEnvironment(env);
}
#endif
process.setEnvironment(env.toStringList());
process.start(qmake.absoluteFilePath(), QStringList(QLatin1String("-query")), QIODevice::ReadOnly);
process.start(binary.toString(), QStringList(QLatin1String("-query")), QIODevice::ReadOnly);
if (!process.waitForStarted()) {
*qmakeIsExecutable = false;
qWarning("Cannot start '%s': %s", qPrintable(binary.toUserOutput()), qPrintable(process.errorString()));
return false;
*isExecutable = false;
return QByteArray();
}
if (!process.waitForFinished(timeOutMS)) {
Utils::SynchronousProcess::stopProcess(process);
*isExecutable = true;
qWarning("Timeout running '%s' (%dms).", qPrintable(binary.toUserOutput()), timeOutMS);
return false;
return QByteArray();
}
if (process.exitStatus() != QProcess::NormalExit) {
*qmakeIsExecutable = false;
qWarning("'%s' crashed.", qPrintable(binary.toUserOutput()));
*isExecutable = false;
return QByteArray();
}
*isExecutable = true;
return process.readAllStandardOutput();
}
bool BaseQtVersion::queryQMakeVariables(const Utils::FileName &binary, QHash<QString, QString> *versionInfo,
bool *qmakeIsExecutable)
{
const QFileInfo qmake = binary.toFileInfo();
*qmakeIsExecutable = qmake.exists() && qmake.isExecutable() && !qmake.isDir();
if (!*qmakeIsExecutable)
return false;
QByteArray output;
output = runQmakeQuery(binary, Utils::Environment::systemEnvironment(), qmakeIsExecutable);
if (output.isNull() && !qmakeIsExecutable) {
// 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.
// This is required to make non-static qmakes work on windows where every tool chain
// tries to be incompatible with any other.
QList<ProjectExplorer::Abi> abiList = ProjectExplorer::Abi::abisOfBinary(binary);
QList<ProjectExplorer::ToolChain *> tcList = ProjectExplorer::ToolChainManager::instance()->toolChains();
foreach (ProjectExplorer::ToolChain *tc, tcList) {
if (!abiList.contains(tc->targetAbi()))
continue;
Utils::Environment env = Utils::Environment::systemEnvironment();
tc->addToEnvironment(env);
output = runQmakeQuery(binary, env, qmakeIsExecutable);
if (qmakeIsExecutable)
break;
}
}
QByteArray output = process.readAllStandardOutput();
if (output.isNull())
return false;
QTextStream stream(&output);
while (!stream.atEnd()) {
const QString line = stream.readLine();
......
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