diff options
author | Evan Martin <martine@danga.com> | 2012-09-04 22:08:41 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2012-09-04 22:09:00 (GMT) |
commit | 81a5d01bac7bc3302c8ab1c625d357a625f90dcf (patch) | |
tree | 8f13a77a2316172e71bbb3c46ea4a4a338420316 /src/ninja.cc | |
parent | 4d9bf949e0fd6976725dea12bcc254fd39da6490 (diff) | |
download | Ninja-81a5d01bac7bc3302c8ab1c625d357a625f90dcf.zip Ninja-81a5d01bac7bc3302c8ab1c625d357a625f90dcf.tar.gz Ninja-81a5d01bac7bc3302c8ab1c625d357a625f90dcf.tar.bz2 |
pass Builder as arg to build-running functions
Reducing use of globals.
Diffstat (limited to 'src/ninja.cc')
-rw-r--r-- | src/ninja.cc | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/ninja.cc b/src/ninja.cc index 13c0592..799af02 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -122,22 +122,20 @@ struct RealFileReader : public ManifestParser::FileReader { /// Rebuild the build manifest, if necessary. /// Returns true if the manifest was rebuilt. -bool RebuildManifest(Globals* globals, const char* input_file, string* err) { +bool RebuildManifest(Builder* builder, const char* input_file, string* err) { string path = input_file; if (!CanonicalizePath(&path, err)) return false; - Node* node = globals->state->LookupNode(path); + Node* node = builder->state_->LookupNode(path); if (!node) return false; - Builder manifest_builder(globals->state, globals->config, - &globals->disk_interface); - if (!manifest_builder.AddTarget(node, err)) + if (!builder->AddTarget(node, err)) return false; - if (manifest_builder.AlreadyUpToDate()) + if (builder->AlreadyUpToDate()) return false; // Not an error, but we didn't rebuild. - if (!manifest_builder.Build(err)) + if (!builder->Build(err)) return false; // The manifest was only rebuilt if it is now dirty (it may have been cleaned @@ -571,17 +569,16 @@ bool DebugEnable(const string& name, Globals* globals) { } } -int RunBuild(Globals* globals, int argc, char** argv) { +int RunBuild(Builder* builder, int argc, char** argv) { string err; vector<Node*> targets; - if (!CollectTargetsFromArgs(globals->state, argc, argv, &targets, &err)) { + if (!CollectTargetsFromArgs(builder->state_, argc, argv, &targets, &err)) { Error("%s", err.c_str()); return 1; } - Builder builder(globals->state, globals->config, &globals->disk_interface); for (size_t i = 0; i < targets.size(); ++i) { - if (!builder.AddTarget(targets[i], &err)) { + if (!builder->AddTarget(targets[i], &err)) { if (!err.empty()) { Error("%s", err.c_str()); return 1; @@ -592,12 +589,12 @@ int RunBuild(Globals* globals, int argc, char** argv) { } } - if (builder.AlreadyUpToDate()) { + if (builder->AlreadyUpToDate()) { printf("ninja: no work to do.\n"); return 0; } - if (!builder.Build(&err)) { + if (!builder->Build(&err)) { printf("ninja: build stopped: %s.\n", err.c_str()); return 1; } @@ -773,7 +770,9 @@ reload: if (!rebuilt_manifest) { // Don't get caught in an infinite loop by a rebuild // target that is never up to date. - if (RebuildManifest(&globals, input_file, &err)) { + Builder manifest_builder(globals.state, globals.config, + &globals.disk_interface); + if (RebuildManifest(&manifest_builder, input_file, &err)) { rebuilt_manifest = true; globals.ResetState(); goto reload; @@ -783,7 +782,8 @@ reload: } } - int result = RunBuild(&globals, argc, argv); + Builder builder(globals.state, globals.config, &globals.disk_interface); + int result = RunBuild(&builder, argc, argv); if (g_metrics) { g_metrics->Report(); |