7 from headerutils import *
17 name = name[:-2] + ".h"
18 return name.replace("_", "-")
20 def pretty_name (name):
21 name = os.path.basename (name)
22 return name.replace(".","_").replace("-","_").replace("/","_").replace("+","_");
24 depstring = ("In file included from", " from")
26 # indentation indicates nesting levels of included files
27 ignore = [ "coretypes_h",
32 "insn_modes_inline_h",
54 def process_log_file (header, logfile):
55 if header_roots.get (header) != None:
56 print "Error: already processed log file: " + header + ".log"
58 hname = pretty_name (header)
59 header_roots[hname] = { }
65 if len (line) > 21 and line[:21] in depstring:
69 fn = re.findall(ur".*/(.*?):", line)
72 if fn[0][-2:] != ".h":
74 n = pretty_name (fn[0])
79 note = re.findall (ur"^.*note: (.*)", line)
81 sline.append (("note", note[0]))
83 err_msg = re.findall (ur"^.*: error: (.*)", line)
86 if (len (re.findall("error: forward declaration", line))) != 0:
88 path = re.findall (ur"^(.*?):.*error: ", line)
91 if path[0][-2:] != ".h":
93 fname = pretty_name (path[0])
94 if fname in ignore or fname[0:3] == "gt_":
96 sline.append (("error", msg, fname, incfrom))
98 print str(len(sline)) + " lines to process"
101 if line[0] != "note" and lastline[0] == "error":
104 incfrom = lastline[3]
107 if len(incfrom) != 0:
109 string = string + t + " : "
111 if ee not in extra_edges:
112 extra_edges.append (ee)
116 if hname not in nodes:
118 if fname not in nodes:
119 nodes.append (ofname)
125 if header_roots[hname].get(fname) == None:
126 header_roots[hname][fname] = list()
127 if msg not in header_roots[hname][fname]:
128 print string + ofname + " : " +msg
129 header_roots[hname][fname].append (msg)
133 dotname = "graph.dot"
134 graphname = "graph.png"
137 def build_dot_file (file_list):
138 output = open(dotname, "w")
139 output.write ("digraph incweb {\n");
141 if os.path.exists (x) and x[-4:] == ".log":
143 logfile = open(x).read().splitlines()
144 process_log_file (header, logfile)
145 elif os.path.exists (x + ".log"):
146 logfile = open(x + ".log").read().splitlines()
147 process_log_file (x, logfile)
151 label = n + " [ label = \"" + fn + "\" ];"
152 output.write (label + "\n")
153 if os.path.exists (fn):
154 h = open(fn).read().splitlines()
156 t = find_pound_include (l, True, False)
159 if t in ignore or t[-2:] != "_h":
164 if ee not in extra_edges:
165 extra_edges.append (ee)
168 for h in header_roots:
169 for dep in header_roots[h]:
170 label = " [ label = "+ str(len(header_roots[h][dep])) + " ];"
171 string = h + " -> " + dep + label
172 output.write (string + "\n");
174 depcount.append ((h, dep, len(header_roots[h][dep])))
176 for ee in extra_edges:
177 string = ee[0] + " -> " + ee[1] + "[ color=red ];"
178 output.write (string + "\n");
182 depcount.sort(key=lambda tup:tup[2])
184 print " ("+str(x[2])+ ") : " + x[0] + " -> " + x[1]
185 if (x[2] <= verbosity):
186 for l in header_roots[x[0]][x[1]]:
189 output.write ("}\n");
195 for arg in sys.argv[1:]:
197 dotname = arg[2:]+".dot"
198 graphname = arg[2:]+".png"
199 elif arg[0:2] == "-h":
201 elif arg[0:2] == "-v":
204 verbosity = int (arg[2:])
207 elif arg[0:1] == "-":
208 print "Unrecognized option " + arg
213 if len(sys.argv) == 1:
217 print "Parses the log files from the reduce-headers tool to generate"
218 print "dependency graphs for the include web for specified files."
219 print "Usage: [-nnum] [-h] [-v[n]] [-ooutput] file1 [[file2] ... [filen]]"
220 print " -ooutput : Specifies output to output.dot and output.png"
221 print " Defaults to 'graph.dot and graph.png"
222 print " -vn : verbose mode, shows the number of connections, and if n"
223 print " is specified, show the messages if # < n. 9 is infinity"
227 build_dot_file (files)
228 os.system ("dot -Tpng " + dotname + " -o" + graphname)