aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@digia.com>2014-02-04 14:17:38 +0100
committerJoerg Bornemann <joerg.bornemann@digia.com>2014-02-17 11:00:58 +0100
commitf25ef1b86755be284d89ad86212f62b0bc7a80ed (patch)
tree0df0ea31448081652ae925f690566d4c28195920
parent69a0eb040cf99dcfb3cca2fc00d87a9388e49f63 (diff)
Condense executor code.
Remove unused function and merge functions that were (nearly) doing the same thing. Change-Id: I33276068d5595456832ed44a0ff2d5705a87165a Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
-rw-r--r--src/lib/corelib/buildgraph/executor.cpp118
-rw-r--r--src/lib/corelib/buildgraph/executor.h11
-rw-r--r--src/lib/corelib/buildgraph/forward_decls.h3
-rw-r--r--src/lib/corelib/buildgraph/rulenode.h4
-rw-r--r--src/lib/corelib/buildgraph/rulesapplicator.cpp2
-rw-r--r--src/lib/corelib/buildgraph/rulesapplicator.h6
6 files changed, 51 insertions, 93 deletions
diff --git a/src/lib/corelib/buildgraph/executor.cpp b/src/lib/corelib/buildgraph/executor.cpp
index 02e0d332a..dadcb1f70 100644
--- a/src/lib/corelib/buildgraph/executor.cpp
+++ b/src/lib/corelib/buildgraph/executor.cpp
@@ -226,18 +226,33 @@ void Executor::setBuildOptions(const BuildOptions &buildOptions)
m_buildOptions = buildOptions;
}
-static void initArtifactsBottomUp(BuildGraphNode *node)
+static void initNodesBottomUp(BuildGraphNode *node)
{
if (node->buildState == BuildGraphNode::Untouched)
return;
node->buildState = BuildGraphNode::Buildable;
foreach (BuildGraphNode *parent, node->parents)
- initArtifactsBottomUp(parent);
+ initNodesBottomUp(parent);
}
void Executor::initLeaves()
{
- QList<Artifact *> changedArtifacts;
+ if (m_buildOptions.changedFiles().isEmpty())
+ updateLeaves(m_roots);
+ else
+ initLeavesForSelectedFiles();
+}
+
+void Executor::updateLeaves(const NodeSet &nodes)
+{
+ NodeSet seenNodes;
+ foreach (BuildGraphNode * const node, nodes)
+ updateLeaves(node, seenNodes);
+}
+
+void Executor::initLeavesForSelectedFiles()
+{
+ ArtifactSet changedArtifacts;
foreach (const QString &filePath, m_buildOptions.changedFiles()) {
QList<FileResourceBase *> lookupResults;
lookupResults.append(m_project->buildData->lookupFiles(filePath));
@@ -250,23 +265,14 @@ void Executor::initLeaves()
if (Artifact *artifact = dynamic_cast<Artifact *>(lookupResult))
changedArtifacts += artifact;
}
- qSort(changedArtifacts);
- changedArtifacts.erase(std::unique(changedArtifacts.begin(), changedArtifacts.end()),
- changedArtifacts.end());
-
- if (changedArtifacts.isEmpty()) {
- QSet<BuildGraphNode *> seenNodes;
- foreach (BuildGraphNode *root, m_roots)
- initLeavesTopDown(root, seenNodes);
- } else {
- foreach (BuildGraphNode *artifact, changedArtifacts) {
- m_leaves.push(artifact);
- initArtifactsBottomUp(artifact);
- }
+
+ foreach (Artifact *artifact, changedArtifacts) {
+ m_leaves.push(artifact);
+ initNodesBottomUp(artifact);
}
}
-void Executor::initLeavesTopDown(BuildGraphNode *node, QSet<BuildGraphNode *> &seenNodes)
+void Executor::updateLeaves(BuildGraphNode *node, NodeSet &seenNodes)
{
if (seenNodes.contains(node))
return;
@@ -281,11 +287,18 @@ void Executor::initLeavesTopDown(BuildGraphNode *node, QSet<BuildGraphNode *> &s
retrieveSourceFileTimestamp(artifact);
}
- if (node->children.isEmpty()) {
+ bool isLeaf = true;
+ foreach (BuildGraphNode *child, node->children) {
+ if (child->buildState != BuildGraphNode::Built) {
+ isLeaf = false;
+ updateLeaves(child, seenNodes);
+ }
+ }
+
+ if (isLeaf) {
+ if (m_doDebug)
+ m_logger.qbsDebug() << "[EXEC] adding leaf " << node->toString();
m_leaves.push(node);
- } else {
- foreach (BuildGraphNode *child, node->children)
- initLeavesTopDown(child, seenNodes);
}
}
@@ -522,16 +535,15 @@ void Executor::executeRuleNode(RuleNode *ruleNode)
} else {
if (m_doDebug)
m_logger.qbsDebug() << "[EXEC] " << ruleNode->toString();
- const QVector<BuildGraphNode *> &createdNodes = result.createdNodes;
const WeakPointer<ResolvedProduct> &product = ruleNode->product;
QSet<RuleNode *> parentRules;
- if (!createdNodes.isEmpty()) {
+ if (!result.createdNodes.isEmpty()) {
foreach (BuildGraphNode *parent, ruleNode->parents) {
if (RuleNode *parentRule = dynamic_cast<RuleNode *>(parent))
parentRules += parentRule;
}
}
- foreach (BuildGraphNode *node, createdNodes) {
+ foreach (BuildGraphNode *node, result.createdNodes) {
if (m_doDebug)
m_logger.qbsDebug() << "[EXEC] rule created " << node->toString();
loggedConnect(node, ruleNode, m_logger);
@@ -547,7 +559,7 @@ void Executor::executeRuleNode(RuleNode *ruleNode)
foreach (RuleNode *parentRule, parentRules)
loggedConnect(parentRule, outputArtifact, m_logger);
}
- insertLeavesAfterAddingDependencies(createdNodes);
+ updateLeaves(result.createdNodes);
}
finishNode(ruleNode);
if (m_progressObserver)
@@ -642,43 +654,11 @@ void Executor::finishArtifact(Artifact *leaf)
}
}
-void Executor::insertLeavesAfterAddingDependencies_recurse(BuildGraphNode *const node,
- QSet<BuildGraphNode *> *seenNodes, Leaves *leaves) const
-{
- if (seenNodes->contains(node))
- return;
- seenNodes->insert(node);
-
- if (node->buildState == BuildGraphNode::Untouched)
- node->buildState = BuildGraphNode::Buildable;
-
- bool isLeaf = true;
- foreach (BuildGraphNode *child, node->children) {
- if (child->buildState != BuildGraphNode::Built) {
- isLeaf = false;
- insertLeavesAfterAddingDependencies_recurse(child, seenNodes, leaves);
- }
- }
-
- if (isLeaf) {
- if (m_doDebug)
- m_logger.qbsDebug() << "[EXEC] adding leaf " << node->toString();
- leaves->push(node);
- }
-}
-
QString Executor::configString() const
{
return tr(" for configuration %1").arg(m_project->id());
}
-void Executor::insertLeavesAfterAddingDependencies(QVector<BuildGraphNode *> dependencies)
-{
- QSet<BuildGraphNode *> seenNodes;
- foreach (BuildGraphNode *dependency, dependencies)
- insertLeavesAfterAddingDependencies_recurse(dependency, &seenNodes, &m_leaves);
-}
-
void Executor::cancelJobs()
{
m_logger.qbsTrace() << "Canceling all jobs.";
@@ -792,7 +772,7 @@ void Executor::rescueOldBuildData(Artifact *artifact, bool *childrenAdded = 0)
bool Executor::checkForUnbuiltDependencies(Artifact *artifact)
{
bool buildingDependenciesFound = false;
- QVector<BuildGraphNode *> unbuiltDependencies;
+ NodeSet unbuiltDependencies;
foreach (BuildGraphNode *dependency, artifact->children) {
switch (dependency->buildState) {
case BuildGraphNode::Untouched:
@@ -818,7 +798,7 @@ bool Executor::checkForUnbuiltDependencies(Artifact *artifact)
}
if (!unbuiltDependencies.isEmpty()) {
artifact->inputsScanned = false;
- insertLeavesAfterAddingDependencies(unbuiltDependencies);
+ updateLeaves(unbuiltDependencies);
return true;
}
if (buildingDependenciesFound) {
@@ -997,26 +977,6 @@ void Executor::setupRootNodes()
}
}
-void Executor::updateBuildGraph(Artifact::BuildState buildState)
-{
- QSet<BuildGraphNode *> seenArtifacts;
- foreach (BuildGraphNode *root, m_roots)
- updateBuildGraph_impl(root, buildState, seenArtifacts);
-}
-
-void Executor::updateBuildGraph_impl(BuildGraphNode *node, Artifact::BuildState buildState,
- QSet<BuildGraphNode *> &seenNodes)
-{
- if (seenNodes.contains(node))
- return;
-
- seenNodes += node;
- node->buildState = buildState;
-
- foreach (BuildGraphNode *child, node->children)
- updateBuildGraph_impl(child, buildState, seenNodes);
-}
-
void Executor::setState(ExecutorState s)
{
if (m_state == s)
diff --git a/src/lib/corelib/buildgraph/executor.h b/src/lib/corelib/buildgraph/executor.h
index e402e303b..c0e059472 100644
--- a/src/lib/corelib/buildgraph/executor.h
+++ b/src/lib/corelib/buildgraph/executor.h
@@ -103,10 +103,10 @@ private:
void prepareReachableNodes_impl(BuildGraphNode *node, const Artifact::BuildState buildState);
void prepareProducts();
void setupRootNodes();
- void updateBuildGraph(Artifact::BuildState buildState);
- void updateBuildGraph_impl(BuildGraphNode *node, Artifact::BuildState buildState, QSet<BuildGraphNode *> &seenNodes);
void initLeaves();
- void initLeavesTopDown(BuildGraphNode *artifact, QSet<BuildGraphNode *> &seenArtifacts);
+ void updateLeaves(const NodeSet &nodes);
+ void updateLeaves(BuildGraphNode *node, NodeSet &seenNodes);
+ void initLeavesForSelectedFiles();
bool scheduleJobs();
void buildArtifact(Artifact *artifact);
void executeRuleNode(RuleNode *ruleNode);
@@ -115,7 +115,6 @@ private:
void finishArtifact(Artifact *artifact);
void setState(ExecutorState);
void addExecutorJobs();
- void insertLeavesAfterAddingDependencies(QVector<BuildGraphNode *> dependencies);
void cancelJobs();
void setupProgressObserver();
void doSanityChecks();
@@ -127,8 +126,6 @@ private:
bool isUpToDate(Artifact *artifact) const;
void retrieveSourceFileTimestamp(Artifact *artifact) const;
FileTime recursiveFileTime(const QString &filePath) const;
- void insertLeavesAfterAddingDependencies_recurse(BuildGraphNode * const node,
- QSet<BuildGraphNode *> *seenNodes, Leaves *leaves) const;
QString configString() const;
RulesEvaluationContextPtr m_evalContext;
@@ -140,7 +137,7 @@ private:
ExecutorState m_state;
TopLevelProjectPtr m_project;
QList<ResolvedProductPtr> m_productsToBuild;
- QList<BuildGraphNode *> m_roots;
+ NodeSet m_roots;
Leaves m_leaves;
QList<Artifact *> m_changedSourceArtifacts;
ScanResultCache m_scanResultCache;
diff --git a/src/lib/corelib/buildgraph/forward_decls.h b/src/lib/corelib/buildgraph/forward_decls.h
index 2baa74d6d..91c89e483 100644
--- a/src/lib/corelib/buildgraph/forward_decls.h
+++ b/src/lib/corelib/buildgraph/forward_decls.h
@@ -35,8 +35,11 @@ namespace qbs {
namespace Internal {
class Artifact;
+class ArtifactSet;
class ProjectBuildData;
class ProductBuildData;
+class Node;
+class NodeSet;
class Transformer;
typedef QSharedPointer<Transformer> TransformerPtr;
diff --git a/src/lib/corelib/buildgraph/rulenode.h b/src/lib/corelib/buildgraph/rulenode.h
index b4f17a405..abf0a8e59 100644
--- a/src/lib/corelib/buildgraph/rulenode.h
+++ b/src/lib/corelib/buildgraph/rulenode.h
@@ -34,8 +34,6 @@
#include "buildgraphnode.h"
#include <language/forward_decls.h>
-#include <QVector>
-
namespace qbs {
namespace Internal {
@@ -57,7 +55,7 @@ public:
struct ApplicationResult
{
bool upToDate;
- QVector<BuildGraphNode *> createdNodes;
+ NodeSet createdNodes;
};
void apply(const Logger &logger, const ArtifactSet &changedInputs, ApplicationResult *result);
diff --git a/src/lib/corelib/buildgraph/rulesapplicator.cpp b/src/lib/corelib/buildgraph/rulesapplicator.cpp
index 43c4efb45..e297ef23d 100644
--- a/src/lib/corelib/buildgraph/rulesapplicator.cpp
+++ b/src/lib/corelib/buildgraph/rulesapplicator.cpp
@@ -64,7 +64,7 @@ RulesApplicator::~RulesApplicator()
delete m_mocScanner;
}
-QVector<BuildGraphNode *> RulesApplicator::applyRuleInEvaluationContext(const RuleConstPtr &rule)
+NodeSet RulesApplicator::applyRuleInEvaluationContext(const RuleConstPtr &rule)
{
m_createdArtifacts.clear();
RulesEvaluationContext::Scope s(m_product->topLevelProject()->buildData->evaluationContext.data());
diff --git a/src/lib/corelib/buildgraph/rulesapplicator.h b/src/lib/corelib/buildgraph/rulesapplicator.h
index e5813834a..40aa5d70a 100644
--- a/src/lib/corelib/buildgraph/rulesapplicator.h
+++ b/src/lib/corelib/buildgraph/rulesapplicator.h
@@ -31,6 +31,7 @@
#include "artifactset.h"
#include "forward_decls.h"
+#include "nodeset.h"
#include <language/filetags.h>
#include <language/forward_decls.h>
#include <logging/logger.h>
@@ -38,7 +39,6 @@
#include <QHash>
#include <QScriptValue>
#include <QString>
-#include <QVector>
namespace qbs {
namespace Internal {
@@ -54,7 +54,7 @@ public:
RulesApplicator(const ResolvedProductPtr &product, ArtifactsPerFileTagMap &artifactsPerFileTag,
const Logger &logger);
~RulesApplicator();
- QVector<BuildGraphNode *> applyRuleInEvaluationContext(const RuleConstPtr &rule);
+ NodeSet applyRuleInEvaluationContext(const RuleConstPtr &rule);
void applyRule(const RuleConstPtr &rule);
static void handleRemovedRuleOutputs(ArtifactSet artifactsToRemove, const Logger &logger);
@@ -77,7 +77,7 @@ private:
const ResolvedProductPtr m_product;
ArtifactsPerFileTagMap &m_artifactsPerFileTag;
- QVector<BuildGraphNode *> m_createdArtifacts;
+ NodeSet m_createdArtifacts;
RuleConstPtr m_rule;
TransformerPtr m_transformer;