aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@digia.com>2012-11-12 17:55:00 +0100
committerJoerg Bornemann <joerg.bornemann@digia.com>2012-11-13 12:25:33 +0100
commitfad7c5c967c771aaaea0a3df180cfb823b5d17d0 (patch)
tree9caaec9674debc0fe120f524e67fe1227249083c
parente8360deb12973e53fdb8210b957dd7d305eec8b6 (diff)
Make console progress observer cancelable.
This comprises the following: - The command line client always creates an observer, because the user should be able to cancel a build independently of whether or not a progress bar was requested. - The progress observer has a real "canceled" state. - The progress observer has a way to tell it that no progress bar should be shown. Change-Id: Ie7679f2705faaabf364f90180e0fced82f4187d1 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
-rw-r--r--src/app/qbs/application.cpp26
-rw-r--r--src/app/qbs/application.h9
-rw-r--r--src/app/qbs/consoleprogressobserver.cpp8
-rw-r--r--src/app/qbs/consoleprogressobserver.h11
-rw-r--r--src/app/qbs/main.cpp8
-rw-r--r--src/lib/buildgraph/executor.h2
6 files changed, 34 insertions, 30 deletions
diff --git a/src/app/qbs/application.cpp b/src/app/qbs/application.cpp
index 32a619929..9e76b09ab 100644
--- a/src/app/qbs/application.cpp
+++ b/src/app/qbs/application.cpp
@@ -28,23 +28,20 @@
****************************************************************************/
#include "application.h"
+
+#include "consoleprogressobserver.h"
#include "ctrlchandler.h"
-#include <buildgraph/executor.h>
+#include <logging/logger.h>
+#include <logging/translator.h>
namespace qbs {
-using namespace Internal;
Application::Application(int &argc, char **argv)
- : QCoreApplication(argc, argv)
+ : QCoreApplication(argc, argv), m_observer(new ConsoleProgressObserver)
{
// ### TODO reactivate the Ctrl-C handler
- //installCtrlCHandler();
-}
-
-Application *Application::instance()
-{
- return qobject_cast<Application *>(QCoreApplication::instance());
+ // installCtrlCHandler();
}
void Application::init()
@@ -54,16 +51,11 @@ void Application::init()
setOrganizationDomain(QLatin1String("qt-project.org"));
}
-void Application::setExecutor(Executor *e)
-{
- m_executor = e;
-}
-
void Application::userInterrupt()
{
- fprintf(stderr, "qbs terminated by user (pid=%u)\n", (uint)QCoreApplication::applicationPid());
- if (m_executor)
- m_executor->cancelBuild();
+ qbsInfo() << Tr::tr("Received termination request from user; canceling build. [pid=%1]")
+ .arg(applicationPid());
+ m_observer->setCanceled(true);
}
} // namespace qbs
diff --git a/src/app/qbs/application.h b/src/app/qbs/application.h
index 2f2de0cae..a8bdc5423 100644
--- a/src/app/qbs/application.h
+++ b/src/app/qbs/application.h
@@ -33,7 +33,7 @@
#include <QCoreApplication>
namespace qbs {
-namespace Internal { class Executor; }
+class ConsoleProgressObserver;
class Application : public QCoreApplication
{
@@ -41,17 +41,14 @@ class Application : public QCoreApplication
public:
Application(int &argc, char **argv);
- static Application *instance();
-
void init();
- void setExecutor(Internal::Executor *e);
- Internal::Executor *executor() { return m_executor; }
+ ConsoleProgressObserver *observer() const { return m_observer; }
public slots:
void userInterrupt();
private:
- Internal::Executor *m_executor;
+ ConsoleProgressObserver * const m_observer;
};
} // namespace qbs
diff --git a/src/app/qbs/consoleprogressobserver.cpp b/src/app/qbs/consoleprogressobserver.cpp
index f9f96e35a..cebba0d3b 100644
--- a/src/app/qbs/consoleprogressobserver.cpp
+++ b/src/app/qbs/consoleprogressobserver.cpp
@@ -35,10 +35,16 @@
namespace qbs {
+ConsoleProgressObserver::ConsoleProgressObserver() : m_showProgress(false), m_canceled(false)
+{
+}
+
void ConsoleProgressObserver::initialize(const QString &task, int max)
{
m_maximum = max;
m_value = 0;
+ if (!m_showProgress)
+ return;
m_percentage = 0;
m_hashesPrinted = 0;
std::cout << task.toLocal8Bit().constData() << ": 0%" << std::flush;
@@ -49,6 +55,8 @@ void ConsoleProgressObserver::setProgressValue(int value)
if (value > m_maximum || value <= m_value)
return; // TODO: Should be an assertion, but the executor currently breaks it.
m_value = value;
+ if (!m_showProgress)
+ return;
const int newPercentage = (100 * m_value) / m_maximum;
if (newPercentage == m_percentage)
return;
diff --git a/src/app/qbs/consoleprogressobserver.h b/src/app/qbs/consoleprogressobserver.h
index 6141a892c..8c115a5f5 100644
--- a/src/app/qbs/consoleprogressobserver.h
+++ b/src/app/qbs/consoleprogressobserver.h
@@ -35,11 +35,18 @@ namespace qbs {
class ConsoleProgressObserver : public ProgressObserver
{
+public:
+ ConsoleProgressObserver();
+
+ void setShowProgress(bool show) { m_showProgress = show; }
+ void setCanceled(bool cancel) { m_canceled = cancel; }
+
+private:
void initialize(const QString &task, int max);
void setProgressValue(int value);
int progressValue() { return m_value; }
int maximum() const { return m_maximum; }
- bool canceled() const { return false; }
+ bool canceled() const { return m_canceled; }
void eraseCurrentPercentageString();
void updateProgressBarIfNecessary();
@@ -49,6 +56,8 @@ class ConsoleProgressObserver : public ProgressObserver
int m_value;
int m_percentage;
int m_hashesPrinted;
+ bool m_showProgress;
+ bool m_canceled;
};
} // namespace qbs
diff --git a/src/app/qbs/main.cpp b/src/app/qbs/main.cpp
index bf6160457..2f7513328 100644
--- a/src/app/qbs/main.cpp
+++ b/src/app/qbs/main.cpp
@@ -261,11 +261,9 @@ int main(int argc, char *argv[])
QList<Project::Id> projectIds;
QbsEngine qbsEngine;
qbsEngine.setBuildRoot(QDir::currentPath());
- QScopedPointer<ConsoleProgressObserver> observer;
- if (parser.showProgress()) {
- observer.reset(new ConsoleProgressObserver);
- qbsEngine.setProgressObserver(observer.data());
- }
+ if (parser.showProgress())
+ app.observer()->setShowProgress(true);
+ qbsEngine.setProgressObserver(app.observer());
try {
foreach (const QVariantMap &buildConfig, parser.buildConfigurations()) {
const Project::Id projectId
diff --git a/src/lib/buildgraph/executor.h b/src/lib/buildgraph/executor.h
index c50b9c7ab..cc5efcbdf 100644
--- a/src/lib/buildgraph/executor.h
+++ b/src/lib/buildgraph/executor.h
@@ -58,7 +58,6 @@ public:
~Executor();
void build(const QList<BuildProduct::Ptr> &productsToBuild);
- void cancelBuild();
enum ExecutorState {
ExecutorIdle,
@@ -88,6 +87,7 @@ private slots:
private:
void doBuild(const QList<BuildProduct::Ptr> &productsToBuild);
+ void cancelBuild();
void prepareBuildGraph(const Artifact::BuildState buildState, bool *sourceFilesChanged);
void prepareBuildGraph_impl(Artifact *artifact, const Artifact::BuildState buildState, bool *sourceFilesChanged);
void updateBuildGraph(Artifact::BuildState buildState);