diff --git a/src/libs/utils/environment.cpp b/src/libs/utils/environment.cpp index 9c7140b2021..663e093fb78 100644 --- a/src/libs/utils/environment.cpp +++ b/src/libs/utils/environment.cpp @@ -29,8 +29,6 @@ #include "environment.h" -#include "hostosinfo.h" - #include #include #include @@ -99,12 +97,12 @@ QStringList EnvironmentItem::toStringList(const QList &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::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::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) { diff --git a/src/libs/utils/environment.h b/src/libs/utils/environment.h index 46fd72a88c4..4442be992c3 100644 --- a/src/libs/utils/environment.h +++ b/src/libs/utils/environment.h @@ -30,6 +30,7 @@ #ifndef UTILS_ENVIRONMENT_H #define UTILS_ENVIRONMENT_H +#include "hostosinfo.h" #include "utils_global.h" #include @@ -65,8 +66,8 @@ class QTCREATOR_UTILS_EXPORT Environment public: typedef QMap::const_iterator const_iterator; - Environment() {} - explicit Environment(const QStringList &env); + explicit Environment(OsType osType = HostOsInfo::hostOs()) : m_osType(osType) {} + explicit Environment(const QStringList &env, OsType osType = HostOsInfo::hostOs()); static Environment systemEnvironment(); QStringList toStringList() const; @@ -112,6 +113,7 @@ public: private: QString searchInDirectory(const QStringList &execs, QString directory) const; QMap m_values; + OsType m_osType; }; } // namespace Utils diff --git a/src/plugins/remotelinux/remotelinuxenvironmentreader.cpp b/src/plugins/remotelinux/remotelinuxenvironmentreader.cpp index 92101bed6f9..ba6e1225cc3 100644 --- a/src/plugins/remotelinux/remotelinuxenvironmentreader.cpp +++ b/src/plugins/remotelinux/remotelinuxenvironmentreader.cpp @@ -42,6 +42,7 @@ namespace Internal { RemoteLinuxEnvironmentReader::RemoteLinuxEnvironmentReader(RunConfiguration *config, QObject *parent) : QObject(parent) , m_stop(false) + , m_env(Utils::OsTypeLinux) , m_kit(config->target()->kit()) , m_remoteProcessRunner(0) { @@ -104,7 +105,7 @@ void RemoteLinuxEnvironmentReader::remoteProcessFinished(int exitCode) QString remoteOutput = QString::fromUtf8(m_remoteProcessRunner->readAllStandardOutput()); if (!remoteOutput.isEmpty()) { m_env = Utils::Environment(remoteOutput.split(QLatin1Char('\n'), - QString::SkipEmptyParts)); + QString::SkipEmptyParts), Utils::OsTypeLinux); } } else { QString errorMsg = tr("Error running remote process: %1")