Factor out State struct from ninja_jumble.cc into its header/source files.
authorThiago Farina <tfarina@chromium.org>
Fri, 26 Aug 2011 23:58:28 +0000 (20:58 -0300)
committerThiago Farina <tfarina@chromium.org>
Sat, 3 Sep 2011 18:16:08 +0000 (15:16 -0300)
This was a TODO in src/ninja_jumble.cc. Now this task is completed.

Signed-off-by: Thiago Farina <tfarina@chromium.org>
13 files changed:
configure.py
src/browse.cc
src/build.cc
src/build_log.cc
src/clean.cc
src/graph.cc
src/ninja.cc
src/ninja_test.cc
src/parsers.cc
src/parsers_test.cc
src/state.cc [moved from src/ninja_jumble.cc with 92% similarity]
src/state.h [moved from src/ninja.h with 91% similarity]
src/test.h

index c374f6d..8308c6d 100755 (executable)
@@ -131,8 +131,7 @@ if platform not in ('mingw'):
 
 n.comment('Core source files all build into ninja library.')
 for name in ['build', 'build_log', 'clean', 'eval_env', 'graph', 'graphviz',
-             'parsers', 'util', 'stat_cache',
-             'ninja_jumble', 'disk_interface']:
+             'parsers', 'util', 'stat_cache', 'disk_interface', 'state']:
     objs += cxx(name)
 if platform == 'mingw':
     objs += cxx('subprocess-win32')
index d51bb44..bab3f36 100644 (file)
 #include "browse.h"
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 
 #include "../build/browse_py.h"
