Ninja
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Plan Struct Reference

Plan stores the state of a build plan: what we intend to build, which steps we're ready to execute. More...

#include <build.h>

Public Types

enum  EdgeResult { kEdgeFailed, kEdgeSucceeded }
 

Public Member Functions

bool AddTarget (const Node *node, std::string *err)
 Add a target to our plan (including all its dependencies). More...
 
bool CleanNode (DependencyScan *scan, Node *node, std::string *err)
 Clean the given node during the build. More...
 
int command_edge_count () const
 Number of edges with commands to run. More...
 
void Dump () const
 Dumps the current state of the plan. More...
 
bool DyndepsLoaded (DependencyScan *scan, const Node *node, const DyndepFile &ddf, std::string *err)
 Update the build plan to account for modifications made to the graph by information loaded from a dyndep file. More...
 
bool EdgeFinished (Edge *edge, EdgeResult result, std::string *err)
 Mark an edge as done building (whether it succeeded or failed). More...
 
EdgeFindWork ()
 
bool more_to_do () const
 Returns true if there's more work to be done. More...
 
 Plan (Builder *builder=NULL)
 
void Reset ()
 Reset state. Clears want and ready sets. More...
 

Private Types

enum  Want { kWantNothing, kWantToStart, kWantToFinish }
 Enumerate possible steps we want for an edge. More...
 

Private Member Functions

bool AddSubTarget (const Node *node, const Node *dependent, std::string *err, std::set< Edge *> *dyndep_walk)
 
bool EdgeMaybeReady (std::map< Edge *, Want >::iterator want_e, std::string *err)
 
void EdgeWanted (const Edge *edge)
 
bool NodeFinished (Node *node, std::string *err)
 Update plan with knowledge that the given node is up to date. More...
 
bool RefreshDyndepDependents (DependencyScan *scan, const Node *node, std::string *err)
 
void ScheduleWork (std::map< Edge *, Want >::iterator want_e)
 Submits a ready edge as a candidate for execution. More...
 
void UnmarkDependents (const Node *node, std::set< Node *> *dependents)
 

Private Attributes

Builderbuilder_
 
int command_edges_
 Total number of edges that have commands (not phony). More...
 
std::set< Edge * > ready_
 
std::map< Edge *, Wantwant_
 Keep track of which edges we want to build in this plan. More...
 
int wanted_edges_
 Total remaining number of wanted edges. More...
 

Detailed Description

Plan stores the state of a build plan: what we intend to build, which steps we're ready to execute.

Definition at line 43 of file build.h.

Member Enumeration Documentation

◆ EdgeResult

Enumerator
kEdgeFailed 
kEdgeSucceeded 

Definition at line 61 of file build.h.

◆ Want

enum Plan::Want
private

Enumerate possible steps we want for an edge.

Enumerator
kWantNothing 

We do not want to build the edge, but we might want to build one of its dependents.

kWantToStart 

We want to build the edge, but have not yet scheduled it.

kWantToFinish 

We want to build the edge, have scheduled it, and are waiting for it to complete.

Definition at line 99 of file build.h.

Constructor & Destructor Documentation

◆ Plan()

Plan::Plan ( Builder builder = NULL)

Definition at line 308 of file build.cc.

Member Function Documentation

◆ AddSubTarget()

bool Plan::AddSubTarget ( const Node node,
const Node dependent,
std::string *  err,
std::set< Edge *> *  dyndep_walk 
)
private

◆ AddTarget()

bool Plan::AddTarget ( const Node node,
std::string *  err 
)

Add a target to our plan (including all its dependencies).

Returns false if we don't need to build this target; may fill in |err| with an error message if there's a problem.

Definition at line 321 of file build.cc.

References AddSubTarget().

Referenced by TEST_F().

◆ CleanNode()

bool Plan::CleanNode ( DependencyScan scan,
Node node,
std::string *  err 
)

Clean the given node during the build.

Return false on error.

Definition at line 478 of file build.cc.

References command_edges_, Node::dirty(), kWantNothing, MEM_FN, Node::mtime(), Node::out_edges(), DependencyScan::RecomputeOutputsDirty(), Node::set_dirty(), want_, and wanted_edges_.

Referenced by Builder::FinishCommand().

◆ command_edge_count()

int Plan::command_edge_count ( ) const
inline

Number of edges with commands to run.

Definition at line 77 of file build.h.

References command_edges_.

Referenced by Builder::Build(), Builder::FinishCommand(), Builder::LoadDyndeps(), and TEST_F().

◆ Dump()

void Plan::Dump ( ) const

Dumps the current state of the plan.

Definition at line 657 of file build.cc.

References kWantNothing, ready_, and want_.

◆ DyndepsLoaded()

bool Plan::DyndepsLoaded ( DependencyScan scan,
const Node node,
const DyndepFile ddf,
std::string *  err 
)

Update the build plan to account for modifications made to the graph by information loaded from a dyndep file.

Definition at line 535 of file build.cc.

References AddSubTarget(), EdgeMaybeReady(), Node::out_edges(), Edge::outputs_ready(), RefreshDyndepDependents(), and want_.

