1 // Copyright 2011 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
22 void GraphViz::AddTarget(Node* node) {
23 if (visited_nodes_.find(node) != visited_nodes_.end())
26 string pathstr = node->path();
27 replace(pathstr.begin(), pathstr.end(), '\\', '/');
28 printf("\"%p\" [label=\"%s\"]\n", node, pathstr.c_str());
29 visited_nodes_.insert(node);
31 Edge* edge = node->in_edge();
39 if (visited_edges_.find(edge) != visited_edges_.end())
41 visited_edges_.insert(edge);
43 if (edge->inputs_.size() == 1 && edge->outputs_.size() == 1) {
45 // Note extra space before label text -- this is cosmetic and feels
46 // like a graphviz bug.
47 printf("\"%p\" -> \"%p\" [label=\" %s\"]\n",
48 edge->inputs_[0], edge->outputs_[0], edge->rule_->name().c_str());
50 printf("\"%p\" [label=\"%s\", shape=ellipse]\n",
51 edge, edge->rule_->name().c_str());
52 for (vector<Node*>::iterator out = edge->outputs_.begin();
53 out != edge->outputs_.end(); ++out) {
54 printf("\"%p\" -> \"%p\"\n", edge, *out);
56 for (vector<Node*>::iterator in = edge->inputs_.begin();
57 in != edge->inputs_.end(); ++in) {
58 const char* order_only = "";
59 if (edge->is_order_only(in - edge->inputs_.begin()))
60 order_only = " style=dotted";
61 printf("\"%p\" -> \"%p\" [arrowhead=none%s]\n", (*in), edge, order_only);
65 for (vector<Node*>::iterator in = edge->inputs_.begin();
66 in != edge->inputs_.end(); ++in) {
71 void GraphViz::Start() {
72 printf("digraph ninja {\n");
73 printf("rankdir=\"LR\"\n");
74 printf("node [fontsize=10, shape=box, height=0.25]\n");
75 printf("edge [fontsize=10]\n");
78 void GraphViz::Finish() {