summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Farina <tfarina@chromium.org>2011-03-07 22:34:25 (GMT)
committerEvan Martin <martine@danga.com>2011-03-07 22:34:48 (GMT)
commit835983365c3730dbd93baa1b17f42f3cd6579999 (patch)
treefdab1fd6349251ef4b2418dc2124374acf534935
parent58a2b6d560f1749f3c275c7a289ddb2168a045f7 (diff)
downloadNinja-835983365c3730dbd93baa1b17f42f3cd6579999.zip
Ninja-835983365c3730dbd93baa1b17f42f3cd6579999.tar.gz
Ninja-835983365c3730dbd93baa1b17f42f3cd6579999.tar.bz2
move the implementation of GraphViz to source file
-rw-r--r--build.ninja5
-rw-r--r--src/graphviz.cc72
-rw-r--r--src/graphviz.h59
-rw-r--r--src/ninja.cc4
4 files changed, 82 insertions, 58 deletions
diff --git a/build.ninja b/build.ninja
index b8c900a..c993ecf 100644
--- a/build.ninja
+++ b/build.ninja
@@ -43,14 +43,15 @@ build $builddir/build.o: cxx src/build.cc
build $builddir/build_log.o: cxx src/build_log.cc
build $builddir/eval_env.o: cxx src/eval_env.cc
build $builddir/graph.o: cxx src/graph.cc
+build $builddir/graphviz.o: cxx src/graphviz.cc
build $builddir/parsers.o: cxx src/parsers.cc
build $builddir/subprocess.o: cxx src/subprocess.cc
build $builddir/util.o: cxx src/util.cc
build $builddir/ninja_jumble.o: cxx src/ninja_jumble.cc
build $builddir/ninja.a: ar $builddir/browse.o $builddir/build.o \
$builddir/build_log.o $builddir/eval_env.o $builddir/graph.o \
- $builddir/parsers.o $builddir/subprocess.o $builddir/util.o \
- $builddir/ninja_jumble.o
+ $builddir/graphviz.o $builddir/parsers.o $builddir/subprocess.o \
+ $builddir/util.o $builddir/ninja_jumble.o
build $builddir/ninja.o: cxx src/ninja.cc
build ninja: link $builddir/ninja.o $builddir/ninja.a
diff --git a/src/graphviz.cc b/src/graphviz.cc
new file mode 100644
index 0000000..aa75ea1
--- /dev/null
+++ b/src/graphviz.cc
@@ -0,0 +1,72 @@
+// 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 "graphviz.h"
+
+#include <stdio.h>
+
+#include "graph.h"
+
+void GraphViz::AddTarget(Node* node) {
+ if (visited_.find(node) != visited_.end())
+ return;
+
+ printf("\"%p\" [label=\"%s\"]\n", node, node->file_->path_.c_str());
+ visited_.insert(node);
+
+ if (!node->in_edge_) {
+ // Leaf node.
+ // Draw as a rect?
+ return;
+ }
+
+ Edge* edge = node->in_edge_;
+
+ if (edge->inputs_.size() == 1 && edge->outputs_.size() == 1) {
+ // Can draw simply.
+ // Note extra space before label text -- this is cosmetic and feels
+ // like a graphviz bug.
+ printf("\"%p\" -> \"%p\" [label=\" %s\"]\n",
+ edge->inputs_[0], edge->outputs_[0], edge->rule_->name_.c_str());
+ } else {
+ printf("\"%p\" [label=\"%s\", shape=ellipse]\n",
+ edge, edge->rule_->name_.c_str());
+ for (vector<Node*>::iterator out = edge->outputs_.begin();
+ out != edge->outputs_.end(); ++out) {
+ printf("\"%p\" -> \"%p\"\n", edge, *out);
+ }
+ for (vector<Node*>::iterator in = edge->inputs_.begin();
+ in != edge->inputs_.end(); ++in) {
+ const char* order_only = "";
+ if (edge->is_order_only(in - edge->inputs_.begin()))
+ order_only = " style=dotted";
+ printf("\"%p\" -> \"%p\" [arrowhead=none%s]\n", (*in), edge, order_only);
+ }
+ }
+
+ for (vector<Node*>::iterator in = edge->inputs_.begin();
+ in != edge->inputs_.end(); ++in) {
+ AddTarget(*in);
+ }
+}
+
+void GraphViz::Start() {
+ printf("digraph ninja {\n");
+ printf("node [fontsize=10, shape=box, height=0.25]\n");
+ printf("edge [fontsize=10]\n");
+}
+
+void GraphViz::Finish() {
+ printf("}\n");
+}
diff --git a/src/graphviz.h b/src/graphviz.h
index fd6b58e..f9b19b6 100644
--- a/src/graphviz.h
+++ b/src/graphviz.h
@@ -12,10 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#ifndef NINJA_GRAPHVIZ_H_
+#define NINJA_GRAPHVIZ_H_
+
#include <set>
+using namespace std;
-// XXX deinline all this code so we don't need this include
-#include "graph.h"
struct Node;
struct GraphViz {
@@ -26,55 +28,4 @@ struct GraphViz {
set<Node*> visited_;
};
-void GraphViz::AddTarget(Node* node) {
- if (visited_.find(node) != visited_.end())
- return;
- printf("\"%p\" [label=\"%s\"]\n", node, node->file_->path_.c_str());
- visited_.insert(node);
-
- if (!node->in_edge_) {
- // Leaf node.
- // Draw as a rect?
- return;
- }
-
- Edge* edge = node->in_edge_;
-
- if (edge->inputs_.size() == 1 && edge->outputs_.size() == 1) {
- // Can draw simply.
- // Note extra space before label text -- this is cosmetic and feels
- // like a graphviz bug.
- printf("\"%p\" -> \"%p\" [label=\" %s\"]\n",
- edge->inputs_[0], edge->outputs_[0], edge->rule_->name_.c_str());
- } else {
- printf("\"%p\" [label=\"%s\", shape=ellipse]\n",
- edge, edge->rule_->name_.c_str());
- for (vector<Node*>::iterator out = edge->outputs_.begin();
- out != edge->outputs_.end(); ++out) {
- printf("\"%p\" -> \"%p\"\n", edge, *out);
- }
- for (vector<Node*>::iterator in = edge->inputs_.begin();
- in != edge->inputs_.end(); ++in) {
- const char* order_only = "";
- if (edge->is_order_only(in - edge->inputs_.begin()))
- order_only = " style=dotted";
- printf("\"%p\" -> \"%p\" [arrowhead=none%s]\n", (*in), edge, order_only);
- }
- }
-
- for (vector<Node*>::iterator in = edge->inputs_.begin();
- in != edge->inputs_.end(); ++in) {
- AddTarget(*in);
- }
-}
-
-void GraphViz::Start() {
- printf("digraph ninja {\n");
- printf("node [fontsize=10, shape=box, height=0.25]\n");
- printf("edge [fontsize=10]\n");
-}
-
-void GraphViz::Finish() {
- printf("}\n");
-}
-
+#endif // NINJA_GRAPHVIZ_H_
diff --git a/src/ninja.cc b/src/ninja.cc
index 8c46833..c113bfb 100644
--- a/src/ninja.cc
+++ b/src/ninja.cc
@@ -31,9 +31,9 @@
#include "browse.h"
#include "build.h"
#include "build_log.h"
-#include "parsers.h"
-
+#include "graph.h"
#include "graphviz.h"
+#include "parsers.h"
option options[] = {
{ "help", no_argument, NULL, 'h' },