Merge pull request #1834 from jhasse/close-during-generator

Close BuildLog while running generators, fix #1724
diff --git a/src/build.cc b/src/build.cc
index e3131e2..2fb2aa4 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -828,6 +828,10 @@
     // See if we can start any more commands.
     if (failures_allowed && command_runner_->CanRunMore()) {
       if (Edge* edge = plan_.FindWork()) {
+        if (edge->GetBindingBool("generator")) {
+          scan_.build_log()->Close();
+        }
+
         if (!StartEdge(edge, err)) {
           Cleanup();
           status_->BuildFinished();
diff --git a/src/build_log.cc b/src/build_log.cc
index 04409c8..4dcd6ce 100644
--- a/src/build_log.cc
+++ b/src/build_log.cc
@@ -183,7 +183,7 @@
 }
 
 bool BuildLog::OpenForWriteIfNeeded() {
-  if (log_file_path_.empty()) {
+  if (log_file_ || log_file_path_.empty()) {
     return true;
   }
   log_file_ = fopen(log_file_path_.c_str(), "ab");
@@ -204,7 +204,6 @@
       return false;
     }
   }
-  log_file_path_.clear();
   return true;
 }