forked from qt-creator/qt-creator
Utils: Introduce HostOsInfo class.
The class' member functions are intended to be used instead of the Q_OS_* macros in all contexts where the latter are not syntactically required. This lowers the likelihood of changes made on one platform breaking the build on another, e.g. due to the code model missing symbols in #ifdef'ed out code when refactoring. Change-Id: I4a54788591b4c8f8d589b8368a6c683d4155c9fa Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -29,6 +29,8 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "synchronousprocess.h"
|
||||
|
||||
#include "hostosinfo.h"
|
||||
#include <qtcassert.h>
|
||||
|
||||
#include <QDebug>
|
||||
@@ -599,18 +601,6 @@ bool SynchronousProcess::stopProcess(QProcess &p)
|
||||
|
||||
// Path utilities
|
||||
|
||||
enum OS_Type { OS_Mac, OS_Windows, OS_Unix };
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
static const OS_Type pathOS = OS_Windows;
|
||||
#else
|
||||
# ifdef Q_OS_MAC
|
||||
static const OS_Type pathOS = OS_Mac;
|
||||
# else
|
||||
static const OS_Type pathOS = OS_Unix;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Locate a binary in a directory, applying all kinds of
|
||||
// extensions the operating system supports.
|
||||
static QString checkBinary(const QDir &dir, const QString &binary)
|
||||
@@ -622,16 +612,18 @@ static QString checkBinary(const QDir &dir, const QString &binary)
|
||||
|
||||
// Does the OS have some weird extension concept or does the
|
||||
// binary have a 3 letter extension?
|
||||
if (pathOS == OS_Unix)
|
||||
if (HostOsInfo::isAnyUnixHost() && !HostOsInfo::isMacHost())
|
||||
return QString();
|
||||
const int dotIndex = binary.lastIndexOf(QLatin1Char('.'));
|
||||
if (dotIndex != -1 && dotIndex == binary.size() - 4)
|
||||
return QString();
|
||||
|
||||
switch (pathOS) {
|
||||
case OS_Unix:
|
||||
switch (HostOsInfo::hostOs()) {
|
||||
case HostOsInfo::HostOsLinux:
|
||||
case HostOsInfo::HostOsOtherUnix:
|
||||
case HostOsInfo::HostOsOther:
|
||||
break;
|
||||
case OS_Windows: {
|
||||
case HostOsInfo::HostOsWindows: {
|
||||
static const char *windowsExtensions[] = {".cmd", ".bat", ".exe", ".com" };
|
||||
// Check the Windows extensions using the order
|
||||
const int windowsExtensionCount = sizeof(windowsExtensions)/sizeof(const char*);
|
||||
@@ -642,7 +634,7 @@ static QString checkBinary(const QDir &dir, const QString &binary)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OS_Mac: {
|
||||
case HostOsInfo::HostOsMac: {
|
||||
// Check for Mac app folders
|
||||
const QFileInfo appFolder(dir.filePath(binary + QLatin1String(".app")));
|
||||
if (appFolder.isDir()) {
|
||||
@@ -667,7 +659,7 @@ QString SynchronousProcess::locateBinary(const QString &path, const QString &bin
|
||||
return checkBinary(absInfo.dir(), absInfo.fileName());
|
||||
|
||||
// Windows finds binaries in the current directory
|
||||
if (pathOS == OS_Windows) {
|
||||
if (HostOsInfo::isWindowsHost()) {
|
||||
const QString currentDirBinary = checkBinary(QDir::current(), binary);
|
||||
if (!currentDirBinary.isEmpty())
|
||||
return currentDirBinary;
|
||||
@@ -694,9 +686,7 @@ QString SynchronousProcess::locateBinary(const QString &binary)
|
||||
|
||||
QChar SynchronousProcess::pathSeparator()
|
||||
{
|
||||
if (pathOS == OS_Windows)
|
||||
return QLatin1Char(';');
|
||||
return QLatin1Char(':');
|
||||
return HostOsInfo::isWindowsHost() ? QLatin1Char(';') : QLatin1Char(':');
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
Reference in New Issue
Block a user