Commit c6a02170 authored by dt's avatar dt
Browse files

Fixes: Move Buildparser to the projectexplorer, use in cmakeplugin

Details:  This enables us to parse the build errors correctly.
          The makesteps of the qt4project and cmakeproject have some
          code dupliaction, which could be refactored. And the code
          to find out the correct build parser could probably also
          be done better, but we are now parsing the build output for
          cmake.
parent 9cb61560
......@@ -40,6 +40,7 @@
#include "cmakestep.h"
#include "makestep.h"
#include <projectexplorer/projectexplorerconstants.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
......@@ -103,7 +104,7 @@ void CMakeProject::parseCMakeLists()
} else {
// TODO hmm?
}
if (newToolChain == m_toolChain) {
if (ProjectExplorer::ToolChain::equals(newToolChain, m_toolChain)) {
delete newToolChain;
newToolChain = 0;
} else {
......@@ -158,6 +159,21 @@ void CMakeProject::parseCMakeLists()
}
}
QString CMakeProject::buildParser(const QString &buildConfiguration) const
{
if (!m_toolChain)
return QString::null;
if (m_toolChain->type() == ProjectExplorer::ToolChain::GCC
|| m_toolChain->type() == ProjectExplorer::ToolChain::LinuxICC
|| m_toolChain->type() == ProjectExplorer::ToolChain::MinGW) {
return ProjectExplorer::Constants::BUILD_PARSER_GCC;
} else if (m_toolChain->type() == ProjectExplorer::ToolChain::MSVC
|| m_toolChain->type() == ProjectExplorer::ToolChain::WINCE) {
return ProjectExplorer::Constants::BUILD_PARSER_MSVC;
}
return QString::null;
}
QStringList CMakeProject::targets() const
{
QStringList results;
......
......@@ -105,6 +105,7 @@ public:
MakeStep *makeStep() const;
CMakeStep *cmakeStep() const;
QStringList targets() const;
QString buildParser(const QString &buildConfiguration) const;
private:
void parseCMakeLists();
......
......@@ -34,6 +34,7 @@
#include "makestep.h"
#include "cmakeprojectconstants.h"
#include "cmakeproject.h"
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
#include <QtGui/QFormLayout>
......@@ -42,6 +43,11 @@
#include <QtGui/QLineEdit>
#include <QtGui/QListWidget>
namespace {
bool debug = false;
}
using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;
......@@ -52,10 +58,42 @@ MakeStep::MakeStep(CMakeProject *pro)
MakeStep::~MakeStep()
{
delete m_buildParser;
m_buildParser = 0;
}
bool MakeStep::init(const QString &buildConfiguration)
{
// TODO figure out the correct build parser
delete m_buildParser;
m_buildParser = 0;
QString buildParser = m_pro->buildParser(buildConfiguration);
QList<ProjectExplorer::IBuildParserFactory *> buildParserFactories =
ExtensionSystem::PluginManager::instance()->getObjects<ProjectExplorer::IBuildParserFactory>();
foreach (ProjectExplorer::IBuildParserFactory * factory, buildParserFactories)
if (factory->canCreate(buildParser)) {
m_buildParser = factory->create(buildParser);
break;
}
if (m_buildParser) {
connect(m_buildParser, SIGNAL(addToOutputWindow(const QString &)),
this, SIGNAL(addToOutputWindow(const QString &)),
Qt::DirectConnection);
connect(m_buildParser, SIGNAL(addToTaskWindow(const QString &, int, int, const QString &)),
this, SLOT(slotAddToTaskWindow(const QString &, int, int, const QString &)),
Qt::DirectConnection);
connect(m_buildParser, SIGNAL(enterDirectory(const QString &)),
this, SLOT(addDirectory(const QString &)),
Qt::DirectConnection);
connect(m_buildParser, SIGNAL(leaveDirectory(const QString &)),
this, SLOT(removeDirectory(const QString &)),
Qt::DirectConnection);
}
m_openDirectories.clear();
addDirectory(m_pro->buildDirectory(buildConfiguration));
setEnabled(buildConfiguration, true);
setWorkingDirectory(buildConfiguration, m_pro->buildDirectory(buildConfiguration));
setCommand(buildConfiguration, "make"); // TODO give full path here?
......@@ -89,6 +127,79 @@ bool MakeStep::immutable() const
return true;
}
void MakeStep::stdOut(const QString &line)
{
if (m_buildParser)
m_buildParser->stdOutput(line);
AbstractProcessStep::stdOut(line);
}
void MakeStep::stdError(const QString &line)
{
if (m_buildParser)
m_buildParser->stdError(line);
AbstractProcessStep::stdError(line);
}
void MakeStep::slotAddToTaskWindow(const QString & fn, int type, int linenumber, const QString & description)
{
QString filePath = fn;
if (!filePath.isEmpty() && !QDir::isAbsolutePath(filePath)) {
// We have no save way to decide which file in which subfolder
// is meant. Therefore we apply following heuristics:
// 1. Search for unique file in directories currently indicated as open by GNU make
// (Enter directory xxx, Leave directory xxx...) + current directory
// 3. Check if file is unique in whole project
// 4. Otherwise give up
filePath = filePath.trimmed();
QList<QFileInfo> possibleFiles;
foreach (const QString &dir, m_openDirectories) {
QFileInfo candidate(dir + QLatin1Char('/') + filePath);
if (debug)
qDebug() << "Checking path " << candidate.filePath();
if (candidate.exists()
&& !possibleFiles.contains(candidate)) {
if (debug)
qDebug() << candidate.filePath() << "exists!";
possibleFiles << candidate;
}
}
if (possibleFiles.count() == 0) {
if (debug)
qDebug() << "No success. Trying all files in project ...";
QString fileName = QFileInfo(filePath).fileName();
foreach (const QString &file, project()->files(ProjectExplorer::Project::AllFiles)) {
QFileInfo candidate(file);
if (candidate.fileName() == fileName) {
if (debug)
qDebug() << "Found " << file;
possibleFiles << candidate;
}
}
}
if (possibleFiles.count() == 1)
filePath = possibleFiles.first().filePath();
else
qWarning() << "Could not find absolute location of file " << filePath;
}
emit addToTaskWindow(filePath, type, linenumber, description);
}
void MakeStep::addDirectory(const QString &dir)
{
if (!m_openDirectories.contains(dir))
m_openDirectories.insert(dir);
}
void MakeStep::removeDirectory(const QString &dir)
{
if (m_openDirectories.contains(dir))
m_openDirectories.remove(dir);
}
CMakeProject *MakeStep::project() const
{
return m_pro;
......@@ -154,7 +265,6 @@ void MakeBuildStepConfigWidget::init(const QString &buildConfiguration)
}
// and connect again
connect(m_targetsList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
}
//
......
......@@ -64,8 +64,17 @@ public:
CMakeProject *project() const;
bool buildsTarget(const QString &buildConfiguration, const QString &target) const;
void setBuildTarget(const QString &buildConfiguration, const QString &target, bool on);
private slots:
void slotAddToTaskWindow(const QString & fn, int type, int linenumber, const QString & description);
void addDirectory(const QString &dir);
void removeDirectory(const QString &dir);
protected:
virtual void stdOut(const QString &line);
virtual void stdError(const QString &line);
private:
CMakeProject *m_pro;
ProjectExplorer::BuildParserInterface *m_buildParser;
QSet<QString> m_openDirectories;
};
class MakeBuildStepConfigWidget :public ProjectExplorer::BuildStepConfigWidget
......
......@@ -33,11 +33,11 @@
#include "buildparserfactory.h"
#include "qt4projectmanagerconstants.h"
#include "projectexplorerconstants.h"
#include "gccparser.h"
#include "msvcparser.h"
using namespace Qt4ProjectManager::Internal;
using namespace ProjectExplorer::Internal;
GccParserFactory::~GccParserFactory()
{
......
......@@ -36,14 +36,14 @@
#include <projectexplorer/buildparserinterface.h>
namespace Qt4ProjectManager {
namespace ProjectExplorer {
namespace Internal {
class GccParserFactory : public ProjectExplorer::IBuildParserFactory
{
Q_OBJECT
public:
GccParserFactory() {};
GccParserFactory() {}
virtual ~GccParserFactory();
virtual bool canCreate(const QString & name) const;
virtual ProjectExplorer::BuildParserInterface * create(const QString & name) const;
......@@ -53,13 +53,13 @@ class MsvcParserFactory : public ProjectExplorer::IBuildParserFactory
{
Q_OBJECT
public:
MsvcParserFactory() {};
MsvcParserFactory() {}
virtual ~MsvcParserFactory();
virtual bool canCreate(const QString & name) const;
virtual ProjectExplorer::BuildParserInterface * create(const QString & name) const;
};
} // namespace Internal
} // namespace Qt4ProjectManager
} // namespace ProjectExplorer
#endif // BUILDPARSERFACTORY_H
......@@ -32,11 +32,11 @@
***************************************************************************/
#include "gccparser.h"
#include "qt4projectmanagerconstants.h"
#include "projectexplorerconstants.h"
#include <QDebug>
using namespace Qt4ProjectManager;
using namespace ProjectExplorer;
GccParser::GccParser()
{
......@@ -56,7 +56,7 @@ GccParser::GccParser()
QString GccParser::name() const
{
return QLatin1String(Qt4ProjectManager::Constants::BUILD_PARSER_GCC);
return QLatin1String(ProjectExplorer::Constants::BUILD_PARSER_GCC);
}
void GccParser::stdOutput(const QString & line)
......
......@@ -34,11 +34,11 @@
#ifndef GCCPARSER_H
#define GCCPARSER_H
#include <projectexplorer/buildparserinterface.h>
#include "buildparserinterface.h"
#include <QtCore/QRegExp>
namespace Qt4ProjectManager {
namespace ProjectExplorer {
class GccParser : public ProjectExplorer::BuildParserInterface
{
......
......@@ -32,11 +32,11 @@
***************************************************************************/
#include "msvcparser.h"
#include "qt4projectmanagerconstants.h"
#include "projectexplorerconstants.h"
#include <QtCore/QStringList>
using namespace Qt4ProjectManager;
using namespace ProjectExplorer;
MsvcParser::MsvcParser()
{
......@@ -48,7 +48,7 @@ MsvcParser::MsvcParser()
QString MsvcParser::name() const
{
return QLatin1String(Qt4ProjectManager::Constants::BUILD_PARSER_MSVC);
return QLatin1String(ProjectExplorer::Constants::BUILD_PARSER_MSVC);
}
void MsvcParser::stdError(const QString & line)
......
......@@ -34,11 +34,11 @@
#ifndef MSVCPARSER_H
#define MSVCPARSER_H
#include <projectexplorer/buildparserinterface.h>
#include "buildparserinterface.h"
#include <QtCore/QRegExp>
namespace Qt4ProjectManager {
namespace ProjectExplorer {
class MsvcParser : public ProjectExplorer::BuildParserInterface
{
......
......@@ -59,6 +59,7 @@
#include "scriptwrappers.h"
#include "session.h"
#include "sessiondialog.h"
#include "buildparserfactory.h"
#include <coreplugin/basemode.h>
#include <coreplugin/coreconstants.h>
......@@ -233,6 +234,10 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
addAutoReleasedObject(new ProjectFileWizardExtension);
// Build parsers
addAutoReleasedObject(new GccParserFactory);
addAutoReleasedObject(new MsvcParserFactory);
// context menus
Core::ActionContainer *msessionContextMenu =
am->createMenu(Constants::M_SESSIONCONTEXT);
......
......@@ -54,7 +54,10 @@ HEADERS += projectexplorer.h \
projectmodels.h \
currentprojectfind.h \
toolchain.h \
cesdkhandler.h
cesdkhandler.h\
buildparserfactory.h\
gccparser.h\
msvcparser.h
SOURCES += projectexplorer.cpp \
projectwindow.cpp \
buildmanager.cpp \
......@@ -97,7 +100,10 @@ SOURCES += projectexplorer.cpp \
projectmodels.cpp \
currentprojectfind.cpp \
toolchain.cpp \
cesdkhandler.cpp
cesdkhandler.cpp\
buildparserfactory.cpp \
gccparser.cpp\
msvcparser.cpp
FORMS += dependenciespanel.ui \
buildsettingspropertiespage.ui \
processstep.ui \
......
......@@ -176,6 +176,11 @@ const char * const CPP_HEADER_MIMETYPE = "text/x-c++hdr";
const char * const FORM_MIMETYPE = "application/x-designer";
const char * const RESOURCE_MIMETYPE = "application/vnd.nokia.xml.qt.resource";
// build parsers
const char * const BUILD_PARSER_MSVC = "BuildParser.MSVC";
const char * const BUILD_PARSER_GCC = "BuildParser.Gcc";
} // namespace Constants
} // namespace ProjectExplorer
......
......@@ -36,6 +36,8 @@
#include "qt4project.h"
#include "qt4projectmanagerconstants.h"
#include <projectexplorer/projectexplorerconstants.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
......@@ -71,9 +73,9 @@ ProjectExplorer::BuildParserInterface *MakeStep::buildParser(const QtVersion * c
QString buildParser;
ProjectExplorer::ToolChain::ToolChainType type = version->toolchainType();
if ( type == ProjectExplorer::ToolChain::MSVC || type == ProjectExplorer::ToolChain::WINCE)
buildParser = Constants::BUILD_PARSER_MSVC;
buildParser = ProjectExplorer::Constants::BUILD_PARSER_MSVC;
else
buildParser = Constants::BUILD_PARSER_GCC;
buildParser = ProjectExplorer::Constants::BUILD_PARSER_GCC;
QList<IBuildParserFactory *> buildParserFactories =
ExtensionSystem::PluginManager::instance()->getObjects<ProjectExplorer::IBuildParserFactory>();
......
......@@ -28,9 +28,6 @@ HEADERS = qt4projectmanagerplugin.h \
makestep.h \
qmakestep.h \
qmakebuildstepfactory.h \
gccparser.h \
msvcparser.h \
buildparserfactory.h \
deployhelper.h \
embeddedpropertiespage.h \
qt4runconfiguration.h \
......@@ -63,9 +60,6 @@ SOURCES = qt4projectmanagerplugin.cpp \
makestep.cpp \
qmakestep.cpp \
qmakebuildstepfactory.cpp \
gccparser.cpp \
msvcparser.cpp \
buildparserfactory.cpp \
deployhelper.cpp \
embeddedpropertiespage.cpp \
qt4runconfiguration.cpp \
......
......@@ -79,10 +79,6 @@ const char * const GDBMACROSBUILDSTEP = "trolltech.qt4projectmanager.gdbmaros";
const char * const QT4RUNSTEP = "trolltech.qt4projectmanager.qt4runstep";
const char * const DEPLOYHELPERRUNSTEP = "trolltech.qt4projectmanager.deployhelperrunstep";
// build parsers
const char * const BUILD_PARSER_MSVC = "BuildParser.MSVC";
const char * const BUILD_PARSER_GCC = "BuildParser.Gcc";
// views
const char * const VIEW_DETAILED = "Qt4.View.Detailed";
const char * const VIEW_PROFILESONLY = "Qt4.View.ProjectHierarchy";
......
......@@ -41,7 +41,6 @@
#include "qt4projectmanagerconstants.h"
#include "qt4project.h"
#include "qmakebuildstepfactory.h"
#include "buildparserfactory.h"
#include "qtversionmanager.h"
#include "embeddedpropertiespage.h"
#include "qt4runconfiguration.h"
......@@ -133,9 +132,6 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *
addAutoReleasedObject(new MakeBuildStepFactory);
addAutoReleasedObject(new GdbMacrosBuildStepFactory);
addAutoReleasedObject(new GccParserFactory);
addAutoReleasedObject(new MsvcParserFactory);
m_qtVersionManager = new QtVersionManager;
addObject(m_qtVersionManager);
......
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