Do not modify environment for user applications

We used to set QT_OPENGL, currently set LD_LIBRARY_PATH when qtcreator.sh
is used, and might set other variables in the future,
but these environment modifications should not be passed on
to user applications or when we run tools that are not shipped with
Qt Creator.

For LD_LIBRARY_PATH there already was a hack for
Environment::systemEnvironment.

For environment variables that we might set in main()
in the future, this patch caches the system environment for
Environment::systemEnvironment early before any modifications are made.

The previous hack for LD_LIBRARY_PATH no longer works, since it
used QCoreApplication::applicationDirPath() which cannot be used at that
point in time (before the QApplication has been created). Instead pass
the correct user LD_LIBRARY_PATH directly from qtcreator.sh to
Qt Creator through a command line option, which is cleaner anyhow.

Task-number: QTCREATORBUG-20808
Change-Id: I6674a5e0537e1b37fd7dcbff371b542fa24bce69
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Eike Ziller
2018-08-09 11:31:41 +02:00
parent 2c0554c187
commit d35638df56
4 changed files with 36 additions and 31 deletions

View File

@@ -34,30 +34,8 @@
#include <QSet>
#include <QCoreApplication>
class SystemEnvironment : public Utils::Environment
{
public:
SystemEnvironment()
: Environment(QProcessEnvironment::systemEnvironment().toStringList())
{
if (Utils::HostOsInfo::isLinuxHost()) {
QString ldLibraryPath = value("LD_LIBRARY_PATH");
QDir lib(QCoreApplication::applicationDirPath());
lib.cd("../lib");
QString toReplace = lib.path();
lib.cd("qtcreator");
toReplace.append(':');
toReplace.append(lib.path());
if (ldLibraryPath.startsWith(toReplace + ':'))
set("LD_LIBRARY_PATH", ldLibraryPath.remove(0, toReplace.length() + 1));
else if (ldLibraryPath == toReplace)
unset("LD_LIBRARY_PATH");
}
}
};
Q_GLOBAL_STATIC(SystemEnvironment, staticSystemEnvironment)
Q_GLOBAL_STATIC_WITH_ARGS(Utils::Environment, staticSystemEnvironment,
(QProcessEnvironment::systemEnvironment().toStringList()))
static QMap<QString, QString>::iterator findKey(QMap<QString, QString> &input, Utils::OsType osType,
const QString &key)
@@ -621,6 +599,11 @@ bool Environment::operator==(const Environment &other) const
return m_osType == other.m_osType && m_values == other.m_values;
}
void Environment::modifySystemEnvironment(const QList<EnvironmentItem> &list)
{
staticSystemEnvironment->modify(list);
}
/** Expand environment variables in a string.
*
* Environment variables are accepted in the following forms: