Commit 6d684220 authored by Christian Kandeler's avatar Christian Kandeler Committed by hjk

Utils: Introduce new class OsSpecificAspects.

This is basically a generalization of HostOsInfo for
a system that might not be the host system. HostOsInfo
is now implemented in terms of the new class.
Prospective use case: Untie Utils::Environment from
the host system.

Change-Id: If333b96674652109fcb0ad79f75aaaf5e86e17e3
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent ffae1fcb
...@@ -187,14 +187,14 @@ void Environment::prependOrSetPath(const QString &value) ...@@ -187,14 +187,14 @@ void Environment::prependOrSetPath(const QString &value)
void Environment::prependOrSetLibrarySearchPath(const QString &value) void Environment::prependOrSetLibrarySearchPath(const QString &value)
{ {
switch (HostOsInfo::hostOs()) { switch (HostOsInfo::hostOs()) {
case HostOsInfo::HostOsWindows: { case OsTypeWindows: {
const QChar sep = QLatin1Char(';'); const QChar sep = QLatin1Char(';');
const QLatin1String path("PATH"); const QLatin1String path("PATH");
prependOrSet(path, QDir::toNativeSeparators(value), QString(sep)); prependOrSet(path, QDir::toNativeSeparators(value), QString(sep));
break; break;
} }
case HostOsInfo::HostOsLinux: case OsTypeLinux:
case HostOsInfo::HostOsOtherUnix: { case OsTypeOtherUnix: {
const QChar sep = QLatin1Char(':'); const QChar sep = QLatin1Char(':');
const QLatin1String path("LD_LIBRARY_PATH"); const QLatin1String path("LD_LIBRARY_PATH");
prependOrSet(path, QDir::toNativeSeparators(value), QString(sep)); prependOrSet(path, QDir::toNativeSeparators(value), QString(sep));
......
...@@ -32,10 +32,12 @@ ...@@ -32,10 +32,12 @@
#include "utils_global.h" #include "utils_global.h"
#include "osspecificaspects.h"
#include <QString> #include <QString>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#define QTC_HOST_EXE_SUFFIX ".exe" #define QTC_HOST_EXE_SUFFIX QTC_WIN_EXE_SUFFIX
#else #else
#define QTC_HOST_EXE_SUFFIX "" #define QTC_HOST_EXE_SUFFIX ""
#endif // Q_OS_WIN #endif // Q_OS_WIN
...@@ -45,55 +47,54 @@ namespace Utils { ...@@ -45,55 +47,54 @@ namespace Utils {
class QTCREATOR_UTILS_EXPORT HostOsInfo class QTCREATOR_UTILS_EXPORT HostOsInfo
{ {
public: public:
// Add more as needed. static inline OsType hostOs();
enum HostOs { HostOsWindows, HostOsLinux, HostOsMac, HostOsOtherUnix, HostOsOther };
static inline HostOs hostOs();
enum HostArchitecture { HostArchitectureX86, HostArchitectureAMD64, HostArchitectureItanium, enum HostArchitecture { HostArchitectureX86, HostArchitectureAMD64, HostArchitectureItanium,
HostArchitectureArm, HostArchitectureUnknown }; HostArchitectureArm, HostArchitectureUnknown };
static HostArchitecture hostArchitecture(); static HostArchitecture hostArchitecture();
static bool isWindowsHost() { return hostOs() == HostOsWindows; } static bool isWindowsHost() { return hostOs() == OsTypeWindows; }
static bool isLinuxHost() { return hostOs() == HostOsLinux; } static bool isLinuxHost() { return hostOs() == OsTypeLinux; }
static bool isMacHost() { return hostOs() == HostOsMac; } static bool isMacHost() { return hostOs() == OsTypeMac; }
static inline bool isAnyUnixHost(); static inline bool isAnyUnixHost();
static QString withExecutableSuffix(const QString &executable) static QString withExecutableSuffix(const QString &executable)
{ {
QString finalName = executable; return hostOsAspects().withExecutableSuffix(executable);
if (isWindowsHost())
finalName += QLatin1String(QTC_HOST_EXE_SUFFIX);
return finalName;
} }
static Qt::CaseSensitivity fileNameCaseSensitivity() static Qt::CaseSensitivity fileNameCaseSensitivity()
{ {
return isWindowsHost() ? Qt::CaseInsensitive: Qt::CaseSensitive; return hostOsAspects().fileNameCaseSensitivity();
} }
static QChar pathListSeparator() static QChar pathListSeparator()
{ {
return isWindowsHost() ? QLatin1Char(';') : QLatin1Char(':'); return hostOsAspects().pathListSeparator();
} }
static Qt::KeyboardModifier controlModifier() static Qt::KeyboardModifier controlModifier()
{ {
return isMacHost() ? Qt::MetaModifier : Qt::ControlModifier; return hostOsAspects().controlModifier();
} }
private:
static OsSpecificAspects hostOsAspects() { return OsSpecificAspects(hostOs()); }
}; };
HostOsInfo::HostOs HostOsInfo::hostOs()
OsType HostOsInfo::hostOs()
{ {
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
return HostOsWindows; return OsTypeWindows;
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
return HostOsLinux; return OsTypeLinux;
#elif defined(Q_OS_MAC) #elif defined(Q_OS_MAC)
return HostOsMac; return OsTypeMac;
#elif defined(Q_OS_UNIX) #elif defined(Q_OS_UNIX)
return HostOsOtherUnix; return OsTypeOtherUnix;
#else #else
return HostOsOther; return OsTypeOther;
#endif #endif
} }
......
/**************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QTC_OSSPECIFICASPECTS_H
#define QTC_OSSPECIFICASPECTS_H
#include "utils_global.h"
#include <QString>
#define QTC_WIN_EXE_SUFFIX ".exe"
namespace Utils {
// Add more as needed.
enum OsType { OsTypeWindows, OsTypeLinux, OsTypeMac, OsTypeOtherUnix, OsTypeOther };
class QTCREATOR_UTILS_EXPORT OsSpecificAspects
{
public:
OsSpecificAspects(OsType osType) : m_osType(osType) { }
QString withExecutableSuffix(const QString &executable) const {
QString finalName = executable;
if (m_osType == OsTypeWindows)
finalName += QLatin1String(QTC_WIN_EXE_SUFFIX);
return finalName;
}
Qt::CaseSensitivity fileNameCaseSensitivity() const {
return m_osType == OsTypeWindows ? Qt::CaseInsensitive : Qt::CaseSensitive;
}
QChar pathListSeparator() const {
return QLatin1Char(m_osType == OsTypeWindows ? ';' : ':');
}
Qt::KeyboardModifier controlModifier() const {
return m_osType == OsTypeMac ? Qt::MetaModifier : Qt::ControlModifier;
}
private:
const OsType m_osType;
};
} // namespace Utils
#endif // Include guard.
...@@ -621,11 +621,11 @@ static QString checkBinary(const QDir &dir, const QString &binary) ...@@ -621,11 +621,11 @@ static QString checkBinary(const QDir &dir, const QString &binary)
return QString(); return QString();
switch (HostOsInfo::hostOs()) { switch (HostOsInfo::hostOs()) {
case HostOsInfo::HostOsLinux: case OsTypeLinux:
case HostOsInfo::HostOsOtherUnix: case OsTypeOtherUnix:
case HostOsInfo::HostOsOther: case OsTypeOther:
break; break;
case HostOsInfo::HostOsWindows: { case OsTypeWindows: {
static const char *windowsExtensions[] = {".cmd", ".bat", ".exe", ".com" }; static const char *windowsExtensions[] = {".cmd", ".bat", ".exe", ".com" };
// Check the Windows extensions using the order // Check the Windows extensions using the order
const int windowsExtensionCount = sizeof(windowsExtensions)/sizeof(const char*); const int windowsExtensionCount = sizeof(windowsExtensions)/sizeof(const char*);
...@@ -636,7 +636,7 @@ static QString checkBinary(const QDir &dir, const QString &binary) ...@@ -636,7 +636,7 @@ static QString checkBinary(const QDir &dir, const QString &binary)
} }
} }
break; break;
case HostOsInfo::HostOsMac: { case OsTypeMac: {
// Check for Mac app folders // Check for Mac app folders
const QFileInfo appFolder(dir.filePath(binary + QLatin1String(".app"))); const QFileInfo appFolder(dir.filePath(binary + QLatin1String(".app")));
if (appFolder.isDir()) { if (appFolder.isDir()) {
......
...@@ -167,6 +167,7 @@ HEADERS += \ ...@@ -167,6 +167,7 @@ HEADERS += \
$$PWD/bracematcher.h \ $$PWD/bracematcher.h \
$$PWD/proxyaction.h \ $$PWD/proxyaction.h \
$$PWD/hostosinfo.h \ $$PWD/hostosinfo.h \
$$PWD/osspecificaspects.h \
$$PWD/elidinglabel.h \ $$PWD/elidinglabel.h \
$$PWD/tooltip/tooltip.h \ $$PWD/tooltip/tooltip.h \
$$PWD/tooltip/tips.h \ $$PWD/tooltip/tips.h \
......
...@@ -110,6 +110,7 @@ QtcLibrary { ...@@ -110,6 +110,7 @@ QtcLibrary {
"newclasswidget.cpp", "newclasswidget.cpp",
"newclasswidget.h", "newclasswidget.h",
"newclasswidget.ui", "newclasswidget.ui",
"osspecificaspects.h",
"outputformat.h", "outputformat.h",
"outputformatter.cpp", "outputformatter.cpp",
"outputformatter.h", "outputformatter.h",
......
...@@ -335,13 +335,13 @@ void AndroidConfigurations::detectToolchainHost() ...@@ -335,13 +335,13 @@ void AndroidConfigurations::detectToolchainHost()
{ {
QStringList hostPatterns; QStringList hostPatterns;
switch (HostOsInfo::hostOs()) { switch (HostOsInfo::hostOs()) {
case HostOsInfo::HostOsLinux: case OsTypeLinux:
hostPatterns << QLatin1String("linux*"); hostPatterns << QLatin1String("linux*");
break; break;
case HostOsInfo::HostOsWindows: case OsTypeWindows:
hostPatterns << QLatin1String("windows*"); hostPatterns << QLatin1String("windows*");
break; break;
case HostOsInfo::HostOsMac: case OsTypeMac:
hostPatterns << QLatin1String("darwin*"); hostPatterns << QLatin1String("darwin*");
break; break;
default: /* unknown host */ return; default: /* unknown host */ return;
......
...@@ -67,13 +67,13 @@ LibraryDetailsController::LibraryDetailsController( ...@@ -67,13 +67,13 @@ LibraryDetailsController::LibraryDetailsController(
m_libraryDetailsWidget(libraryDetails) m_libraryDetailsWidget(libraryDetails)
{ {
switch (Utils::HostOsInfo::hostOs()) { switch (Utils::HostOsInfo::hostOs()) {
case Utils::HostOsInfo::HostOsMac: case Utils::OsTypeMac:
m_creatorPlatform = CreatorMac; m_creatorPlatform = CreatorMac;
break; break;
case Utils::HostOsInfo::HostOsLinux: case Utils::OsTypeLinux:
m_creatorPlatform = CreatorLinux; m_creatorPlatform = CreatorLinux;
break; break;
case Utils::HostOsInfo::HostOsWindows: case Utils::OsTypeWindows:
m_creatorPlatform = CreatorWindows; m_creatorPlatform = CreatorWindows;
break; break;
default: default:
......
...@@ -286,10 +286,10 @@ void WelcomeMode::initPlugins() ...@@ -286,10 +286,10 @@ void WelcomeMode::initPlugins()
QString WelcomeMode::platform() const QString WelcomeMode::platform() const
{ {
switch (HostOsInfo::hostOs()) { switch (HostOsInfo::hostOs()) {
case HostOsInfo::HostOsWindows: return QLatin1String("windows"); case OsTypeWindows: return QLatin1String("windows");
case HostOsInfo::HostOsMac: return QLatin1String("mac"); case OsTypeMac: return QLatin1String("mac");
case HostOsInfo::HostOsLinux: return QLatin1String("linux"); case OsTypeLinux: return QLatin1String("linux");
case HostOsInfo::HostOsOtherUnix: return QLatin1String("unix"); case OsTypeOtherUnix: return QLatin1String("unix");
default: return QLatin1String("other"); default: return QLatin1String("other");
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment