Commit 15e2ac46 authored by dt's avatar dt
Browse files

Fixes: Add ToolChain classes.

Details:  These classes replace a number of classes with differing
interfaces by just one class. The design isn't quite perfect, but a lot
better than what it used to be. Also moved the ToolChain classes to the
projectexplorerm so that eventually the cmake plugin can also use them.
parent a7cda431
......@@ -37,7 +37,7 @@
#include <QtCore/QDebug>
#include <QtCore/QXmlStreamReader>
using namespace Qt4ProjectManager::Internal;
using namespace ProjectExplorer::Internal;
using ProjectExplorer::Environment;
CeSdkInfo::CeSdkInfo()
......@@ -45,15 +45,13 @@ CeSdkInfo::CeSdkInfo()
{
}
Environment CeSdkInfo::addToEnvironment(const Environment &env)
void CeSdkInfo::addToEnvironment(Environment &env)
{
qDebug() << "adding " << name() << "to Environment";
Environment e(env);
e.set("INCLUDE", m_include);
e.set("LIB", m_lib);
e.prependOrSetPath(m_bin);
env.set("INCLUDE", m_include);
env.set("LIB", m_lib);
env.prependOrSetPath(m_bin);
qDebug()<<e.toStringList();
return e;
}
CeSdkHandler::CeSdkHandler()
......
......@@ -42,8 +42,7 @@
#define VCINSTALL_MACRO "$(VCInstallDir)"
#define VSINSTALL_MACRO "$(VSInstallDir)"
namespace Qt4ProjectManager {
namespace Internal {
namespace ProjectExplorer {
class CeSdkInfo
{
......@@ -53,7 +52,7 @@ public:
inline QString binPath();
inline QString includePath();
inline QString libPath();
ProjectExplorer::Environment addToEnvironment(const ProjectExplorer::Environment &env);
void addToEnvironment(ProjectExplorer::Environment &env);
inline bool isValid();
inline int majorVersion();
inline int minorVersion();
......@@ -102,7 +101,6 @@ inline QString CeSdkHandler::fixPaths(QString path) const
return QDir::toNativeSeparators(QDir::cleanPath(path.replace(VCINSTALL_MACRO, VCInstallDir).replace(VSINSTALL_MACRO, VSInstallDir).replace(QLatin1String(";$(PATH)"), QLatin1String(""))));
}
} // namespace Internal
} // namespace Qt4ProjectManager
#endif // CE_SDK_HANDLER_H
......@@ -52,7 +52,8 @@ HEADERS += projectexplorer.h \
removefiledialog.h \
nodesvisitor.h \
projectmodels.h \
currentprojectfind.h
currentprojectfind.h \
toolchain.h
SOURCES += projectexplorer.cpp \
projectwindow.cpp \
buildmanager.cpp \
......@@ -93,7 +94,8 @@ SOURCES += projectexplorer.cpp \
removefiledialog.cpp \
nodesvisitor.cpp \
projectmodels.cpp \
currentprojectfind.cpp
currentprojectfind.cpp \
toolchain.cpp
FORMS += dependenciespanel.ui \
buildsettingspropertiespage.ui \
processstep.ui \
......
#include "toolchain.h"
#include "cesdkhandler.h"
#include <QtCore/QFileInfo>
#include <QtCore/QProcess>
#include <QtCore/QDebug>
#include <QtCore/QSettings>
#include <QtCore/QDir>
#include <QtCore/QTemporaryFile>
#include <QtCore/QString>
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;
bool ToolChain::equals(ToolChain *a, ToolChain *b)
{
if (a == b)
return true;
if (a == 0 || b == 0)
return false;
if (a->type() == b->type())
a->equals(b);
}
ToolChain::ToolChain()
{
}
ToolChain::~ToolChain()
{
}
ToolChain *ToolChain::createGccToolChain(const QString &gcc)
{
return new GccToolChain(gcc);
}
ToolChain *ToolChain::createMinGWToolChain(const QString &gcc, const QString &mingwPath)
{
return new MinGWToolChain(gcc, mingwPath);
}
ToolChain *ToolChain::createMSVCToolChain(const QString &name)
{
return new MSVCToolChain(name);
}
ToolChain *ToolChain::createWinCEToolChain(const QString &name, const QString &platform)
{
return new WinCEToolChain(name, platform);
}
QStringList ToolChain::availableMSVCVersions()
{
QSettings registry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7",
QSettings::NativeFormat);
QStringList versions = registry.allKeys();
return versions;
}
GccToolChain::GccToolChain(const QString &gcc)
: m_gcc(gcc)
{
}
ToolChain::ToolChainType GccToolChain::type() const
{
return ToolChain::GCC;
}
QByteArray GccToolChain::predefinedMacros()
{
if (m_predefinedMacros.isEmpty()) {
QStringList arguments;
arguments << QLatin1String("-xc++")
<< QLatin1String("-E")
<< QLatin1String("-dM")
<< QLatin1String("-");
QProcess cpp;
cpp.start(m_gcc, arguments);
cpp.closeWriteChannel();
cpp.waitForFinished();
m_predefinedMacros = cpp.readAllStandardOutput();
}
return m_predefinedMacros;
}
QList<HeaderPath> GccToolChain::systemHeaderPaths()
{
if (m_systemHeaderPaths.isEmpty()) {
QStringList arguments;
arguments << QLatin1String("-xc++")
<< QLatin1String("-E")
<< QLatin1String("-v")
<< QLatin1String("-");
QProcess cpp;
cpp.setReadChannelMode(QProcess::MergedChannels);
cpp.start(m_gcc, arguments);
cpp.closeWriteChannel();
cpp.waitForFinished();
QByteArray line;
while (cpp.canReadLine()) {
line = cpp.readLine();
if (line.startsWith("#include"))
break;
}
if (! line.isEmpty() && line.startsWith("#include")) {
HeaderPath::Kind kind = HeaderPath::UserHeaderPath;
while (cpp.canReadLine()) {
line = cpp.readLine();
if (line.startsWith("#include")) {
kind = HeaderPath::GlobalHeaderPath;
} else if (! line.isEmpty() && QChar(line.at(0)).isSpace()) {
HeaderPath::Kind thisHeaderKind = kind;
line = line.trimmed();
if (line.endsWith('\n'))
line.chop(1);
int index = line.indexOf(" (framework directory)");
if (index != -1) {
line = line.left(index);
thisHeaderKind = HeaderPath::FrameworkHeaderPath;
}
m_systemHeaderPaths.append(HeaderPath(QFile::decodeName(line), thisHeaderKind));
} else if (line.startsWith("End of search list.")) {
break;
} else {
qWarning() << "ignore line:" << line;
}
}
}
}
return m_systemHeaderPaths;
}
void GccToolChain::addToEnvironment(ProjectExplorer::Environment &env)
{
Q_UNUSED(env)
}
bool GccToolChain::equals(ToolChain *other) const
{
return (m_gcc == static_cast<GccToolChain *>(other)->m_gcc);
}
MinGWToolChain::MinGWToolChain(const QString &gcc, const QString &mingwPath)
: GccToolChain(gcc), m_mingwPath(mingwPath)
{
}
ToolChain::ToolChainType MinGWToolChain::type() const
{
return ToolChain::MinGW;
}
bool MinGWToolChain::equals(ToolChain *other) const
{
MinGWToolChain *o = static_cast<MinGWToolChain *>(other);
return (m_mingwPath == o->m_mingwPath && this->GccToolChain::equals(other));
}
void MinGWToolChain::addToEnvironment(ProjectExplorer::Environment &env)
{
QString binDir = m_mingwPath + "/bin";
if (QFileInfo(binDir).exists())
env.prependOrSetPath(binDir);
}
MSVCToolChain::MSVCToolChain(const QString &name)
: m_name(name), m_valuesSet(false)
{
}
ToolChain::ToolChainType MSVCToolChain::type() const
{
return ToolChain::MSVC;
}
bool MSVCToolChain::equals(ToolChain *other) const
{
MSVCToolChain *o = static_cast<MSVCToolChain *>(other);
return (m_name == o->m_name);
}
QByteArray MSVCToolChain::predefinedMacros()
{
return "#define __WIN32__\n"
"#define __WIN32\n"
"#define _WIN32\n"
"#define WIN32\n"
"#define __WINNT__\n"
"#define __WINNT\n"
"#define WINNT\n"
"#define _X86_\n"
"#define __MSVCRT__\n";
}
QList<HeaderPath> MSVCToolChain::systemHeaderPaths()
{
//TODO fix this code
ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
addToEnvironment(env);
#ifdef QTCREATOR_WITH_MSVC_INCLUDES
return env.value("INCLUDE").split(QLatin1Char(';'));
#endif
return QList<HeaderPath>();
}
void MSVCToolChain::addToEnvironment(ProjectExplorer::Environment &env)
{
if (!m_valuesSet) {
QSettings registry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7",
QSettings::NativeFormat);
QString path = registry.value(m_name).toString();
ProjectExplorer::Environment oldEnv(env);
QString desc;
QString varsbat = path + "Common7\\Tools\\vsvars32.bat";
if (QFileInfo(varsbat).exists()) {
QTemporaryFile tf(QDir::tempPath() + "\\XXXXXX.bat");
if (!tf.open())
return;
QString filename = tf.fileName();
tf.write("call \"" + varsbat.toLocal8Bit()+"\"\r\n");
tf.write(("set > \"" + QDir::tempPath() + "\\qtcreator-msvc-environment.txt\"\r\n").toLocal8Bit());
tf.flush();
tf.waitForBytesWritten(30000);
QProcess run;
QString cmdPath = env.searchInPath("cmd");
run.start(cmdPath, QStringList()<<"/c"<<filename);
run.waitForFinished();
tf.close();
QFile vars(QDir::tempPath() + "\\qtcreator-msvc-environment.txt");
if (vars.exists() && vars.open(QIODevice::ReadOnly)) {
while (!vars.atEnd()) {
QByteArray line = vars.readLine();
QString line2 = QString::fromLocal8Bit(line);
line2 = line2.trimmed();
QRegExp regexp("(\\w*)=(.*)");
if (regexp.exactMatch(line2)) {
QString variable = regexp.cap(1);
QString value = regexp.cap(2);
value.replace('%' + variable + '%', oldEnv.value(variable));
m_values.append(QPair<QString, QString>(variable, value));
}
}
vars.close();
vars.remove();
}
}
m_valuesSet = true;
}
QList< QPair<QString, QString> >::const_iterator it, end;
end = m_values.constEnd();
for (it = m_values.constBegin(); it != end; ++it) {
env.set((*it).first, (*it).second);
qDebug()<<"variable:"<<(*it).first<<"value:"<<(*it).second;
}
}
WinCEToolChain::WinCEToolChain(const QString &name, const QString &platform)
: MSVCToolChain(name), m_platform(platform)
{
}
ToolChain::ToolChainType WinCEToolChain::type() const
{
return ToolChain::WINCE;
}
bool WinCEToolChain::equals(ToolChain *other) const
{
WinCEToolChain *o = static_cast<WinCEToolChain *>(other);
return (m_platform == o->m_platform && this->MSVCToolChain::equals(other));
}
QByteArray WinCEToolChain::predefinedMacros()
{
//TODO
return MSVCToolChain::predefinedMacros();
}
QList<HeaderPath> WinCEToolChain::systemHeaderPaths()
{
//TODO fix this code
ProjectExplorer::Environment env = ProjectExplorer::Environment::systemEnvironment();
addToEnvironment(env);
#ifdef QTCREATOR_WITH_MSVC_INCLUDES
return env.value("INCLUDE").split(QLatin1Char(';'));
#endif
}
void WinCEToolChain::addToEnvironment(ProjectExplorer::Environment &env)
{
MSVCToolChain::addToEnvironment(env);
QSettings registry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7",
QSettings::NativeFormat);
QString path = registry.value(m_name).toString();
// Find MSVC path
path += "/";
// qDebug()<<"MSVC path"<<msvcPath;
// qDebug()<<"looking for platform name in"<< path() + "/mkspecs/" + mkspec() +"/qmake.conf";
// Find Platform name
// qDebug()<<"Platform Name"<<platformName;
CeSdkHandler cesdkhandler;
cesdkhandler.parse(path);
cesdkhandler.find(m_platform).addToEnvironment(env);
}
#ifndef TOOLCHAIN_H
#define TOOLCHAIN_H
#include "environment.h"
#include <QtCore/QString>
#include <QtCore/QPair>
namespace ProjectExplorer {
class PROJECTEXPLORER_EXPORT HeaderPath
{
public:
enum Kind {
GlobalHeaderPath,
UserHeaderPath,
FrameworkHeaderPath
};
HeaderPath()
: _kind(GlobalHeaderPath)
{ }
HeaderPath(const QString &path, Kind kind)
: _path(path), _kind(kind)
{ }
QString path() const { return _path; }
Kind kind() const { return _kind; }
private:
QString _path;
Kind _kind;
};
class PROJECTEXPLORER_EXPORT ToolChain
{
public:
enum ToolChainType
{
GCC,
MinGW,
MSVC,
WINCE,
OTHER,
INVALID
};
virtual QByteArray predefinedMacros() = 0;
virtual QList<HeaderPath> systemHeaderPaths() = 0;
virtual void addToEnvironment(ProjectExplorer::Environment &env) = 0;
virtual ToolChainType type() const = 0;
ToolChain();
virtual ~ToolChain();
static bool equals(ToolChain *, ToolChain *);
static ToolChain *createGccToolChain(const QString &gcc);
static ToolChain *createMinGWToolChain(const QString &gcc, const QString &mingwPath);
static ToolChain *createMSVCToolChain(const QString &name);
static ToolChain *createWinCEToolChain(const QString &name, const QString &platform);
static QStringList availableMSVCVersions();
protected:
virtual bool equals(ToolChain *other) const = 0;
};
namespace Internal {
class GccToolChain : public ToolChain
{
public:
GccToolChain(const QString &gcc);
virtual QByteArray predefinedMacros();
virtual QList<HeaderPath> systemHeaderPaths();
virtual void addToEnvironment(ProjectExplorer::Environment &env);
virtual ToolChainType type() const;
protected:
virtual bool equals(ToolChain *other) const;
private:
QString m_gcc;
QByteArray m_predefinedMacros;
QList<HeaderPath> m_systemHeaderPaths;
};
// TODO this class needs to fleshed out more
class MinGWToolChain : public GccToolChain
{
public:
MinGWToolChain(const QString &gcc, const QString &mingwPath);
virtual void addToEnvironment(ProjectExplorer::Environment &env);
virtual ToolChainType type() const;
protected:
virtual bool equals(ToolChain *other) const;
private:
QString m_mingwPath;
};
// TODO some stuff needs to be moved into this
class MSVCToolChain : public ToolChain
{
public:
MSVCToolChain(const QString &name);
virtual QByteArray predefinedMacros();
virtual QList<HeaderPath> systemHeaderPaths();
virtual void addToEnvironment(ProjectExplorer::Environment &env);
virtual ToolChainType type() const;
protected:
virtual bool equals(ToolChain *other) const;
QString m_name;
private:
mutable QList<QPair<QString, QString> > m_values;
mutable bool m_valuesSet;
};
// TODO some stuff needs to be moved into here
class WinCEToolChain : public MSVCToolChain
{
public:
WinCEToolChain(const QString &name, const QString &platform);
virtual QByteArray predefinedMacros();
virtual QList<HeaderPath> systemHeaderPaths();
virtual void addToEnvironment(ProjectExplorer::Environment &env);
virtual ToolChainType type() const;
protected:
virtual bool equals(ToolChain *other) const;
private:
QString m_platform;
};
}
}
#endif // TOOLCHAIN_H
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "gccpreprocessor.h"
#include <QProcess>
#include <QString>
#include <QFile>
#include <QtDebug>
using namespace Qt4ProjectManager::Internal;
GCCPreprocessor::GCCPreprocessor(const QString &gcc)
: m_gcc(gcc)
{ }
GCCPreprocessor::~GCCPreprocessor()
{ }
void GCCPreprocessor::setGcc(const QString &gcc)
{
if (m_gcc == gcc)
return;
m_gcc = gcc;
m_predefinedMacros.clear();;
m_systemHeaderPaths.clear();;
}
QByteArray GCCPreprocessor::predefinedMacros()