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)
void Environment::prependOrSetLibrarySearchPath(const QString &value)
{
switch (HostOsInfo::hostOs()) {
case HostOsInfo::HostOsWindows: {
case OsTypeWindows: {
const QChar sep = QLatin1Char(';');
const QLatin1String path("PATH");
prependOrSet(path, QDir::toNativeSeparators(value), QString(sep));
break;
}
case HostOsInfo::HostOsLinux:
case HostOsInfo::HostOsOtherUnix: {
case OsTypeLinux:
case OsTypeOtherUnix: {
const QChar sep = QLatin1Char(':');
const QLatin1String path("LD_LIBRARY_PATH");
prependOrSet(path, QDir::toNativeSeparators(value), QString(sep));
......
......@@ -32,10 +32,12 @@
#include "utils_global.h"
#include "osspecificaspects.h"
#include <QString>
#ifdef Q_OS_WIN
#define QTC_HOST_EXE_SUFFIX ".exe"
#define QTC_HOST_EXE_SUFFIX QTC_WIN_EXE_SUFFIX
#else
#define QTC_HOST_EXE_SUFFIX ""
#endif // Q_OS_WIN
......@@ -45,55 +47,54 @@ namespace Utils {
class QTCREATOR_UTILS_EXPORT HostOsInfo
{
public:
// Add more as needed.
enum HostOs { HostOsWindows, HostOsLinux, HostOsMac, HostOsOtherUnix, HostOsOther };
static inline HostOs hostOs();
static inline OsType hostOs();
enum HostArchitecture { HostArchitectureX86, HostArchitectureAMD64, HostArchitectureItanium,
HostArchitectureArm, HostArchitectureUnknown };
static HostArchitecture hostArchitecture();
static bool isWindowsHost() { return hostOs() == HostOsWindows; }
static bool isLinuxHost() { return hostOs() == HostOsLinux; }
static bool isMacHost() { return hostOs() == HostOsMac; }
static bool isWindowsHost() { return hostOs() == OsTypeWindows; }
static bool isLinuxHost() { return hostOs() == OsTypeLinux; }
static bool isMacHost() { return hostOs() == OsTypeMac; }
static inline bool isAnyUnixHost();
static QString withExecutableSuffix(const QString &executable)
{
QString finalName = executable;
if (isWindowsHost())
finalName += QLatin1String(QTC_HOST_EXE_SUFFIX);
return finalName;
return hostOsAspects().withExecutableSuffix(executable);
}
static Qt::CaseSensitivity fileNameCaseSensitivity()
{
return isWindowsHost() ? Qt::CaseInsensitive: Qt::CaseSensitive;
return hostOsAspects().fileNameCaseSensitivity();
}
static QChar pathListSeparator()
{
return isWindowsHost() ? QLatin1Char(';') : QLatin1Char(':');
return hostOsAspects().pathListSeparator();
}
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)
return HostOsWindows;
return OsTypeWindows;
#elif defined(Q_OS_LINUX)
return HostOsLinux;
return OsTypeLinux;
#elif defined(Q_OS_MAC)
return HostOsMac;
return OsTypeMac;
#elif defined(Q_OS_UNIX)
return HostOsOtherUnix;
return OsTypeOtherUnix;
#else
return HostOsOther;
return OsTypeOther;
#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)
return QString();
switch (HostOsInfo::hostOs()) {
case HostOsInfo::HostOsLinux:
case HostOsInfo::HostOsOtherUnix:
case HostOsInfo::HostOsOther:
case OsTypeLinux:
case OsTypeOtherUnix:
case OsTypeOther:
break;
case HostOsInfo::HostOsWindows: {
case OsTypeWindows: {
static const char *windowsExtensions[] = {".cmd", ".bat", ".exe", ".com" };
// Check the Windows extensions using the order
const int windowsExtensionCount = sizeof(windowsExtensions)/sizeof(const char*);
......@@ -636,7 +636,7 @@ static QString checkBinary(const QDir &dir, const QString &binary)
}
}
break;
case HostOsInfo::HostOsMac: {
case OsTypeMac: {
// Check for Mac app folders
const QFileInfo appFolder(dir.filePath(binary + QLatin1String(".app")));
if (appFolder.isDir()) {
......
......@@ -167,6 +167,7 @@ HEADERS += \
$$PWD/bracematcher.h \
$$PWD/proxyaction.h \
$$PWD/hostosinfo.h \
$$PWD/osspecificaspects.h \
$$PWD/elidinglabel.h \
$$PWD/tooltip/tooltip.h \
$$PWD/tooltip/tips.h \
......
......@@ -110,6 +110,7 @@ QtcLibrary {
"newclasswidget.cpp",
"newclasswidget.h",
"newclasswidget.ui",
"osspecificaspects.h",
"outputformat.h",
"outputformatter.cpp",
"outputformatter.h",
......
......@@ -335,13 +335,13 @@ void AndroidConfigurations::detectToolchainHost()
{
QStringList hostPatterns;
switch (HostOsInfo::hostOs()) {
case HostOsInfo::HostOsLinux:
case OsTypeLinux:
hostPatterns << QLatin1String("linux*");
break;
case HostOsInfo::HostOsWindows:
case OsTypeWindows:
hostPatterns << QLatin1String("windows*");
break;
case HostOsInfo::HostOsMac:
case OsTypeMac:
hostPatterns << QLatin1String("darwin*");
break;
default: /* unknown host */ return;
......
......@@ -67,13 +67,13 @@ LibraryDetailsController::LibraryDetailsController(
m_libraryDetailsWidget(libraryDetails)
{
switch (Utils::HostOsInfo::hostOs()) {
case Utils::HostOsInfo::HostOsMac:
case Utils::OsTypeMac:
m_creatorPlatform = CreatorMac;
break;
case Utils::HostOsInfo::HostOsLinux:
case Utils::OsTypeLinux:
m_creatorPlatform = CreatorLinux;
break;
case Utils::HostOsInfo::HostOsWindows:
case Utils::OsTypeWindows:
m_creatorPlatform = CreatorWindows;
break;
default:
......
......@@ -286,10 +286,10 @@ void WelcomeMode::initPlugins()
QString WelcomeMode::platform() const
{
switch (HostOsInfo::hostOs()) {
case HostOsInfo::HostOsWindows: return QLatin1String("windows");
case HostOsInfo::HostOsMac: return QLatin1String("mac");
case HostOsInfo::HostOsLinux: return QLatin1String("linux");
case HostOsInfo::HostOsOtherUnix: return QLatin1String("unix");
case OsTypeWindows: return QLatin1String("windows");
case OsTypeMac: return QLatin1String("mac");
case OsTypeLinux: return QLatin1String("linux");
case OsTypeOtherUnix: return QLatin1String("unix");
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