aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2018-08-09 11:31:41 +0200
committerEike Ziller <eike.ziller@qt.io>2018-08-21 08:48:21 +0000
commitd35638df56b741bc7bc3cac228075040cdd8a931 (patch)
tree01941b6bae22b931f180cb224c397ae540d9cfee
parent2c0554c187adb4ef886affd193b8149afa199d13 (diff)
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>
-rwxr-xr-xbin/qtcreator.sh3
-rw-r--r--src/app/main.cpp31
-rw-r--r--src/libs/utils/environment.cpp31
-rw-r--r--src/libs/utils/environment.h2
4 files changed, 36 insertions, 31 deletions
diff --git a/bin/qtcreator.sh b/bin/qtcreator.sh
index 80fc4499c9..86826f1e3b 100755
--- a/bin/qtcreator.sh
+++ b/bin/qtcreator.sh
@@ -39,6 +39,7 @@ if test -d "$qtlibdir"; then
qtlibpath=:$qtlibdir
fi
# Add Qt Creator library path
+_ORIGINAL_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
LD_LIBRARY_PATH=$libdir:$libdir/qtcreator$qtlibpath${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
export LD_LIBRARY_PATH
-exec "$bindir/qtcreator" ${1+"$@"}
+exec "$bindir/qtcreator" -user-library-path "$_ORIGINAL_LD_LIBRARY_PATH" ${1+"$@"}
diff --git a/src/app/main.cpp b/src/app/main.cpp
index c498db3759..045add4fbe 100644
--- a/src/app/main.cpp
+++ b/src/app/main.cpp
@@ -32,8 +32,10 @@
#include <extensionsystem/pluginspec.h>
#include <qtsingleapplication.h>
+#include <utils/environment.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
+#include <utils/optional.h>
#include <utils/temporarydirectory.h>
#include <QDebug>
@@ -95,6 +97,7 @@ const char TEST_OPTION[] = "-test";
const char PID_OPTION[] = "-pid";
const char BLOCK_OPTION[] = "-block";
const char PLUGINPATH_OPTION[] = "-pluginpath";
+const char USER_LIBRARY_PATH_OPTION[] = "-user-library-path"; // hidden option for qtcreator.sh
typedef QList<PluginSpec *> PluginSpecSet;
@@ -343,6 +346,7 @@ struct Options
QString installSettingsPath;
QStringList customPluginPaths;
std::vector<char *> appArguments;
+ Utils::optional<QString> userLibraryPath;
bool hasTestOption = false;
};
@@ -365,6 +369,9 @@ Options parseCommandLine(int argc, char *argv[])
} else if (arg == PLUGINPATH_OPTION && hasNext) {
++it;
options.customPluginPaths += QDir::fromNativeSeparators(nextArg);
+ } else if (arg == USER_LIBRARY_PATH_OPTION && hasNext) {
+ ++it;
+ options.userLibraryPath = nextArg;
} else { // arguments that are still passed on to the application
if (arg == TEST_OPTION)
options.hasTestOption = true;
@@ -377,6 +384,24 @@ Options parseCommandLine(int argc, char *argv[])
int main(int argc, char **argv)
{
+ Utils::Environment::systemEnvironment(); // cache system environment before we do any changes
+
+ // Manually determine various command line options
+ // We can't use the regular way of the plugin manager,
+ // because settings can change the way plugin manager behaves
+ Options options = parseCommandLine(argc, argv);
+ applicationDirPath(argv[0]);
+
+ if (options.userLibraryPath) {
+ if ((*options.userLibraryPath).isEmpty()) {
+ Utils::Environment::modifySystemEnvironment(
+ {{"LD_LIBRARY_PATH", "", Utils::EnvironmentItem::Unset}});
+ } else {
+ Utils::Environment::modifySystemEnvironment(
+ {{"LD_LIBRARY_PATH", *options.userLibraryPath, Utils::EnvironmentItem::Set}});
+ }
+ }
+
#ifdef Q_OS_WIN
if (!qEnvironmentVariableIsSet("QT_OPENGL"))
QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
@@ -400,12 +425,6 @@ int main(int argc, char **argv)
setrlimit(RLIMIT_NOFILE, &rl);
#endif
- // Manually determine various command line options
- // We can't use the regular way of the plugin manager,
- // because settings can change the way plugin manager behaves
- Options options = parseCommandLine(argc, argv);
- applicationDirPath(argv[0]);
-
QScopedPointer<Utils::TemporaryDirectory> temporaryCleanSettingsDir;
if (options.settingsPath.isEmpty() && options.hasTestOption) {
temporaryCleanSettingsDir.reset(new Utils::TemporaryDirectory("qtc-test-settings"));
diff --git a/src/libs/utils/environment.cpp b/src/libs/utils/environment.cpp
index 9b77a8b71e..54a5b72317 100644
--- a/src/libs/utils/environment.cpp
+++ b/src/libs/utils/environment.cpp
@@ -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:
diff --git a/src/libs/utils/environment.h b/src/libs/utils/environment.h
index 4803dda2a5..43a4ded9be 100644
--- a/src/libs/utils/environment.h
+++ b/src/libs/utils/environment.h
@@ -139,6 +139,8 @@ public:
bool operator!=(const Environment &other) const;
bool operator==(const Environment &other) const;
+ static void modifySystemEnvironment(const QList<EnvironmentItem> &list); // use with care!!!
+
private:
FileName searchInDirectory(const QStringList &execs, const FileName &directory,
QSet<FileName> &alreadyChecked) const;