summaryrefslogtreecommitdiff
path: root/src/lib/buildgraph/artifactcleaner.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@digia.com>2013-01-31 18:23:59 +0100
committerChristian Kandeler <christian.kandeler@digia.com>2013-02-06 10:36:05 +0100
commitaea6cbfa9d96f3f76bbc3b81362c54c9322b3fcb (patch)
treec140b905b53b01e509ad923a12e5b31f043f3361 /src/lib/buildgraph/artifactcleaner.cpp
parente5545733e8f63f62d499e73a27a72fc898a58e4e (diff)
downloadqbs-aea6cbfa9d96f3f76bbc3b81362c54c9322b3fcb.tar.gz
Remove global log sink.
Applications may not want to use the same log sink for all builds. The logging facility is also decoupled from the command-line client in other ways: - The LogWriter modifiers for output channel and text color are gone, since this type of decision should not be made by low-level code. Instead, the "highlight" string can be forwarded to the log sink. - The console logger now lives in app/shared, as it must never be used by library code. Change-Id: I8863a554c9b74577320ef23f6f934a74e0f0cbb0 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'src/lib/buildgraph/artifactcleaner.cpp')
-rw-r--r--src/lib/buildgraph/artifactcleaner.cpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/lib/buildgraph/artifactcleaner.cpp b/src/lib/buildgraph/artifactcleaner.cpp
index 1a150130c..d9cce0c09 100644
--- a/src/lib/buildgraph/artifactcleaner.cpp
+++ b/src/lib/buildgraph/artifactcleaner.cpp
@@ -36,7 +36,6 @@
#include "transformer.h"
#include <language/language.h>
-#include <logging/logger.h>
#include <logging/translator.h>
#include <tools/buildoptions.h>
#include <tools/error.h>
@@ -52,12 +51,12 @@
namespace qbs {
namespace Internal {
-static void printRemovalMessage(const QString &path, bool dryRun)
+static void printRemovalMessage(const QString &path, bool dryRun, const Logger &logger)
{
if (dryRun)
- qbsInfo() << Tr::tr("Would remove '%1'.").arg(path);
+ logger.qbsInfo() << Tr::tr("Would remove '%1'.").arg(path);
else
- qbsDebug() << "Removing '" << path << "'.";
+ logger.qbsDebug() << "Removing '" << path << "'.";
}
static void invalidateArtifactTimestamp(Artifact *artifact)
@@ -68,7 +67,7 @@ static void invalidateArtifactTimestamp(Artifact *artifact)
}
}
-static void removeArtifactFromDisk(Artifact *artifact, bool dryRun)
+static void removeArtifactFromDisk(Artifact *artifact, bool dryRun, const Logger &logger)
{
QFileInfo fileInfo(artifact->filePath());
if (!fileInfo.exists()) {
@@ -76,7 +75,7 @@ static void removeArtifactFromDisk(Artifact *artifact, bool dryRun)
invalidateArtifactTimestamp(artifact);
return;
}
- printRemovalMessage(fileInfo.filePath(), dryRun);
+ printRemovalMessage(fileInfo.filePath(), dryRun, logger);
if (dryRun)
return;
invalidateArtifactTimestamp(artifact);
@@ -88,11 +87,12 @@ static void removeArtifactFromDisk(Artifact *artifact, bool dryRun)
class CleanupVisitor : public ArtifactVisitor
{
public:
- CleanupVisitor(bool stopOnError, bool dryRun, bool removeAll)
+ CleanupVisitor(bool stopOnError, bool dryRun, bool removeAll, const Logger &logger)
: ArtifactVisitor(Artifact::Generated)
, m_stopOnError(stopOnError)
, m_dryRun(dryRun)
, m_removeAll(removeAll)
+ , m_logger(logger)
, m_hasError(false)
{
}
@@ -114,11 +114,11 @@ private:
if (artifact->parents.isEmpty() && !m_removeAll)
return;
try {
- removeArtifactFromDisk(artifact, m_dryRun);
+ removeArtifactFromDisk(artifact, m_dryRun, m_logger);
} catch (const Error &error) {
if (m_stopOnError)
throw;
- qbsWarning() << error.toString();
+ m_logger.qbsWarning() << error.toString();
m_hasError = true;
}
m_directories << artifact->dirPath();
@@ -127,20 +127,25 @@ private:
const bool m_stopOnError;
const bool m_dryRun;
const bool m_removeAll;
+ Logger m_logger;
bool m_hasError;
BuildProductConstPtr m_product;
QSet<QString> m_directories;
};
+ArtifactCleaner::ArtifactCleaner(const Logger &logger) : m_logger(logger)
+{
+}
+
void ArtifactCleaner::cleanup(const QList<BuildProductPtr> &products, bool removeAll,
const BuildOptions &buildOptions)
{
m_hasError = false;
- TimedActivityLogger logger(QLatin1String("Cleaning up"));
+ TimedActivityLogger logger(m_logger, QLatin1String("Cleaning up"));
QSet<QString> directories;
foreach (const BuildProductConstPtr &product, products) {
- CleanupVisitor visitor(!buildOptions.keepGoing, buildOptions.dryRun, removeAll);
+ CleanupVisitor visitor(!buildOptions.keepGoing, buildOptions.dryRun, removeAll, m_logger);
visitor.visitProduct(product);
directories.unite(visitor.directories());
if (visitor.hasError())
@@ -171,12 +176,12 @@ void ArtifactCleaner::removeEmptyDirectories(const QString &rootDir, const Build
subTreeIsEmpty = false;
}
if (subTreeIsEmpty) {
- printRemovalMessage(rootDir, options.dryRun);
+ printRemovalMessage(rootDir, options.dryRun, m_logger);
if (!QDir::root().rmdir(rootDir)) {
Error error(Tr::tr("Failure to remove empty directory '%1'.").arg(rootDir));
if (!options.keepGoing)
throw error;
- qbsWarning() << error.toString();
+ m_logger.qbsWarning() << error.toString();
m_hasError = true;
subTreeIsEmpty = false;
}