|
Ninja
|
Builder wraps the build process: starting commands, updating status. More...
#include <build.h>
Public Member Functions | |
| Node * | AddTarget (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< CommandRunner > | command_runner_ |
| const BuildConfig & | config_ |
| std::unique_ptr< Jobserver::Client > | jobserver_ |
| Plan | plan_ |
| State * | state_ |
| Status * | status_ |
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 | |
| DiskInterface * | disk_interface_ |
| ExitStatus | exit_code_ = ExitSuccess |
| Keep the global exit code for the build. More... | |
| std::unique_ptr< Explanations > | explanations_ |
| std::string | lock_file_path_ |
| RunningEdgeMap | running_edges_ |
| DependencyScan | scan_ |
| int64_t | start_time_millis_ |
| Time the build started. More... | |
Builder wraps the build process: starting commands, updating status.
|
private |
| Builder::Builder | ( | State * | state, |
| const BuildConfig & | config, | ||
| BuildLog * | build_log, | ||
| DepsLog * | deps_log, | ||
| DiskInterface * | disk_interface, | ||
| Status * | status, | ||
| int64_t | start_time_millis | ||
| ) |
Definition at line 607 of file build.cc.
References State::bindings_, explanations_, lock_file_path_, BindingEnv::LookupVariable(), Status::SetExplanations(), state_, and status_.
| Builder::~Builder | ( | ) |
Definition at line 622 of file build.cc.
References Cleanup(), Status::SetExplanations(), and status_.
|
private |
| Node* Builder::AddTarget | ( | const std::string & | name, |
| std::string * | err | ||
| ) |
Referenced by BuildTest::RebuildTarget(), TEST_F(), and TestPhonyUseCase().
| bool Builder::AddTarget | ( | Node * | target, |
| std::string * | err | ||
| ) |
Add a target to the build, scanning dependencies.
| 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().
| ExitStatus Builder::Build | ( | std::string * | err | ) |
Run the build.
Returns ExitStatus or the exit code of the last failed job. It is an error to call this function when AlreadyUpToDate() is true.
Definition at line 703 of file build.cc.
References AlreadyUpToDate(), DependencyScan::build_log(), Status::BuildFinished(), Status::BuildStarted(), Cleanup(), BuildLog::Close(), command_runner_, config_, BuildConfig::dry_run, Plan::EdgeFinished(), ExitFailure, ExitInterrupted, ExitSuccess, CommandRunner::factory(), BuildConfig::failures_allowed, Plan::FindWork(), FinishCommand(), Edge::GetBindingBool(), GetExitCode(), Edge::is_phony(), jobserver_, Plan::kEdgeSucceeded, Plan::more_to_do(), plan_, Plan::PrepareQueue(), scan_, SetFailureCode(), StartEdge(), CommandRunner::Result::status, status_, and CommandRunner::Result::success().
Referenced by BuildTest::RebuildTarget(), TEST_F(), and TestPhonyUseCase().
| 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().
|
private |
Definition at line 984 of file build.cc.
References CanonicalizePath(), config_, BuildConfig::depfile_parser_options, disk_interface_, CommandRunner::Result::edge, Fatal(), g_keep_depfile, State::GetNode(), Edge::GetUnescapedDepfile(), CLParser::includes_, DepfileParser::ins_, FileReader::NotFound, FileReader::Okay, FileReader::OtherError, CommandRunner::Result::output, CLParser::Parse(), DepfileParser::Parse(), FileReader::ReadFile(), DiskInterface::RemoveFile(), and state_.
Referenced by FinishCommand().
| bool Builder::FinishCommand | ( | CommandRunner::Result * | result, |
| std::string * | err | ||
| ) |
Update status ninja logs following a command termination.
Definition at line 876 of file build.cc.
References DependencyScan::build_log(), Status::BuildEdgeFinished(), Plan::CleanNode(), Edge::command_start_time_, config_, DependencyScan::deps_log(), disk_interface_, BuildConfig::dry_run, CommandRunner::Result::edge, Plan::EdgeFinished(), ExitFailure, ExtractDeps(), g_keep_rsp, Edge::GetBinding(), Edge::GetBindingBool(), GetTimeMillis(), Edge::GetUnescapedRspfile(), Plan::kEdgeFailed, Plan::kEdgeSucceeded, METRIC_RECORD, CommandRunner::Result::output, Edge::outputs_, plan_, BuildLog::RecordCommand(), DepsLog::RecordDeps(), DiskInterface::RemoveFile(), running_edges_, scan_, start_time_millis_, DiskInterface::Stat(), CommandRunner::Result::status, status_, and CommandRunner::Result::success().
Referenced by Build().
|
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().
| 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().
|
private |
|
inline |
Used for tests.
Definition at line 231 of file build.h.
References scan_, and DependencyScan::set_build_log().
|
private |
Definition at line 1063 of file build.cc.
References exit_code_, and ExitSuccess.
Referenced by Build().
|
inline |
Set Jobserver client instance for this builder.
Definition at line 204 of file build.h.
References jobserver_.
| bool Builder::StartEdge | ( | Edge * | edge, |
| std::string * | err | ||
| ) |
Definition at line 823 of file build.cc.
References Status::BuildEdgeStarted(), command_runner_, Edge::command_start_time_, config_, disk_interface_, BuildConfig::dry_run, Edge::EvaluateCommand(), Edge::GetBinding(), GetTimeMillis(), Edge::GetUnescapedDepfile(), Edge::GetUnescapedRspfile(), Edge::is_phony(), lock_file_path_, DiskInterface::MakeDirs(), METRIC_RECORD, Edge::outputs_, running_edges_, start_time_millis_, DiskInterface::Stat(), status_, and DiskInterface::WriteFile().
Referenced by Build().
| 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().
| const BuildConfig& Builder::config_ |
Definition at line 239 of file build.h.
Referenced by Build(), ExtractDeps(), FinishCommand(), and StartEdge().
|
private |
Definition at line 262 of file build.h.
Referenced by Cleanup(), ExtractDeps(), FinishCommand(), and StartEdge().
|
private |
Keep the global exit code for the build.
Definition at line 270 of file build.h.
Referenced by GetExitCode(), and SetFailureCode().
|
private |
| std::unique_ptr<Jobserver::Client> Builder::jobserver_ |
Definition at line 241 of file build.h.
Referenced by Build(), Plan::EdgeFinished(), Plan::FindWork(), and SetJobserverClient().
|
private |
Definition at line 261 of file build.h.
Referenced by Builder(), Cleanup(), and StartEdge().
| Plan Builder::plan_ |
Definition at line 240 of file build.h.
Referenced by AlreadyUpToDate(), Build(), FinishCommand(), and LoadDyndeps().
|
private |
Definition at line 256 of file build.h.
Referenced by FinishCommand(), and StartEdge().
|
private |
Definition at line 267 of file build.h.
Referenced by Build(), FinishCommand(), LoadDyndeps(), and SetBuildLog().
|
private |
Time the build started.
Definition at line 259 of file build.h.
Referenced by FinishCommand(), and StartEdge().
| State* Builder::state_ |
Definition at line 238 of file build.h.
Referenced by Builder(), and ExtractDeps().
| Status* Builder::status_ |
Definition at line 243 of file build.h.
Referenced by Build(), Builder(), Plan::CleanNode(), Cleanup(), Plan::EdgeWanted(), FinishCommand(), StartEdge(), and ~Builder().