From: Evan Martin Date: Tue, 4 Sep 2012 22:39:04 +0000 (-0400) Subject: move BuildLog to DependencyScan X-Git-Tag: v1.0.0^2~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1e11c8a6bd119025efd8725370ffa42354f92f88;p=platform%2Fupstream%2Fninja.git move BuildLog to DependencyScan The build log is needed in computing whether an edge is dirty, so I think it belongs here. (It's a bit weird that Builder needs to reach into it to record completed commands, maybe it will become cleaner with more thought.) --- diff --git a/src/build.cc b/src/build.cc index 4102209..efc05b0 100644 --- a/src/build.cc +++ b/src/build.cc @@ -554,11 +554,10 @@ struct DryRunCommandRunner : public CommandRunner { }; Builder::Builder(State* state, const BuildConfig& config, - DiskInterface* disk_interface) + BuildLog* log, DiskInterface* disk_interface) : state_(state), config_(config), disk_interface_(disk_interface), - scan_(state, disk_interface) { + scan_(state, log, disk_interface) { status_ = new BuildStatus(config); - log_ = state->build_log_; } Builder::~Builder() { @@ -797,7 +796,7 @@ void Builder::FinishEdge(Edge* edge, bool success, const string& output) { int start_time, end_time; status_->BuildEdgeFinished(edge, success, output, &start_time, &end_time); - if (success && log_) - log_->RecordCommand(edge, start_time, end_time, restat_mtime); + if (success && scan_.build_log()) + scan_.build_log()->RecordCommand(edge, start_time, end_time, restat_mtime); } diff --git a/src/build.h b/src/build.h index 9152eac..3e7a144 100644 --- a/src/build.h +++ b/src/build.h @@ -121,7 +121,7 @@ struct BuildConfig { /// Builder wraps the build process: starting commands, updating status. struct Builder { Builder(State* state, const BuildConfig& config, - DiskInterface* disk_interface); + BuildLog* log, DiskInterface* disk_interface); ~Builder(); /// Clean up after interrupted commands by deleting output files. @@ -143,12 +143,16 @@ struct Builder { bool StartEdge(Edge* edge, string* err); void FinishEdge(Edge* edge, bool success, const string& output); + /// Used for tests. + void SetBuildLog(BuildLog* log) { + scan_.set_build_log(log); + } + State* state_; const BuildConfig& config_; Plan plan_; auto_ptr command_runner_; BuildStatus* status_; - BuildLog* log_; private: DiskInterface* disk_interface_; diff --git a/src/build_test.cc b/src/build_test.cc index d4673ae..859e758 100644 --- a/src/build_test.cc +++ b/src/build_test.cc @@ -178,7 +178,8 @@ TEST_F(PlanTest, DependencyCycle) { struct BuildTest : public StateTestWithBuiltinRules, public CommandRunner { - BuildTest() : config_(MakeConfig()), builder_(&state_, config_, &fs_), + BuildTest() : config_(MakeConfig()), + builder_(&state_, config_, NULL, &fs_), now_(1), last_command_(NULL), status_(config_) { builder_.command_runner_.reset(this); AssertParse(&state_, @@ -717,7 +718,7 @@ TEST_F(BuildTest, SwallowFailuresLimit) { struct BuildWithLogTest : public BuildTest { BuildWithLogTest() { - state_.build_log_ = builder_.log_ = &build_log_; + builder_.SetBuildLog(&build_log_); } BuildLog build_log_; diff --git a/src/disk_interface_test.cc b/src/disk_interface_test.cc index 68a6ca9..32fe9cb 100644 --- a/src/disk_interface_test.cc +++ b/src/disk_interface_test.cc @@ -105,7 +105,7 @@ TEST_F(DiskInterfaceTest, RemoveFile) { struct StatTest : public StateTestWithBuiltinRules, public DiskInterface { - StatTest() : scan_(&state_, this) {} + StatTest() : scan_(&state_, NULL, this) {} // DiskInterface implementation. virtual TimeStamp Stat(const string& path); diff --git a/src/graph.h b/src/graph.h index ced1f4f..893ec09 100644 --- a/src/graph.h +++ b/src/graph.h @@ -201,8 +201,10 @@ struct Edge { /// DependencyScan manages the process of scanning the files in a graph /// and updating the dirty/outputs_ready state of all the nodes and edges. struct DependencyScan { - DependencyScan(State* state, DiskInterface* disk_interface) - : state_(state), disk_interface_(disk_interface) {} + DependencyScan(State* state, BuildLog* build_log, + DiskInterface* disk_interface) + : state_(state), build_log_(build_log), + disk_interface_(disk_interface) {} /// Examine inputs, outputs, and command lines to judge whether an edge /// needs to be re-run, and update outputs_ready_ and each outputs' |dirty_| @@ -217,11 +219,17 @@ struct DependencyScan { bool LoadDepFile(Edge* edge, string* err); - State* state_; - DiskInterface* disk_interface_; BuildLog* build_log() const { - return state_->build_log_; + return build_log_; } + void set_build_log(BuildLog* log) { + build_log_ = log; + } + + private: + State* state_; + BuildLog* build_log_; + DiskInterface* disk_interface_; }; #endif // NINJA_GRAPH_H_ diff --git a/src/graph_test.cc b/src/graph_test.cc index 2bc0c17..5b25c2f 100644 --- a/src/graph_test.cc +++ b/src/graph_test.cc @@ -17,7 +17,7 @@ #include "test.h" struct GraphTest : public StateTestWithBuiltinRules { - GraphTest() : scan_(&state_, &fs_) {} + GraphTest() : scan_(&state_, NULL, &fs_) {} VirtualFileSystem fs_; DependencyScan scan_; diff --git a/src/ninja.cc b/src/ninja.cc index 799af02..fb2bb3c 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -737,7 +737,6 @@ reload: return RunTool(tool, &globals, argc, argv); BuildLog build_log; - globals.state->build_log_ = &build_log; const string build_dir = globals.state->bindings_.LookupVariable("builddir"); const char* kLogPath = ".ninja_log"; @@ -770,7 +769,7 @@ reload: if (!rebuilt_manifest) { // Don't get caught in an infinite loop by a rebuild // target that is never up to date. - Builder manifest_builder(globals.state, globals.config, + Builder manifest_builder(globals.state, globals.config, &build_log, &globals.disk_interface); if (RebuildManifest(&manifest_builder, input_file, &err)) { rebuilt_manifest = true; @@ -782,7 +781,8 @@ reload: } } - Builder builder(globals.state, globals.config, &globals.disk_interface); + Builder builder(globals.state, globals.config, &build_log, + &globals.disk_interface); int result = RunBuild(&builder, argc, argv); if (g_metrics) { g_metrics->Report(); diff --git a/src/state.cc b/src/state.cc index 9f38fe9..4c7168b 100644 --- a/src/state.cc +++ b/src/state.cc @@ -24,7 +24,7 @@ const Rule State::kPhonyRule("phony"); -State::State() : build_log_(NULL) { +State::State() { AddRule(&kPhonyRule); } diff --git a/src/state.h b/src/state.h index 9197ef8..026acf3 100644 --- a/src/state.h +++ b/src/state.h @@ -23,7 +23,6 @@ using namespace std; #include "eval_env.h" #include "hash_map.h" -struct BuildLog; struct Edge; struct Node; struct Rule; @@ -71,7 +70,6 @@ struct State { BindingEnv bindings_; vector defaults_; - BuildLog* build_log_; }; #endif // NINJA_STATE_H_