RemoteLinux: Don't force value for DISPLAY in base environment

When set on nVidia Jetson TX-1, it leads to applications failing.

To allow previously created projects to work, add DISPLAY=:0.0 to user
changes to the base environment the first time the project is loaded. On
new projects for devices using X11 the user now has to manually set the
DISPLAY variable.

Task-number: QTBUG-60665
Change-Id: Iecc192fbad81ad5cbbbcabce6aeb28c3f501d022
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Kari Oikarinen
2017-05-08 16:40:59 +03:00
parent 6dc6eb9ad0
commit 9ea07a2fbc
2 changed files with 44 additions and 3 deletions

View File

@@ -26,6 +26,22 @@
#include "remotelinuxenvironmentaspect.h"
#include "remotelinuxenvironmentaspectwidget.h"
#include "utils/algorithm.h"
static const char DISPLAY_KEY[] = "DISPLAY";
static const char VERSION_KEY[] = "RemoteLinux.EnvironmentAspect.Version";
static const int ENVIRONMENTASPECT_VERSION = 1; // Version was introduced in 4.3 with the value 1
namespace {
bool displayAlreadySet(const QList<Utils::EnvironmentItem> &changes)
{
return Utils::contains(changes, [](const Utils::EnvironmentItem &item) {
return item.name == DISPLAY_KEY;
});
}
} // anonymous namespace
namespace RemoteLinux {
@@ -64,9 +80,6 @@ Utils::Environment RemoteLinuxEnvironmentAspect::baseEnvironment() const
Utils::Environment env;
if (baseEnvironmentBase() == static_cast<int>(RemoteBaseEnvironment))
env = m_remoteEnvironment;
const QString displayKey = QLatin1String("DISPLAY");
if (!env.hasKey(displayKey))
env.appendOrSet(displayKey, QLatin1String(":0.0"));
return env;
}
@@ -93,5 +106,29 @@ QString RemoteLinuxEnvironmentAspect::userEnvironmentChangesAsString() const
return env.mid(0, env.size() - 1);
}
void RemoteLinuxEnvironmentAspect::fromMap(const QVariantMap &map)
{
ProjectExplorer::EnvironmentAspect::fromMap(map);
const auto version = map.value(QLatin1String(VERSION_KEY), 0).toInt();
if (version == 0) {
// In Qt Creator versions prior to 4.3 RemoteLinux included DISPLAY=:0.0 in the base
// environment, if DISPLAY was not set. In order to keep existing projects expecting
// that working, add the DISPLAY setting to user changes in them. New projects will
// have version 1 and will not get DISPLAY set.
auto changes = userEnvironmentChanges();
if (!displayAlreadySet(changes)) {
changes.append(Utils::EnvironmentItem(QLatin1String(DISPLAY_KEY), QLatin1String(":0.0")));
setUserEnvironmentChanges(changes);
}
}
}
void RemoteLinuxEnvironmentAspect::toMap(QVariantMap &map) const
{
ProjectExplorer::EnvironmentAspect::toMap(map);
map.insert(QLatin1String(VERSION_KEY), ENVIRONMENTASPECT_VERSION);
}
} // namespace RemoteLinux

View File

@@ -48,6 +48,10 @@ public:
QString userEnvironmentChangesAsString() const;
protected:
void fromMap(const QVariantMap &map) override;
void toMap(QVariantMap &map) const override;
private:
enum BaseEnvironmentBase {
CleanBaseEnvironment = 0,