Referenced by Builder::LoadDyndeps().

◆ EdgeFinished()

bool Plan::EdgeFinished ( Edge edge,
EdgeResult  result,
std::string *  err 
)

Mark an edge as done building (whether it succeeded or failed).

If any of the edge's outputs are dyndep bindings of their dependents, this loads dynamic dependencies from the nodes' paths. Returns 'false' if loading dyndep info fails and 'true' otherwise.

Definition at line 412 of file build.cc.

References Pool::EdgeFinished(), kEdgeSucceeded, kWantNothing, NodeFinished(), Edge::outputs_, Edge::outputs_ready_, Edge::pool(), ready_, Pool::RetrieveReadyEdges(), want_, and wanted_edges_.

Referenced by Builder::Build(), EdgeMaybeReady(), and Builder::FinishCommand().

◆ EdgeMaybeReady()

bool Plan::EdgeMaybeReady ( std::map< Edge *, Want >::iterator  want_e,
std::string *  err 
)
private

Definition at line 463 of file build.cc.

References Edge::AllInputsReady(), EdgeFinished(), kEdgeSucceeded, kWantNothing, and ScheduleWork().

Referenced by DyndepsLoaded(), and NodeFinished().

◆ EdgeWanted()

void Plan::EdgeWanted ( const Edge edge)
private

Definition at line 375 of file build.cc.

References command_edges_, Edge::is_phony(), and wanted_edges_.

Referenced by AddSubTarget(), and RefreshDyndepDependents().

◆ FindWork()

Edge * Plan::FindWork ( )

Definition at line 381 of file build.cc.

References ready_.

Referenced by Builder::Build(), and PlanTest::FindWorkSorted().

◆ more_to_do()

bool Plan::more_to_do ( ) const
inline

Returns true if there's more work to be done.

Definition at line 56 of file build.h.

References command_edges_, and wanted_edges_.

Referenced by Builder::AlreadyUpToDate(), Builder::Build(), PlanTest::FindWorkSorted(), and TEST_F().

◆ NodeFinished()

bool Plan::NodeFinished ( Node node,
std::string *  err 
)
private

Update plan with knowledge that the given node is up to date.

If the node is a dyndep binding on any of its dependents, this loads dynamic dependencies from the node's path. Returns 'false' if loading dyndep info fails and 'true' otherwise.

Definition at line 440 of file build.cc.

References builder_, Node::dyndep_pending(), EdgeMaybeReady(), Builder::LoadDyndeps(), Node::out_edges(), and want_.

Referenced by EdgeFinished().

◆ RefreshDyndepDependents()

bool Plan::RefreshDyndepDependents ( DependencyScan scan,
const Node node,
std::string *  err 
)
private

◆ Reset()

void Plan::Reset ( )

Reset state. Clears want and ready sets.

Definition at line 314 of file build.cc.

References command_edges_, ready_, want_, and wanted_edges_.

◆ ScheduleWork()

void Plan::ScheduleWork ( std::map< Edge *, Want >::iterator  want_e)
private

Submits a ready edge as a candidate for execution.

The edge may be delayed from running, for example if it's a member of a currently-full pool.

Definition at line 390 of file build.cc.

References Pool::DelayEdge(), Pool::EdgeScheduled(), kWantToFinish, kWantToStart, Edge::pool(), ready_, Pool::RetrieveReadyEdges(), and Pool::ShouldDelayEdge().

Referenced by AddSubTarget(), and EdgeMaybeReady().

◆ UnmarkDependents()

void Plan::UnmarkDependents ( const Node node,
std::set< Node *> *  dependents 
)
private

Definition at line 637 of file build.cc.

References Edge::mark_, Node::out_edges(), Edge::outputs_, Edge::VisitNone, and want_.

Referenced by RefreshDyndepDependents().

Member Data Documentation

◆ builder_

Builder* Plan::builder_
private

Definition at line 127 of file build.h.

Referenced by NodeFinished().

◆ command_edges_

int Plan::command_edges_
private

Total number of edges that have commands (not phony).

Definition at line 130 of file build.h.

Referenced by CleanNode(), command_edge_count(), EdgeWanted(), more_to_do(), and Reset().

◆ ready_

std::set<Edge*> Plan::ready_
private

Definition at line 125 of file build.h.

Referenced by Dump(), EdgeFinished(), FindWork(), Reset(), and ScheduleWork().

◆ want_

std::map<Edge*, Want> Plan::want_
private

Keep track of which edges we want to build in this plan.

If this map does not contain an entry for an edge, we do not want to build the entry or its dependents. If it does contain an entry, the enumeration indicates what we want for the edge.

Definition at line 123 of file build.h.

Referenced by AddSubTarget(), CleanNode(), Dump(), DyndepsLoaded(), EdgeFinished(), NodeFinished(), RefreshDyndepDependents(), Reset(), and UnmarkDependents().

◆ wanted_edges_

int Plan::wanted_edges_
private

Total remaining number of wanted edges.

Definition at line 133 of file build.h.

Referenced by CleanNode(), EdgeFinished(), EdgeWanted(), more_to_do(), and Reset().


The documentation for this struct was generated from the following files: