From 05f60dcd1439dcf12525b247f65d86618e59b6b4 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Sun, 19 Jun 2011 17:54:32 +0300 Subject: [PATCH] * Build current file --- src/plugins/projectexplorer/abstractprocessstep.h | 3 + src/plugins/projectexplorer/projectexplorer.cpp | 88 ++++++++++++++++++++ src/plugins/projectexplorer/projectexplorer.h | 1 + .../projectexplorer/projectexplorerconstants.h | 1 + 4 files changed, 93 insertions(+), 0 deletions(-) diff --git a/src/plugins/projectexplorer/abstractprocessstep.h b/src/plugins/projectexplorer/abstractprocessstep.h index 69f0c36..fd3e8a1 100644 --- a/src/plugins/projectexplorer/abstractprocessstep.h +++ b/src/plugins/projectexplorer/abstractprocessstep.h @@ -108,6 +108,9 @@ public: /// Append the given output parser to the existing chain of parsers. void appendOutputParser(ProjectExplorer::IOutputParser *parser); ProjectExplorer::IOutputParser *outputParser() const; + virtual QString userArguments() { return QString(); } + virtual void setUserArguments(const QString & /*arguments*/) {} + protected: AbstractProcessStep(BuildStepList *bsl, const QString &id); diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index bc95a6e..6386108 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -160,6 +160,7 @@ struct ProjectExplorerPluginPrivate { QAction *m_buildProjectOnlyAction; Utils::ParameterAction *m_buildAction; Utils::ParameterAction *m_buildActionContextMenu; + Utils::ParameterAction *m_buildFileAction; QAction *m_buildSessionAction; QAction *m_rebuildProjectOnlyAction; Utils::ParameterAction *m_rebuildAction; @@ -212,6 +213,7 @@ struct ProjectExplorerPluginPrivate { RunConfiguration *m_delayedRunConfiguration; // TODO this is not right QString m_runMode; QString m_projectFilterString; + QString m_currentFile; Internal::MiniProjectTargetSelector * m_targetSelector; Internal::ProjectExplorerSettings m_projectExplorerSettings; Internal::ProjectWelcomePage *m_welcomePage; @@ -662,6 +664,15 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+B"))); mbuild->addAction(cmd, Constants::G_BUILD_PROJECT); + // build current file action + d->m_buildFileAction = new Utils::ParameterAction(tr("Build Current File"), tr("Build File \"%1\""), + Utils::ParameterAction::EnabledWithParameter, this); + cmd = am->registerAction(d->m_buildFileAction, Constants::BUILDFILE, globalcontext); + cmd->setAttribute(Core::Command::CA_UpdateText); + cmd->setDefaultText(d->m_buildFileAction->text()); + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+B"))); + mbuild->addAction(cmd, Constants::G_BUILD_PROJECT); + // rebuild action d->m_rebuildAction = new Utils::ParameterAction(tr("Rebuild Project"), tr("Rebuild Project \"%1\""), Utils::ParameterAction::AlwaysEnabled, this); @@ -890,6 +901,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er connect(d->m_buildProjectOnlyAction, SIGNAL(triggered()), this, SLOT(buildProjectOnly())); connect(d->m_buildAction, SIGNAL(triggered()), this, SLOT(buildProject())); connect(d->m_buildActionContextMenu, SIGNAL(triggered()), this, SLOT(buildProjectContextMenu())); + connect(d->m_buildFileAction, SIGNAL(triggered()), this, SLOT(buildFile())); connect(d->m_buildSessionAction, SIGNAL(triggered()), this, SLOT(buildSession())); connect(d->m_rebuildProjectOnlyAction, SIGNAL(triggered()), this, SLOT(rebuildProjectOnly())); connect(d->m_rebuildAction, SIGNAL(triggered()), this, SLOT(rebuildProject())); @@ -1491,6 +1503,13 @@ void ProjectExplorerPlugin::setCurrent(Project *project, QString filePath, Node Core::ICore *core = Core::ICore::instance(); + QFileInfo fi(filePath); + QString suffix = fi.suffix().toLower(); + if (suffix == QLatin1String("cpp") || (suffix == QLatin1String("c"))) + d->m_currentFile = fi.fileName(); + else + d->m_currentFile.clear(); + d->m_buildFileAction->setParameter(d->m_currentFile); bool projectChanged = false; if (d->m_currentProject != project) { Core::Context oldContext; @@ -1559,6 +1578,7 @@ void ProjectExplorerPlugin::updateActions() d->m_cleanAction->setParameter(projectName); d->m_buildAction->setEnabled(enableBuildActions); + d->m_buildFileAction->setEnabled(enableBuildActions && !d->m_currentFile.isEmpty()); d->m_rebuildAction->setEnabled(enableBuildActions); d->m_cleanAction->setEnabled(enableBuildActions); @@ -1698,6 +1718,74 @@ void ProjectExplorerPlugin::buildProjectContextMenu() QStringList() << Constants::BUILDSTEPS_BUILD); } +static QString getObjectName(const QString &workingDir, const QString &fileName) +{ + QFileInfo srcFile(fileName); + QRegExp objDirRE("OBJECTS_DIR\\s*=\\s*(.*)$"); + QRegExp objSuffixRE("\\.cpp.*\\.([^:]*):"); + QDir objDir; + QString objSuffix; + int found = 0; + QFile make(QDir(workingDir).absoluteFilePath("Makefile")); + make.open(QIODevice::ReadOnly | QIODevice::Text); + while (!make.atEnd() && (found < 2)) + { + QString line = QString::fromLocal8Bit(make.readLine()).trimmed(); + if (objDirRE.indexIn(line) != -1) + { + objDir.setPath(objDirRE.cap(1)); + ++found; + } + else if (objSuffixRE.indexIn(line) != -1) + { + objSuffix = objSuffixRE.cap(1); + ++found; + } + } + make.close(); + if (found < 2) + return QString(); + QString objFile = srcFile.fileName().replace(srcFile.suffix(), objSuffix); + return QDir().relativeFilePath(objDir.filePath(objFile)); +} + +void ProjectExplorerPlugin::buildFile() +{ + AbstractProcessStep *makeStep = NULL; + QList stepLists; + foreach (Project *pro, d->m_session->projectOrder(d->m_session->startupProject())) { + if (!pro || !pro->activeTarget()) + continue; + BuildStepList *bsl = 0; + if (pro->activeTarget()->activeBuildConfiguration()) + bsl = pro->activeTarget()->activeBuildConfiguration()->stepList(Constants::BUILDSTEPS_BUILD); + + if (!bsl || bsl->isEmpty()) + continue; + stepLists << bsl; + } + foreach (BuildStep *step, stepLists.at(0)->steps()) + { + if (step->id() == QLatin1String("Qt4ProjectManager.MakeStep")) + { + makeStep = (AbstractProcessStep *)step; + break; + } + } + if (makeStep) + { + QString args = makeStep->userArguments(); + makeStep->init(); + QString workingDir = makeStep->processParameters()->effectiveWorkingDirectory(); + QString objName = getObjectName(workingDir, d->m_currentFile); + if (objName.isEmpty()) + return; + makeStep->setUserArguments(objName); + d->m_buildManager->buildLists(stepLists); + makeStep->setUserArguments(args); + } +} + void ProjectExplorerPlugin::buildSession() { queue(d->m_session->projectOrder(), diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h index 89b91db..dc8ca36 100644 --- a/src/plugins/projectexplorer/projectexplorer.h +++ b/src/plugins/projectexplorer/projectexplorer.h @@ -148,6 +148,7 @@ private slots: void buildProjectOnly(); void buildProject(); void buildProjectContextMenu(); + void buildFile(); void buildSession(); void rebuildProjectOnly(); void rebuildProject(); diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h index 5365706..0f322cc 100644 --- a/src/plugins/projectexplorer/projectexplorerconstants.h +++ b/src/plugins/projectexplorer/projectexplorerconstants.h @@ -50,6 +50,7 @@ const char * const UNLOAD = "ProjectExplorer.Unload"; const char * const CLEARSESSION = "ProjectExplorer.ClearSession"; const char * const BUILDPROJECTONLY = "ProjectExplorer.BuildProjectOnly"; const char * const BUILD = "ProjectExplorer.Build"; +const char * const BUILDFILE = "ProjectExplorer.BuildFile"; const char * const BUILDCM = "ProjectExplorer.BuildCM"; const char * const BUILDSESSION = "ProjectExplorer.BuildSession"; const char * const REBUILDPROJECTONLY = "ProjectExplorer.RebuildProjectOnly"; -- 1.7.4.msysgit.0