From: idgay Date: Fri, 1 Jun 2007 23:07:20 +0000 (+0000) Subject: add -app option to nesdoc to generate app-level graphs X-Git-Tag: release_tools_1_2_4_1~155 X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=commitdiff_plain;h=e72d501c66169662d7ea42cf07fab6bba6b40bbc;p=tinyos-2.x.git add -app option to nesdoc to generate app-level graphs --- diff --git a/tools/tinyos/ncc/nesdoc-py/archive.py b/tools/tinyos/ncc/nesdoc-py/archive.py index d0acc400..ea9cbff0 100644 --- a/tools/tinyos/ncc/nesdoc-py/archive.py +++ b/tools/tinyos/ncc/nesdoc-py/archive.py @@ -40,6 +40,8 @@ from sys import * from getopt import getopt from string import * from nesdoc.utils import * +from nesdoc.graph import generate_graph +from nesdoc.html import * import os def check(x): @@ -52,11 +54,13 @@ def get1(x, tag): return check(xml_tagfind(x, tag)) def usage(): - print "Usage: %s [-t dir] [--topdir dir] [--preserve] repository" % argv[0] + print "Usage: %s [-t dir] [--topdir dir] [--preserve] [--app] repository" % argv[0] print " where -t/--topdir specify prefixes to remove from file names" print " to create nice, package-like names for interface and components" print " (based on their full filename)." print " If --preserve is specified, existing XML files are preserved." + print " If --app is specified, a page for this application is created in the" + print " current directory." print " The XML input is read from stdin." # Return package name for elem, or None if no valid name is found @@ -99,9 +103,10 @@ def canonicalisedir(dirname): return dirname # option processing. See usage string for details. -(opts, args) = getopt(argv[1:], "t:", [ "topdir=", "preserve" ]) -topopts = filter(lambda (x): x[0] != "--preserve", opts) +(opts, args) = getopt(argv[1:], "t:", [ "topdir=", "preserve", "app" ]) +topopts = filter(lambda (x): x[0] != "--preserve" and x[0] != "--app", opts) preserve = filter(lambda(x): x[0] == "--preserve", opts) != [] +app = filter(lambda(x): x[0] == "--app", opts) != [] topdirs = map(lambda (x): canonicalisedir(x[1]), topopts) if len(args) != 1: usage() @@ -172,6 +177,30 @@ for x in dom.getElementsByTagName("interfacedef-ref"): for x in dom.getElementsByTagName("component-ref"): set_nicename(x) +# Do the app stuff if requested +if app: + # The firt component is the main application component. + toplevel = xml_idx(components, 0) + name = toplevel.getAttribute("qname") + nicename = toplevel.getAttribute("nicename") + wiring = xml_tag(xml_tag(dom, "nesc"), "wiring") + generate_graph(".", repository, dom, wiring, name, nicename) + + ht = Html("%s.html" % nicename) + ht.title("Application: " + nicename) + ht.body() + ht.push("h2"); + ht.p("Application: " + nicename) + ht.popln(); + ht.pushln("map", 'name="comp"') + cmap = file("%s.cmap" % nicename) + for line in cmap.readlines(): + ht.pln(line) + cmap.close() + ht.popln() + ht.tag("img", 'src="%s.png"' % nicename, 'usemap="#comp"', 'id=imgwiring') + ht.close() + # save xml information per-interface and per-component in the specified # repository nmkdir(repository) diff --git a/tools/tinyos/ncc/nesdoc-py/components.py b/tools/tinyos/ncc/nesdoc-py/components.py index f6ee41ac..e27ac18d 100644 --- a/tools/tinyos/ncc/nesdoc-py/components.py +++ b/tools/tinyos/ncc/nesdoc-py/components.py @@ -116,5 +116,5 @@ def generate_component(comp): ht.pln(line) cmap.close() ht.popln() - ht.tag("img", 'src="%s.gif"' % nicename, 'usemap="#comp"', 'id=imgwiring') + ht.tag("img", 'src="%s.png"' % nicename, 'usemap="#comp"', 'id=imgwiring') ht.close() diff --git a/tools/tinyos/ncc/nesdoc-py/genhtml.py b/tools/tinyos/ncc/nesdoc-py/genhtml.py index 6aa3e6d9..e775198b 100644 --- a/tools/tinyos/ncc/nesdoc-py/genhtml.py +++ b/tools/tinyos/ncc/nesdoc-py/genhtml.py @@ -25,7 +25,7 @@ from nesdoc.utils import * from nesdoc.interfaces import generate_interface from nesdoc.components import generate_component -from nesdoc.graph import generate_graph +from nesdoc.graph import generate_component_graph from nesdoc.index import generate_indices from sys import * from re import search, compile @@ -84,7 +84,7 @@ for comp in compfiles: if search("\\.xml$", comp): stderr.write("component " + comp + "\n") ixml = parse("components/" + comp) - generate_graph(ixml.documentElement) + generate_component_graph(ixml.documentElement) generate_component(ixml.documentElement) ixml.unlink() diff --git a/tools/tinyos/ncc/nesdoc-py/graph.py b/tools/tinyos/ncc/nesdoc-py/graph.py index 28766c87..0fe7238d 100644 --- a/tools/tinyos/ncc/nesdoc-py/graph.py +++ b/tools/tinyos/ncc/nesdoc-py/graph.py @@ -14,13 +14,14 @@ from nesdoc.generators import * from sys import * from os import system -def generate_graph(comp): - name = comp.getAttribute("qname") - nicename = comp.getAttribute("nicename") - wiring = xml_tag(comp, "wiring") +def generate_component_graph(comp): + generate_graph("chtml", "..", comp, xml_tag(comp, "wiring"), + comp.getAttribute("qname"), comp.getAttribute("nicename")) + +def generate_graph(dir, repository, xml, wiring, name, nicename): if not wiring: return - + # Return the element definition for a given wiring endpoint def lookup_elem(endpoint): elemref = xml_tagset(endpoint, [ "interface-ref", "function-ref" ]) @@ -79,10 +80,10 @@ def generate_graph(comp): styles.append('label="%s"' % instanceof_name) else: styles.append('label="%s\\n(%s)"' % (instanceof_name, iname)) - styles.append('URL="%s.html"' % instanceof.getAttribute("nicename")) + styles.append('URL="%s/chtml/%s.html"' % (repository, instanceof.getAttribute("nicename"))) else: # Just a regular component - styles.append('URL="%s.html"' % ncomp.getAttribute("nicename")) + styles.append('URL="%s/chtml/%s.html"' % (repository, ncomp.getAttribute("nicename"))) if styles != []: gf.write("[%s]" % join(styles, ", ")) gf.write(";\n") @@ -116,7 +117,7 @@ def generate_graph(comp): styles = [ 'label="%s"' % sig ] if xml_tag(elem, "interface-parameters"): styles.append('style=bold') - styles.append('URL="../ihtml/%s.html"' % idef.getAttribute("nicename")) + styles.append('URL="%s/ihtml/%s.html"' % (repository, idef.getAttribute("nicename"))) styles.append("fontsize=10") return styles @@ -124,15 +125,15 @@ def generate_graph(comp): # build indices from ref attribute values to the corresponding elements refidx = {} compidx = {} - for intf in comp.getElementsByTagName("interface"): + for intf in xml.getElementsByTagName("interface"): refidx[intf.getAttribute("ref")] = intf - for fn in comp.getElementsByTagName("function"): + for fn in xml.getElementsByTagName("function"): refidx[fn.getAttribute("ref")] = fn - for ncomp in comp.getElementsByTagName("component"): + for ncomp in xml.getElementsByTagName("component"): compidx[ncomp.getAttribute("qname")] = ncomp # create the dot graph specification - gf = file("chtml/%s.dot" % nicename, "w") + gf = file("%s/%s.dot" % (dir, nicename), "w") gf.write('digraph "%s" {\n' % nicename) endpoints = {} @@ -149,5 +150,5 @@ def generate_graph(comp): gf.close() # Run dot twice to get a picture and cmap - system("dot -Tgif -ochtml/%s.gif chtml/%s.dot" % (nicename, nicename)) - system("dot -Tcmap -ochtml/%s.cmap chtml/%s.dot" % (nicename, nicename)) + system("dot -Tpng -o%s/%s.png %s/%s.dot" % (dir, nicename, dir, nicename)) + system("dot -Tcmap -o%s/%s.cmap %s/%s.dot" % (dir, nicename, dir, nicename)) diff --git a/tools/tinyos/ncc/nesdoc.in b/tools/tinyos/ncc/nesdoc.in index 783493b2..47a731de 100644 --- a/tools/tinyos/ncc/nesdoc.in +++ b/tools/tinyos/ncc/nesdoc.in @@ -93,6 +93,10 @@ for ($i = 0; $i <= $#ARGV; $i++) { $preserve = 1; $strip = 1; } + elsif (/^-app$/) { + $app = 1; + $strip = 1; + } } push @ncc_args, $_ if !$strip; } @@ -120,6 +124,7 @@ if ($genhtml) { # nesdoc-archive unshift @ncc_args, "-fsyntax-only"; +unshift @ncc_args, "-fnesc-dump=wiring" if $app; unshift @ncc_args, "-fnesc-dump=interfacedefs"; unshift @ncc_args, "-fnesc-dump=components(wiring)"; unshift @ncc_args, "-fnesc-dump=interfaces"; @@ -144,6 +149,7 @@ $toscontainer = `dirname $tosdir`; chomp $toscontainer; push @archive_args, "--topdir=$toscontainer"; push @archive_args, "--preserve" if $preserve; +push @archive_args, "--app" if $app; push @archive_args, "$docdir"; unshift @archive_args, "$libprogs/nesdoc/archive.py"; unshift @archive_args, $python; @@ -172,6 +178,10 @@ Usage: nesdoc -o nesdoc -o -html Generate nesdoc html pages from archived nesdoc information. + + nesdoc -o -app + Compile specified nesC application and generate a wiring graph + for the whole program in the current directory. EOM ) }