Permalink
Browse files

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.)
  • Loading branch information...
1 parent 703dcff commit 1e11c8a6bd119025efd8725370ffa42354f92f88 @evmar evmar committed Sep 4, 2012
Showing with 32 additions and 22 deletions.
  1. +4 −5 src/build.cc
  2. +6 −2 src/build.h
  3. +3 −2 src/build_test.cc
  4. +1 −1 src/disk_interface_test.cc
  5. +13 −5 src/graph.h
  6. +1 −1 src/graph_test.cc
  7. +3 −3 src/ninja.cc
  8. +1 −1 src/state.cc
  9. +0 −2 src/state.h
View
@@ -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);
}
View
@@ -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<CommandRunner> command_runner_;
BuildStatus* status_;
- BuildLog* log_;
private:
DiskInterface* disk_interface_;
View
@@ -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_;
@@ -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);
View
@@ -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_
View
@@ -17,7 +17,7 @@
#include "test.h"
struct GraphTest : public StateTestWithBuiltinRules {
- GraphTest() : scan_(&state_, &fs_) {}
+ GraphTest() : scan_(&state_, NULL, &fs_) {}
VirtualFileSystem fs_;
DependencyScan scan_;
View
@@ -737,7 +737,6 @@ int NinjaMain(int argc, char** argv) {
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 @@ int NinjaMain(int argc, char** argv) {
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 @@ int NinjaMain(int argc, char** argv) {
}
}
- 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();
View
@@ -24,7 +24,7 @@
const Rule State::kPhonyRule("phony");
-State::State() : build_log_(NULL) {
+State::State() {
AddRule(&kPhonyRule);
}
View
@@ -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<Node*> defaults_;
- BuildLog* build_log_;
};
#endif // NINJA_STATE_H_

0 comments on commit 1e11c8a

Please sign in to comment.