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

Builder wraps the build process: starting commands, updating status. More...

#include <build.h>

Public Member Functions

NodeAddTarget (const std::string &name, std::string *err)
 
bool AddTarget (Node *target, std::string *err)
 Add a target to the build, scanning dependencies. More...
 
bool AlreadyUpToDate () const
 Returns true if the build targets are already up to date. More...
 
ExitStatus Build (std::string *err)
 Run the build. More...
 
 Builder (State *state, const BuildConfig &config, BuildLog *build_log, DepsLog *deps_log, DiskInterface *disk_interface, Status *status, int64_t start_time_millis)
 
void Cleanup ()
 Clean up after interrupted commands by deleting output files. More...
 
bool FinishCommand (CommandRunner::Result *result, std::string *err)
 Update status ninja logs following a command termination. More...
 
ExitStatus GetExitCode () const
 Returns ExitStatus or the exit code of the last failed job (doesn't need to be an enum value of ExitStatus) More...
 
bool LoadDyndeps (Node *node, std::string *err)
 Load the dyndep information provided by the given node. More...
 
void SetBuildLog (BuildLog *log)
 Used for tests. More...
 
void SetJobserverClient (std::unique_ptr< Jobserver::Client > jobserver_client)
 Set Jobserver client instance for this builder. More...
 
bool StartEdge (Edge *edge, std::string *err)
 
 ~Builder ()
 

Public Attributes

std::unique_ptr< CommandRunnercommand_runner_
 
const BuildConfigconfig_
 
std::unique_ptr< Jobserver::Clientjobserver_
 
Plan plan_
 
Statestate_
 
Statusstatus_
 

Private Types

typedef std::map< const Edge *, int > RunningEdgeMap
 Map of running edge to time the edge started running. More...
 

Private Member Functions

 Builder (const Builder &other)
 
bool ExtractDeps (CommandRunner::Result *result, const std::string &deps_type, const std::string &deps_prefix, std::vector< Node * > *deps_nodes, std::string *err)
 
void operator= (const Builder &other)
 
void SetFailureCode (ExitStatus code)
 

Private Attributes

DiskInterfacedisk_interface_
 
ExitStatus exit_code_ = ExitSuccess
 Keep the global exit code for the build. More...
 
std::unique_ptr< Explanationsexplanations_
 
std::string lock_file_path_
 
RunningEdgeMap running_edges_
 
DependencyScan scan_
 
int64_t start_time_millis_
 Time the build started. More...
 

Detailed Description

Builder wraps the build process: starting commands, updating status.

Definition at line 197 of file build.h.

Member Typedef Documentation

◆ RunningEdgeMap

typedef std::map<const Edge*, int> Builder::RunningEdgeMap
private

Map of running edge to time the edge started running.

Definition at line 255 of file build.h.

Constructor & Destructor Documentation

◆ Builder() [1/2]

Builder::Builder ( State state,
const BuildConfig config,
BuildLog build_log,
DepsLog deps_log,
DiskInterface disk_interface,
Status status,
int64_t  start_time_millis 
)

◆ ~Builder()

Builder::~Builder ( )

Definition at line 622 of file build.cc.

References Cleanup(), Status::SetExplanations(), and status_.

◆ Builder() [2/2]

Builder::Builder ( const Builder other)
private

Member Function Documentation

◆ AddTarget() [1/2]

Node* Builder::AddTarget ( const std::string &  name,
std::string *  err 
)

◆ AddTarget() [2/2]

bool Builder::AddTarget ( Node target,
std::string *  err 
)

Add a target to the build, scanning dependencies.

Returns
false on error.

◆ AlreadyUpToDate()

bool Builder::AlreadyUpToDate ( ) const

Returns true if the build targets are already up to date.

Definition at line 699 of file build.cc.

References Plan::more_to_do(), and plan_.

Referenced by Build(), BuildTest::RebuildTarget(), TEST_F(), and TestPhonyUseCase().

◆ Build()

ExitStatus Builder::Build ( std::string *  err)

◆ Cleanup()

void Builder::Cleanup ( )

Clean up after interrupted commands by deleting output files.

Definition at line 627 of file build.cc.

References command_runner_, disk_interface_, Status::Error(), lock_file_path_, DiskInterface::RemoveFile(), DiskInterface::Stat(), and status_.

Referenced by Build(), and ~Builder().

◆ ExtractDeps()

bool Builder::ExtractDeps ( CommandRunner::Result result,
const std::string &  deps_type,
const std::string &  deps_prefix,
std::vector< Node * > *  deps_nodes,
std::string *  err 
)
private

◆ FinishCommand()

bool Builder::FinishCommand ( CommandRunner::Result result,
std::string *  err 
)

◆ GetExitCode()

ExitStatus Builder::GetExitCode ( ) const
inline

Returns ExitStatus or the exit code of the last failed job (doesn't need to be an enum value of ExitStatus)

Definition at line 247 of file build.h.

References exit_code_.

Referenced by Build().

◆ LoadDyndeps()

bool Builder::LoadDyndeps ( Node node,
std::string *  err 
)

Load the dyndep information provided by the given node.

Definition at line 1050 of file build.cc.

References Plan::DyndepsLoaded(), DependencyScan::LoadDyndeps(), plan_, and scan_.

Referenced by Plan::NodeFinished().

◆ operator=()

void Builder::operator= ( const Builder other)
private

◆ SetBuildLog()

void Builder::SetBuildLog ( BuildLog log)
inline

Used for tests.

Definition at line 231 of file build.h.

References scan_, and DependencyScan::set_build_log().

◆ SetFailureCode()

void Builder::SetFailureCode ( ExitStatus  code)
private

Definition at line 1063 of file build.cc.

References exit_code_, and ExitSuccess.

Referenced by Build().

◆ SetJobserverClient()

void Builder::SetJobserverClient ( std::unique_ptr< Jobserver::Client jobserver_client)
inline

Set Jobserver client instance for this builder.

Definition at line 204 of file build.h.

References jobserver_.

◆ StartEdge()

bool Builder::StartEdge ( Edge edge,
std::string *  err 
)

Member Data Documentation

◆ command_runner_

std::unique_ptr<CommandRunner> Builder::command_runner_

Definition at line 242 of file build.h.

Referenced by Build(), Cleanup(), BuildTest::RebuildTarget(), StartEdge(), TEST_F(), and TestPhonyUseCase().

◆ config_

const BuildConfig& Builder::config_

Definition at line 239 of file build.h.

Referenced by Build(), ExtractDeps(), FinishCommand(), and StartEdge().

◆ disk_interface_

DiskInterface* Builder::disk_interface_
private

Definition at line 262 of file build.h.

Referenced by Cleanup(), ExtractDeps(), FinishCommand(), and StartEdge().

◆ exit_code_

ExitStatus Builder::exit_code_ = ExitSuccess
private

Keep the global exit code for the build.

Definition at line 270 of file build.h.

Referenced by GetExitCode(), and SetFailureCode().

◆ explanations_

std::unique_ptr<Explanations> Builder::explanations_
private

Definition at line 265 of file build.h.

Referenced by Builder().

◆ jobserver_

std::unique_ptr<Jobserver::Client> Builder::jobserver_

Definition at line 241 of file build.h.

Referenced by Build(), Plan::EdgeFinished(), Plan::FindWork(), and SetJobserverClient().

◆ lock_file_path_

std::string Builder::lock_file_path_
private

Definition at line 261 of file build.h.

Referenced by Builder(), Cleanup(), and StartEdge().

◆ plan_

Plan Builder::plan_

Definition at line 240 of file build.h.

Referenced by AlreadyUpToDate(), Build(), FinishCommand(), and LoadDyndeps().

◆ running_edges_

RunningEdgeMap Builder::running_edges_
private

Definition at line 256 of file build.h.

Referenced by FinishCommand(), and StartEdge().

◆ scan_

DependencyScan Builder::scan_
private

Definition at line 267 of file build.h.

Referenced by Build(), FinishCommand(), LoadDyndeps(), and SetBuildLog().

◆ start_time_millis_

int64_t Builder::start_time_millis_
private

Time the build started.

Definition at line 259 of file build.h.

Referenced by FinishCommand(), and StartEdge().

◆ state_

State* Builder::state_

Definition at line 238 of file build.h.

Referenced by Builder(), and ExtractDeps().

◆ status_

Status* Builder::status_

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