This was a TODO in src/ninja_jumble.cc. Now this task is completed.
Signed-off-by: Thiago Farina <tfarina@chromium.org>
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')
#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) {
#include "build.h"
+#include <assert.h>
#include <stdio.h>
#ifdef _WIN32
#include "build_log.h"
#include "disk_interface.h"
#include "graph.h"
-#include "ninja.h"
+#include "state.h"
#include "subprocess.h"
#include "util.h"
#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.
#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)
#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) {
// 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 {
+++ /dev/null
-// Copyright 2011 Google Inc. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef NINJA_NINJA_H_
-#define NINJA_NINJA_H_
-
-#include <assert.h>
-
-#include <algorithm>
-#include <queue>
-#include <set>
-#include <string>
-#include <vector>
-
-#include "eval_env.h"
-#include "stat_cache.h"
-
-using namespace std;
-
-struct Edge;
-struct FileStat;
-struct Node;
-struct Rule;
-
-/// Global state (file status, loaded rules) for a single run.
-struct State {
- State();
-
- StatCache* stat_cache() { return &stat_cache_; }
-
- void AddRule(const Rule* rule);
- const Rule* LookupRule(const string& rule_name);
- Edge* AddEdge(const Rule* rule);
- Node* GetNode(const string& path);
- Node* LookupNode(const string& path);
- 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_;
- /// 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_
+++ /dev/null
-// Copyright 2011 Google Inc. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// 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 "ninja.h"
-
-#include <errno.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "build_log.h"
-#include "graph.h"
-#include "util.h"
-
-const Rule State::kPhonyRule("phony");
-
-State::State() : build_log_(NULL) {
- AddRule(&kPhonyRule);
-}
-
-const Rule* State::LookupRule(const string& rule_name) {
- map<string, const Rule*>::iterator i = rules_.find(rule_name);
- if (i == rules_.end())
- return NULL;
- 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;
- edge->env_ = &bindings_;
- edges_.push_back(edge);
- return edge;
-}
-
-Node* State::LookupNode(const string& path) {
- FileStat* file = stat_cache_.GetFile(path);
- if (!file->node_)
- return NULL;
- return file->node_;
-}
-
-Node* State::GetNode(const string& path) {
- FileStat* file = stat_cache_.GetFile(path);
- if (!file->node_)
- file->node_ = new Node(file);
- return file->node_;
-}
-
-void State::AddIn(Edge* edge, const string& path) {
- Node* node = GetNode(path);
- edge->inputs_.push_back(node);
- node->out_edges_.push_back(edge);
-}
-
-void State::AddOut(Edge* edge, const string& path) {
- Node* node = GetNode(path);
- edge->outputs_.push_back(node);
- if (node->in_edge_) {
- Warning("multiple rules generate %s. "
- "build will not be correct; continuing anyway", path.c_str());
- }
- node->in_edge_ = edge;
-}
-
-bool State::AddDefault(const string& path, string* err) {
- Node* node = LookupNode(path);
- if (!node) {
- *err = "unknown target '" + path + "'";
- return false;
- }
- defaults_.push_back(node);
- return true;
-}
-
-vector<Node*> State::RootNodes(string* err) {
- vector<Node*> root_nodes;
- // Search for nodes with no output.
- for (vector<Edge*>::iterator e = edges_.begin(); e != edges_.end(); ++e) {
- for (vector<Node*>::iterator out = (*e)->outputs_.begin();
- out != (*e)->outputs_.end(); ++out) {
- if ((*out)->out_edges_.empty())
- root_nodes.push_back(*out);
- }
- }
-
- if (!edges_.empty() && root_nodes.empty())
- *err = "could not determine root nodes of build graph";
-
- assert(edges_.empty() || !root_nodes.empty());
- return root_nodes;
-}
-
-vector<Node*> State::DefaultNodes(string* err) {
- return defaults_.empty() ? RootNodes(err) : defaults_;
-}
// 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>
#include <string.h>
#include "graph.h"
-#include "ninja.h"
+#include "state.h"
#include "util.h"
string Token::AsString() const {
#include <gtest/gtest.h>
#include "graph.h"
-#include "ninja.h"
+#include "state.h"
struct ParserTest : public testing::Test,
public ManifestParser::FileReader {
--- /dev/null
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "state.h"
+
+#include <assert.h>
+
+#include "graph.h"
+#include "util.h"
+
+const Rule State::kPhonyRule("phony");
+
+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())
+ return NULL;
+ return i->second;
+}
+
+Edge* State::AddEdge(const Rule* rule) {
+ Edge* edge = new Edge();
+ edge->rule_ = rule;
+ edge->env_ = &bindings_;
+ edges_.push_back(edge);
+ return edge;
+}
+
+Node* State::GetNode(const string& path) {
+ FileStat* file = stat_cache_.GetFile(path);
+ if (!file->node_)
+ file->node_ = new Node(file);
+ return file->node_;
+}
+
+Node* State::LookupNode(const string& path) {
+ FileStat* file = stat_cache_.GetFile(path);
+ if (!file->node_)
+ return NULL;
+ return file->node_;
+}
+
+void State::AddIn(Edge* edge, const string& path) {
+ Node* node = GetNode(path);
+ edge->inputs_.push_back(node);
+ node->out_edges_.push_back(edge);
+}
+
+void State::AddOut(Edge* edge, const string& path) {
+ Node* node = GetNode(path);
+ edge->outputs_.push_back(node);
+ if (node->in_edge_) {
+ Warning("multiple rules generate %s. "
+ "build will not be correct; continuing anyway", path.c_str());
+ }
+ node->in_edge_ = edge;
+}
+
+bool State::AddDefault(const string& path, string* err) {
+ Node* node = LookupNode(path);
+ if (!node) {
+ *err = "unknown target '" + path + "'";
+ return false;
+ }
+ defaults_.push_back(node);
+ return true;
+}
+
+vector<Node*> State::RootNodes(string* err) {
+ vector<Node*> root_nodes;
+ // Search for nodes with no output.
+ for (vector<Edge*>::iterator e = edges_.begin(); e != edges_.end(); ++e) {
+ for (vector<Node*>::iterator out = (*e)->outputs_.begin();
+ out != (*e)->outputs_.end(); ++out) {
+ if ((*out)->out_edges_.empty())
+ root_nodes.push_back(*out);
+ }
+ }
+
+ if (!edges_.empty() && root_nodes.empty())
+ *err = "could not determine root nodes of build graph";
+
+ assert(edges_.empty() || !root_nodes.empty());
+ return root_nodes;
+}
+
+vector<Node*> State::DefaultNodes(string* err) {
+ return defaults_.empty() ? RootNodes(err) : defaults_;
+}
--- /dev/null
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef NINJA_STATE_H_
+#define NINJA_STATE_H_
+#pragma once
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "eval_env.h"
+#include "stat_cache.h"
+
+using namespace std;
+
+struct BuildLog;
+struct Edge;
+struct Node;
+struct Rule;
+
+/// Global state (file status, loaded rules) for a single run.
+struct State {
+ static const Rule kPhonyRule;
+
+ State();
+
+ void AddRule(const Rule* rule);
+ const Rule* LookupRule(const string& rule_name);
+ Edge* AddEdge(const Rule* rule);
+ Node* GetNode(const string& path);
+ Node* LookupNode(const string& path);
+ 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_;
+};
+
+#endif // NINJA_STATE_H_
#include <gtest/gtest.h>
#include "disk_interface.h"
-#include "ninja.h"
+#include "state.h"
// Support utilites for tests.