From f25ef1b86755be284d89ad86212f62b0bc7a80ed Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Tue, 4 Feb 2014 14:17:38 +0100 Subject: Condense executor code. Remove unused function and merge functions that were (nearly) doing the same thing. Change-Id: I33276068d5595456832ed44a0ff2d5705a87165a Reviewed-by: Joerg Bornemann --- src/lib/corelib/buildgraph/executor.cpp | 118 ++++++++----------------- src/lib/corelib/buildgraph/executor.h | 11 +-- src/lib/corelib/buildgraph/forward_decls.h | 3 + src/lib/corelib/buildgraph/rulenode.h | 4 +- src/lib/corelib/buildgraph/rulesapplicator.cpp | 2 +- src/lib/corelib/buildgraph/rulesapplicator.h | 6 +- 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 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 lookupResults; lookupResults.append(m_project->buildData->lookupFiles(filePath)); @@ -250,23 +265,14 @@ void Executor::initLeaves() if (Artifact *artifact = dynamic_cast(lookupResult)) changedArtifacts += artifact; } - qSort(changedArtifacts); - changedArtifacts.erase(std::unique(changedArtifacts.begin(), changedArtifacts.end()), - changedArtifacts.end()); - - if (changedArtifacts.isEmpty()) { - QSet 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 &seenNodes) +void Executor::updateLeaves(BuildGraphNode *node, NodeSet &seenNodes) { if (seenNodes.contains(node)) return; @@ -281,11 +287,18 @@ void Executor::initLeavesTopDown(BuildGraphNode *node, QSet &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 &createdNodes = result.createdNodes; const WeakPointer &product = ruleNode->product; QSet parentRules; - if (!createdNodes.isEmpty()) { + if (!result.createdNodes.isEmpty()) { foreach (BuildGraphNode *parent, ruleNode->parents) { if (RuleNode *parentRule = dynamic_cast(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 *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 dependencies) -{ - QSet 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 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 seenArtifacts; - foreach (BuildGraphNode *root, m_roots) - updateBuildGraph_impl(root, buildState, seenArtifacts); -} - -void Executor::updateBuildGraph_impl(BuildGraphNode *node, Artifact::BuildState buildState, - QSet &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 &seenNodes); void initLeaves(); - void initLeavesTopDown(BuildGraphNode *artifact, QSet &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 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 *seenNodes, Leaves *leaves) const; QString configString() const; RulesEvaluationContextPtr m_evalContext; @@ -140,7 +137,7 @@ private: ExecutorState m_state; TopLevelProjectPtr m_project; QList m_productsToBuild; - QList m_roots; + NodeSet m_roots; Leaves m_leaves; QList 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 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 -#include - namespace qbs { namespace Internal { @@ -57,7 +55,7 @@ public: struct ApplicationResult { bool upToDate; - QVector 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 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 #include #include @@ -38,7 +39,6 @@ #include #include #include -#include namespace qbs { namespace Internal { @@ -54,7 +54,7 @@ public: RulesApplicator(const ResolvedProductPtr &product, ArtifactsPerFileTagMap &artifactsPerFileTag, const Logger &logger); ~RulesApplicator(); - QVector 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 m_createdArtifacts; + NodeSet m_createdArtifacts; RuleConstPtr m_rule; TransformerPtr m_transformer; -- cgit v1.2.3