Mercurial > hg > truffle
diff mx/commands.py @ 5706:6f2ccb483d96
added overview.html for each project and integrated it into the generated 'mx site' command
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 27 Jun 2012 18:06:03 +0200 |
parents | 12a34d1bcaa2 |
children | e149c0e252e0 |
line wrap: on
line diff
--- a/mx/commands.py Wed Jun 27 15:40:03 2012 +0200 +++ b/mx/commands.py Wed Jun 27 18:06:03 2012 +0200 @@ -1001,12 +1001,77 @@ mx.abort('jacocoreport takes only one argument : an output directory') mx.run_java(['-jar', jacocoreport.get_path(True), '-in', 'jacoco.exec', '-g', join(_graal_home, 'graal'), out]) +def _fix_overview_summary(path, topLink): + """ + Processes an "overview-summary.html" generated by javadoc to put the complete + summary text above the Packages table. + """ + + # This uses scraping and so will break if the relevant content produced by javadoc changes in any way! + orig = path + '.orig' + if exists(orig): + with open(orig) as fp: + content = fp.read() + else: + with open(path) as fp: + content = fp.read() + with open(orig, 'w') as fp: + fp.write(content) + + class Chunk: + def __init__(self, content, ldelim, rdelim): + lindex = content.find(ldelim) + rindex = content.find(rdelim) + self.ldelim = ldelim + self.rdelim = rdelim + if lindex != -1 and rindex != -1 and rindex > lindex: + self.text = content[lindex + len(ldelim):rindex] + else: + self.text = None + + def replace(self, content, repl): + lindex = content.find(self.ldelim) + rindex = content.find(self.rdelim) + old = content[lindex:rindex + len(self.rdelim)] + return content.replace(old, repl) + + chunk1 = Chunk(content, """<div class="header"> +<div class="subTitle"> +<div class="block">""", """</div> +</div> +<p>See: <a href="#overview_description">Description</a></p> +</div>""") + + chunk2 = Chunk(content, """<div class="footer"><a name="overview_description"> +<!-- --> +</a> +<div class="subTitle"> +<div class="block">""", """</div> +</div> +</div> +<!-- ======= START OF BOTTOM NAVBAR ====== -->""") + + if not chunk1.text: + mx.log('Could not find header section in ' + path) + return + + if not chunk2.text: + mx.log('Could not find footer section in ' + path) + return + + content = chunk1.replace(content, '<div class="header"><div class="subTitle"><div class="block">' + chunk2.text + topLink +'</div></div></div>') + content = chunk2.replace(content, '') + + with open(path, 'w') as fp: + fp.write(content) + def site(args): """creates a website containing javadoc and the project dependency graph""" parser = ArgumentParser(prog='site') parser.add_argument('-d', '--base', action='store', help='directory for generated site', required=True, metavar='<dir>') parser.add_argument('-c', '--clean', action='store_true', help='remove existing site in <dir>') + parser.add_argument('-t', '--test', action='store_true', help='omit the Javadoc execution (useful for testing)') args = parser.parse_args(args) @@ -1018,14 +1083,23 @@ shutil.rmtree(args.base) os.mkdir(args.base) - mx.javadoc(['--base', args.base]) + unified = join(args.base, 'all') + + if not args.test: + # Create javadoc for each project + mx.javadoc(['--base', args.base]) - unified = join(args.base, 'all') - if exists(unified): - shutil.rmtree(unified) - mx.javadoc(['--base', args.base, '--unified', '--arg', '@-overview', '--arg', '@' + join(_graal_home, 'graal', 'overview.html')]) - os.rename(join(args.base, 'javadoc'), unified) - + # Create unified javadoc for all projects + if exists(unified): + shutil.rmtree(unified) + mx.javadoc(['--base', args.base, + '--unified', + '--arg', '@-windowtitle', '--arg', '@Unified Graal Javadoc', + '--arg', '@-doctitle', '--arg', '@Unified Graal Javadoc', + '--arg', '@-overview', '--arg', '@' + join(_graal_home, 'graal', 'overview.html')]) + os.rename(join(args.base, 'javadoc'), unified) + + # Generate dependency graph with Graphviz _, tmp = tempfile.mkstemp() try: svg = join(args.base, 'all', 'modules.svg') @@ -1050,18 +1124,31 @@ mx.run(['dot', '-Tsvg', '-o' + svg, tmp]) - # Post-process generated SVG to remove unified title elements which most browsers - # render as redundant (and annoying) tooltips. - with open(svg, 'r') as fp: - content = fp.read() - content = re.sub('<title>.*</title>', '', content) - content = re.sub('xlink:title="[^"]*"', '', content) - with open(svg, 'w') as fp: - fp.write(content) - - print 'Created website - root is ' + join(unified, 'index.html') finally: os.remove(tmp) + + # Post-process generated SVG to remove title elements which most browsers + # render as redundant (and annoying) tooltips. + with open(svg, 'r') as fp: + content = fp.read() + content = re.sub('<title>.*</title>', '', content) + content = re.sub('xlink:title="[^"]*"', '', content) + with open(svg, 'w') as fp: + fp.write(content) + + # Post-process generated overview-summary.html files + top = join(args.base, 'all', 'overview-summary.html') + for root, _, files in os.walk(args.base): + for f in files: + if f == 'overview-summary.html': + path = join(root, f) + topLink = '' + if top != path: + link = os.path.relpath(join(args.base, 'all', 'index.html'), dirname(path)) + topLink = '<p><a href="' + link + '", target="_top">[return to the unified Graal javadoc]</a></p>' + _fix_overview_summary(path, topLink) + + print 'Created website - root is ' + join(unified, 'index.html') def mx_init(): _vmbuild = 'product'