diff options
author | Evan Martin <martine@danga.com> | 2012-09-05 16:14:39 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2012-09-05 16:14:39 (GMT) |
commit | c84ee51b5a8f4587db2141f04e5da45f2f0ada9b (patch) | |
tree | b604894009cdd11969f38832e056927246d4f27b /src/ninja.cc | |
parent | d6ff278e22c3392704eec71250584e21966534fe (diff) | |
download | Ninja-c84ee51b5a8f4587db2141f04e5da45f2f0ada9b.zip Ninja-c84ee51b5a8f4587db2141f04e5da45f2f0ada9b.tar.gz Ninja-c84ee51b5a8f4587db2141f04e5da45f2f0ada9b.tar.bz2 |
factor out build log load from main
Diffstat (limited to 'src/ninja.cc')
-rw-r--r-- | src/ninja.cc | 65 |
1 files changed, 37 insertions, 28 deletions
diff --git a/src/ninja.cc b/src/ninja.cc index d194699..c55ba38 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -573,6 +573,42 @@ bool DebugEnable(const string& name, Globals* globals) { } } +bool OpenLog(BuildLog* build_log, Globals* globals, + DiskInterface* disk_interface) { + const string build_dir = + globals->state->bindings_.LookupVariable("builddir"); + const char* kLogPath = ".ninja_log"; + string log_path = kLogPath; + if (!build_dir.empty()) { + log_path = build_dir + "/" + kLogPath; + if (!disk_interface->MakeDirs(log_path) && errno != EEXIST) { + Error("creating build directory %s: %s", + build_dir.c_str(), strerror(errno)); + return false; + } + } + + string err; + if (!build_log->Load(log_path, &err)) { + Error("loading build log %s: %s", log_path.c_str(), err.c_str()); + return false; + } + if (!err.empty()) { + // Hack: Load() can return a warning via err by returning true. + Warning("%s", err.c_str()); + err.clear(); + } + + if (!globals->config->dry_run) { + if (!build_log->OpenForWrite(log_path, &err)) { + Error("opening build log: %s", err.c_str()); + return false; + } + } + + return true; +} + int RunBuild(Builder* builder, int argc, char** argv) { string err; vector<Node*> targets; @@ -756,35 +792,8 @@ reload: return tool_func(&globals, argc, argv); BuildLog build_log; - - const string build_dir = globals.state->bindings_.LookupVariable("builddir"); - const char* kLogPath = ".ninja_log"; - string log_path = kLogPath; - if (!build_dir.empty()) { - log_path = build_dir + "/" + kLogPath; - if (!disk_interface.MakeDirs(log_path) && errno != EEXIST) { - Error("creating build directory %s: %s", - build_dir.c_str(), strerror(errno)); - return 1; - } - } - - if (!build_log.Load(log_path, &err)) { - Error("loading build log %s: %s", log_path.c_str(), err.c_str()); + if (!OpenLog(&build_log, &globals, &disk_interface)) return 1; - } - if (!err.empty()) { - // Hack: Load() can return a warning via err by returning true. - Warning("%s", err.c_str()); - err.clear(); - } - - if (!config.dry_run) { - if (!build_log.OpenForWrite(log_path, &err)) { - Error("opening build log: %s", err.c_str()); - return 1; - } - } if (!rebuilt_manifest) { // Don't get caught in an infinite loop by a rebuild // target that is never up to date. |