Commit 4d5a210f authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Qt: Allow for custom environments to run "qmake -query" in



Some SDKs (Blackberry) use one qmake only and have environment
variables embedded in their mkspecs that are then used to switch
between different instances of that SDK. Rather strange approach,
but that is what they do.

So this patch provides a member method to BaseQtVersion that can
be used to override the environment seen by "qmake -query". The
default implementation is to use the system environment.

This will not work very well while trying to initially detect which
kind of Qt version to construct for a qmake. This is not a big issue
though as they can either create the Qt version in non-standard ways
(Blackberry is going for a SDK setup page). If the system environment
is set up correctly the normal add-a-qmake approach will also work.

Change-Id: I80b1c259b127de816b5d02da414a9f4b11d7f658
Reviewed-by: default avatarMehdi Fekari <mfekari@rim.com>
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent ccd8b92c
......@@ -866,7 +866,7 @@ void BaseQtVersion::updateVersionInfo() const
m_hasQmlDebuggingLibrary = false;
m_hasQmlObserver = false;
if (!queryQMakeVariables(qmakeCommand(), &m_versionInfo, &m_qmakeIsExecutable))
if (!queryQMakeVariables(qmakeCommand(), qmakeRunEnvironment(), &m_versionInfo, &m_qmakeIsExecutable))
return;
const QString qtInstallData = qmakeProperty("QT_INSTALL_DATA");
......@@ -999,6 +999,16 @@ void BaseQtVersion::addToEnvironment(const ProjectExplorer::Kit *k, Environment
env.prependOrSetPath(qmakeProperty("QT_HOST_BINS"));
}
// Some Qt versions may require environment settings for qmake to work
//
// One such example is Blackberry which for some reason decided to always use the same
// qmake and use environment variables embedded in their mkspecs to make that point to
// the different Qt installations.
Utils::Environment BaseQtVersion::qmakeRunEnvironment() const
{
return Utils::Environment::systemEnvironment();
}
bool BaseQtVersion::hasGdbDebuggingHelper() const
{
updateVersionInfo();
......@@ -1172,14 +1182,15 @@ QtConfigWidget *BaseQtVersion::createConfigurationWidget() const
return 0;
}
bool BaseQtVersion::queryQMakeVariables(const FileName &binary, QHash<QString, QString> *versionInfo)
bool BaseQtVersion::queryQMakeVariables(const FileName &binary, const Utils::Environment &env,
QHash<QString, QString> *versionInfo)
{
bool qmakeIsExecutable;
return BaseQtVersion::queryQMakeVariables(binary, versionInfo, &qmakeIsExecutable);
return BaseQtVersion::queryQMakeVariables(binary, env, versionInfo, &qmakeIsExecutable);
}
bool BaseQtVersion::queryQMakeVariables(const FileName &binary, QHash<QString, QString> *versionInfo,
bool *qmakeIsExecutable)
bool BaseQtVersion::queryQMakeVariables(const FileName &binary, const Utils::Environment &env,
QHash<QString, QString> *versionInfo, bool *qmakeIsExecutable)
{
const int timeOutMS = 30000; // Might be slow on some machines.
const QFileInfo qmake = binary.toFileInfo();
......@@ -1188,7 +1199,7 @@ bool BaseQtVersion::queryQMakeVariables(const FileName &binary, QHash<QString, Q
return false;
QProcess process;
Environment env = Environment::systemEnvironment();
Environment qmakeEnv = env;
if (HostOsInfo::isWindowsHost()) {
// Add tool chain environment. This is necessary for non-static qmakes e.g. using mingw on windows
......@@ -1198,11 +1209,11 @@ bool BaseQtVersion::queryQMakeVariables(const FileName &binary, QHash<QString, Q
QList<ProjectExplorer::ToolChain *> tcList = ProjectExplorer::ToolChainManager::instance()->toolChains();
foreach (ProjectExplorer::ToolChain *tc, tcList) {
if (abiList.contains(tc->targetAbi()))
tc->addToEnvironment(env);
tc->addToEnvironment(qmakeEnv);
}
}
process.setEnvironment(env.toStringList());
process.setEnvironment(qmakeEnv.toStringList());
process.start(qmake.absoluteFilePath(), QStringList(QLatin1String("-query")), QIODevice::ReadOnly);
if (!process.waitForStarted()) {
......
......@@ -131,6 +131,7 @@ public:
static QString qmakeProperty(const QHash<QString,QString> &versionInfo, const QByteArray &name);
QString qmakeProperty(const QByteArray &name) const;
virtual void addToEnvironment(const ProjectExplorer::Kit *k, Utils::Environment &env) const;
virtual Utils::Environment qmakeRunEnvironment() const;
virtual Utils::FileName sourcePath() const;
// used by QtUiCodeModelSupport
......@@ -185,8 +186,11 @@ public:
/// warnings and finally info items.
QList<ProjectExplorer::Task> reportIssues(const QString &proFile, const QString &buildDir) const;
static bool queryQMakeVariables(const Utils::FileName &binary, QHash<QString, QString> *versionInfo);
static bool queryQMakeVariables(const Utils::FileName &binary, QHash<QString, QString> *versionInfo, bool *qmakeIsExecutable);
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);
static Utils::FileName mkspecDirectoryFromVersionInfo(const QHash<QString, QString> &versionInfo);
static Utils::FileName mkspecFromVersionInfo(const QHash<QString, QString> &versionInfo);
......
......@@ -33,6 +33,8 @@
#include "baseqtversion.h"
#include <extensionsystem/pluginmanager.h>
#include <utils/environment.h>
#include <QSettings>
using namespace QtSupport;
......@@ -57,7 +59,8 @@ bool sortByPriority(QtVersionFactory *a, QtVersionFactory *b)
BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FileName &qmakePath, bool isAutoDetected, const QString &autoDetectionSource)
{
QHash<QString, QString> versionInfo;
bool success = BaseQtVersion::queryQMakeVariables(qmakePath, &versionInfo);
Utils::Environment env = Utils::Environment::systemEnvironment();
bool success = BaseQtVersion::queryQMakeVariables(qmakePath, env, &versionInfo);
if (!success)
return 0;
Utils::FileName mkspec = BaseQtVersion::mkspecFromVersionInfo(versionInfo);
......
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