-#include "ninja.h"
 
 void RunBrowsePython(State* state, const char* ninja_command,
                      const char* initial_target) {
index 1c8a4fa..3b7d5b8 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "build.h"
 
+#include <assert.h>
 #include <stdio.h>
 
 #ifdef _WIN32
@@ -27,7 +28,7 @@
 #include "build_log.h"
 #include "disk_interface.h"
 #include "graph.h"
-#include "ninja.h"
+#include "state.h"
 #include "subprocess.h"
 #include "util.h"
 
index c3ae1ab..b21a755 100644 (file)
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include "build.h"
 #include "graph.h"
-#include "ninja.h"
 
 // Implementation details:
 // Each run's log appends to the log file.
index 31641d2..16ca5e5 100644 (file)
@@ -23,7 +23,7 @@
 #include "build.h"
 #include "disk_interface.h"
 #include "graph.h"
-#include "ninja.h"
+#include "state.h"
 #include "util.h"
 
 Cleaner::Cleaner(State* state, const BuildConfig& config)
index 5517f17..9b5f10b 100644 (file)
 
 #include "graph.h"
 
+#include <assert.h>
 #include <stdio.h>
 
 #include "build_log.h"
 #include "disk_interface.h"
-#include "ninja.h"
 #include "parsers.h"
+#include "state.h"
 #include "util.h"
 
 bool FileStat::Stat(DiskInterface* disk_interface) {
index 6bf7fbd..8f972f3 100644 (file)
@@ -12,8 +12,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include "ninja.h"
-
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
 #include "browse.h"
 #include "build.h"
 #include "build_log.h"
+#include "clean.h"
 #include "graph.h"
 #include "graphviz.h"
 #include "parsers.h"
+#include "state.h"
 #include "util.h"
-#include "clean.h"
 
 namespace {
 
index a5ef3ab..2bdd08f 100644 (file)
@@ -12,8 +12,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include "ninja.h"
-
 #ifdef _WIN32
 #include <io.h>
 #include <windows.h>
index 420a6cf..7f587a6 100644 (file)
@@ -20,7 +20,7 @@
 #include <string.h>
 
 #include "graph.h"
-#include "ninja.h"
+#include "state.h"
 #include "util.h"
 
 string Token::AsString() const {
index b5d253f..1ac5990 100644 (file)
@@ -17,7 +17,7 @@
 #include <gtest/gtest.h>
 
 #include "graph.h"
-#include "ninja.h"
+#include "state.h"
 
 struct ParserTest : public testing::Test,
                     public ManifestParser::FileReader {
similarity index 92%
rename from src/ninja_jumble.cc
rename to src/state.cc
index faea156..e1fe675 100644 (file)
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-// This file is all the code that used to be in one file.
-// TODO: split into modules, delete this file.
+#include "state.h"
 
-#include "ninja.h"
+#include <assert.h>
 
-#include <errno.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "build_log.h"
 #include "graph.h"
 #include "util.h"
 
@@ -32,6 +25,11 @@ State::State() : build_log_(NULL) {
   AddRule(&kPhonyRule);
 }
 
+void State::AddRule(const Rule* rule) {
+  assert(LookupRule(rule->name_) == NULL);
+  rules_[rule->name_] = rule;
+}
+
 const Rule* State::LookupRule(const string& rule_name) {
   map<string, const Rule*>::iterator i = rules_.find(rule_name);
   if (i == rules_.end())
@@ -39,11 +37,6 @@ const Rule* State::LookupRule(const string& rule_name) {
   return i->second;
 }
 
-void State::AddRule(const Rule* rule) {
-  assert(LookupRule(rule->name_) == NULL);
-  rules_[rule->name_] = rule;
-}
-
 Edge* State::AddEdge(const Rule* rule) {
   Edge* edge = new Edge();
   edge->rule_ = rule;
@@ -52,17 +45,17 @@ Edge* State::AddEdge(const Rule* rule) {
   return edge;
 }
 
-Node* State::LookupNode(const string& path) {
+Node* State::GetNode(const string& path) {
   FileStat* file = stat_cache_.GetFile(path);
   if (!file->node_)
-    return NULL;
+    file->node_ = new Node(file);
   return file->node_;
 }
 
-Node* State::GetNode(const string& path) {
+Node* State::LookupNode(const string& path) {
   FileStat* file = stat_cache_.GetFile(path);
   if (!file->node_)
-    file->node_ = new Node(file);
+    return NULL;
   return file->node_;
 }
 
@@ -87,7 +80,7 @@ bool State::AddDefault(const string& path, string* err) {
   if (!node) {
     *err = "unknown target '" + path + "'";
     return false;
-  } 
+  }
   defaults_.push_back(node);
   return true;
 }
similarity index 91%
rename from src/ninja.h
rename to src/state.h
index 448a060..ceb7c05 100644 (file)
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#ifndef NINJA_NINJA_H_
-#define NINJA_NINJA_H_
+#ifndef NINJA_STATE_H_
+#define NINJA_STATE_H_
+#pragma once
 
-#include <assert.h>
-
-#include <algorithm>
-#include <queue>
-#include <set>
+#include <map>
 #include <string>
 #include <vector>
 
 
 using namespace std;
 
+struct BuildLog;
 struct Edge;
-struct FileStat;
 struct Node;
 struct Rule;
 
 /// Global state (file status, loaded rules) for a single run.
 struct State {
-  State();
+  static const Rule kPhonyRule;
 
-  StatCache* stat_cache() { return &stat_cache_; }
+  State();
 
   void AddRule(const Rule* rule);
   const Rule* LookupRule(const string& rule_name);
@@ -47,21 +44,25 @@ struct State {
   void AddIn(Edge* edge, const string& path);
   void AddOut(Edge* edge, const string& path);
   bool AddDefault(const string& path, string* error);
+
   /// @return the root node(s) of the graph. (Root nodes have no output edges).
   /// @param error where to write the error message if somethings went wrong.
   vector<Node*> RootNodes(string* error);
   vector<Node*> DefaultNodes(string* error);
 
+  StatCache* stat_cache() { return &stat_cache_; }
+
   StatCache stat_cache_;
+
   /// All the rules used in the graph.
   map<string, const Rule*> rules_;
+
   /// All the edges of the graph.
   vector<Edge*> edges_;
+
   BindingEnv bindings_;
   vector<Node*> defaults_;
   struct BuildLog* build_log_;
-
-  static const Rule kPhonyRule;
 };
 
-#endif  // NINJA_NINJA_H_
+#endif  // NINJA_STATE_H_
index 3436ef1..c27e051 100644 (file)
@@ -18,7 +18,7 @@
 #include <gtest/gtest.h>
 
 #include "disk_interface.h"
-#include "ninja.h"
+#include "state.h"
 
 // Support utilites for tests.