summaryrefslogtreecommitdiff
path: root/src/libs/utils/environment.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@digia.com>2013-08-15 16:54:51 +0200
committerChristian Kandeler <christian.kandeler@digia.com>2013-08-16 10:22:30 +0200
commit02105ddf62b40abae18c9155c376fdd6bf13991d (patch)
treefd00c230c90beeb1abbe11d7b86520220bbe60c7 /src/libs/utils/environment.cpp
parent6d6842202606bd153bf8614bb4699ed45ac13d3e (diff)
downloadqt-creator-02105ddf62b40abae18c9155c376fdd6bf13991d.tar.gz
Utils: Untie the Environment class from the host system.
It is used e.g. in the RemoteLinux plugin (via ProjectExplorer::EnvironmentAspect) and should therefore not assume that it's meant for a host system process. Change-Id: I9f44f862f133579b65951e43fc1e654c425fd3d7 Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Diffstat (limited to 'src/libs/utils/environment.cpp')
-rw-r--r--src/libs/utils/environment.cpp32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/libs/utils/environment.cpp b/src/libs/utils/environment.cpp
index 9c7140b202..663e093fb7 100644
--- a/src/libs/utils/environment.cpp
+++ b/src/libs/utils/environment.cpp
@@ -29,8 +29,6 @@
#include "environment.h"
-#include "hostosinfo.h"
-
#include <QDir>
#include <QProcessEnvironment>
#include <QCoreApplication>
@@ -99,12 +97,12 @@ QStringList EnvironmentItem::toStringList(const QList<EnvironmentItem> &list)
return result;
}
-Environment::Environment(const QStringList &env)
+Environment::Environment(const QStringList &env, OsType osType) : m_osType(osType)
{
foreach (const QString &s, env) {
int i = s.indexOf(QLatin1Char('='));
if (i >= 0) {
- if (HostOsInfo::isWindowsHost())
+ if (m_osType == OsTypeWindows)
m_values.insert(s.left(i).toUpper(), s.mid(i+1));
else
m_values.insert(s.left(i), s.mid(i+1));
@@ -136,17 +134,17 @@ QProcessEnvironment Environment::toProcessEnvironment() const
void Environment::set(const QString &key, const QString &value)
{
- m_values.insert(HostOsInfo::isWindowsHost() ? key.toUpper() : key, value);
+ m_values.insert(m_osType == OsTypeWindows ? key.toUpper() : key, value);
}
void Environment::unset(const QString &key)
{
- m_values.remove(HostOsInfo::isWindowsHost() ? key.toUpper() : key);
+ m_values.remove(m_osType == OsTypeWindows ? key.toUpper() : key);
}
void Environment::appendOrSet(const QString &key, const QString &value, const QString &sep)
{
- const QString &_key = HostOsInfo::isWindowsHost() ? key.toUpper() : key;
+ const QString &_key = m_osType == OsTypeWindows ? key.toUpper() : key;
QMap<QString, QString>::iterator it = m_values.find(_key);
if (it == m_values.end()) {
m_values.insert(_key, value);
@@ -160,7 +158,7 @@ void Environment::appendOrSet(const QString &key, const QString &value, const QS
void Environment::prependOrSet(const QString&key, const QString &value, const QString &sep)
{
- const QString &_key = HostOsInfo::isWindowsHost() ? key.toUpper() : key;
+ const QString &_key = m_osType == OsTypeWindows ? key.toUpper() : key;
QMap<QString, QString>::iterator it = m_values.find(_key);
if (it == m_values.end()) {
m_values.insert(_key, value);
@@ -175,18 +173,18 @@ void Environment::prependOrSet(const QString&key, const QString &value, const QS
void Environment::appendOrSetPath(const QString &value)
{
appendOrSet(QLatin1String("PATH"), QDir::toNativeSeparators(value),
- QString(HostOsInfo::pathListSeparator()));
+ QString(OsSpecificAspects(m_osType).pathListSeparator()));
}
void Environment::prependOrSetPath(const QString &value)
{
prependOrSet(QLatin1String("PATH"), QDir::toNativeSeparators(value),
- QString(HostOsInfo::pathListSeparator()));
+ QString(OsSpecificAspects(m_osType).pathListSeparator()));
}
void Environment::prependOrSetLibrarySearchPath(const QString &value)
{
- switch (HostOsInfo::hostOs()) {
+ switch (m_osType) {
case OsTypeWindows: {
const QChar sep = QLatin1Char(';');
const QLatin1String path("PATH");
@@ -243,7 +241,7 @@ QString Environment::searchInPath(const QString &executable,
QFileInfo fi(exec);
QStringList execs(exec);
- if (HostOsInfo::isWindowsHost()) {
+ if (m_osType == OsTypeWindows) {
// Check all the executable extensions on windows:
// PATHEXT is only used if the executable has no extension
if (fi.suffix().isEmpty()) {
@@ -283,8 +281,8 @@ QString Environment::searchInPath(const QString &executable,
QStringList Environment::path() const
{
- return m_values.value(QLatin1String("PATH")).split(HostOsInfo::pathListSeparator(),
- QString::SkipEmptyParts);
+ return m_values.value(QLatin1String("PATH"))
+ .split(OsSpecificAspects(m_osType).pathListSeparator(), QString::SkipEmptyParts);
}
QString Environment::value(const QString &key) const
@@ -398,7 +396,7 @@ bool Environment::hasKey(const QString &key) const
QString Environment::userName() const
{
- return value(QLatin1String(HostOsInfo::isWindowsHost() ? "USERNAME" : "USER"));
+ return value(QLatin1String(m_osType == OsTypeWindows ? "USERNAME" : "USER"));
}
bool Environment::operator!=(const Environment &other) const
@@ -408,7 +406,7 @@ bool Environment::operator!=(const Environment &other) const
bool Environment::operator==(const Environment &other) const
{
- return m_values == other.m_values;
+ return m_osType == other.m_osType && m_values == other.m_values;
}
/** Expand environment variables in a string.
@@ -422,7 +420,7 @@ QString Environment::expandVariables(const QString &input) const
{
QString result = input;
- if (HostOsInfo::isWindowsHost()) {
+ if (m_osType == OsTypeWindows) {
for (int vStart = -1, i = 0; i < result.length(); ) {
if (result.at(i++) == QLatin1Char('%')) {
if (vStart > 0) {