comparison mx/commands.py @ 5771:613a3ddb9a71

moved core site functionality into mx.py
author Doug Simon <doug.simon@oracle.com>
date Thu, 05 Jul 2012 16:24:18 +0200
parents 66ec0bc36a37
children 488864d5069a
comparison
equal deleted inserted replaced
5770:25e37b01b92a 5771:613a3ddb9a71
967 out = args[0] 967 out = args[0]
968 elif len(args) > 1: 968 elif len(args) > 1:
969 mx.abort('jacocoreport takes only one argument : an output directory') 969 mx.abort('jacocoreport takes only one argument : an output directory')
970 mx.run_java(['-jar', jacocoreport.get_path(True), '-in', 'jacoco.exec', '-g', join(_graal_home, 'graal'), out]) 970 mx.run_java(['-jar', jacocoreport.get_path(True), '-in', 'jacoco.exec', '-g', join(_graal_home, 'graal'), out])
971 971
972 def _fix_overview_summary(path, topLink):
973 """
974 Processes an "overview-summary.html" generated by javadoc to put the complete
975 summary text above the Packages table.
976 """
977
978 # This uses scraping and so will break if the relevant content produced by javadoc changes in any way!
979 with open(path) as fp:
980 content = fp.read()
981
982 class Chunk:
983 def __init__(self, content, ldelim, rdelim):
984 lindex = content.find(ldelim)
985 rindex = content.find(rdelim)
986 self.ldelim = ldelim
987 self.rdelim = rdelim
988 if lindex != -1 and rindex != -1 and rindex > lindex:
989 self.text = content[lindex + len(ldelim):rindex]
990 else:
991 self.text = None
992
993 def replace(self, content, repl):
994 lindex = content.find(self.ldelim)
995 rindex = content.find(self.rdelim)
996 old = content[lindex:rindex + len(self.rdelim)]
997 return content.replace(old, repl)
998
999 chunk1 = Chunk(content, """<div class="header">
1000 <div class="subTitle">
1001 <div class="block">""", """</div>
1002 </div>
1003 <p>See: <a href="#overview_description">Description</a></p>
1004 </div>""")
1005
1006 chunk2 = Chunk(content, """<div class="footer"><a name="overview_description">
1007 <!-- -->
1008 </a>
1009 <div class="subTitle">
1010 <div class="block">""", """</div>
1011 </div>
1012 </div>
1013 <!-- ======= START OF BOTTOM NAVBAR ====== -->""")
1014
1015 assert chunk1.text, 'Could not find header section in ' + path
1016 assert chunk2.text, 'Could not find footer section in ' + path
1017
1018 content = chunk1.replace(content, '<div class="header"><div class="subTitle"><div class="block">' + topLink + chunk2.text +'</div></div></div>')
1019 content = chunk2.replace(content, '')
1020
1021 with open(path, 'w') as fp:
1022 fp.write(content)
1023
1024 def site(args): 972 def site(args):
1025 """creates a website containing javadoc and the project dependency graph""" 973 """creates a website containing javadoc and the project dependency graph"""
1026 974
1027 parser = ArgumentParser(prog='site') 975 return mx.site(['--name', 'Graal',
1028 parser.add_argument('-d', '--base', action='store', help='directory for generated site', required=True, metavar='<dir>') 976 '--overview', join(_graal_home, 'graal', 'overview.html'),
1029 977 '--title', 'Graal OpenJDK Project Documentation',
1030 args = parser.parse_args(args) 978 '--dot-output-base', 'modules'] + args)
1031
1032 args.base = os.path.abspath(args.base)
1033 tmpbase = tempfile.mkdtemp(prefix=basename(args.base) + '.', dir=dirname(args.base))
1034 unified = join(tmpbase, 'all')
1035
1036 try:
1037 # Create javadoc for each project
1038 mx.javadoc(['--base', tmpbase])
1039
1040 # Create unified javadoc for all projects
1041 mx.javadoc(['--base', tmpbase,
1042 '--unified',
1043 '--arg', '@-windowtitle', '--arg', '@Graal OpenJDK Project Documentation',
1044 '--arg', '@-doctitle', '--arg', '@Graal OpenJDK Project Documentation',
1045 '--arg', '@-overview', '--arg', '@' + join(_graal_home, 'graal', 'overview.html')])
1046 os.rename(join(tmpbase, 'javadoc'), unified)
1047
1048 # Generate dependency graph with Graphviz
1049 _, tmp = tempfile.mkstemp()
1050 try:
1051 svg = join(tmpbase, 'all', 'modules.svg')
1052 jpg = join(tmpbase, 'all', 'modules.jpg')
1053 with open(tmp, 'w') as fp:
1054 print >> fp, 'digraph projects {'
1055 print >> fp, 'rankdir=BT;'
1056 print >> fp, 'size = "13,13";'
1057 print >> fp, 'node [shape=rect, fontcolor="blue"];'
1058 #print >> fp, 'edge [color="green"];'
1059 for p in mx.projects():
1060 print >> fp, '"' + p.name + '" [URL = "../' + p.name + '/javadoc/index.html", target = "_top"]'
1061 for dep in p.canonical_deps():
1062 if mx.project(dep, False):
1063 print >> fp, '"' + p.name + '" -> "' + dep + '"'
1064 depths = dict()
1065 for p in mx.projects():
1066 d = p.max_depth()
1067 depths.setdefault(d, list()).append(p.name)
1068 for d, names in depths.iteritems():
1069 print >> fp, '{ rank = same; "' + '"; "'.join(names) + '"; }'
1070 print >> fp, '}'
1071
1072 mx.run(['dot', '-Tsvg', '-o' + svg, '-Tjpg', '-o' + jpg, tmp])
1073
1074 finally:
1075 os.remove(tmp)
1076
1077 # Post-process generated SVG to remove title elements which most browsers
1078 # render as redundant (and annoying) tooltips.
1079 with open(svg, 'r') as fp:
1080 content = fp.read()
1081 content = re.sub('<title>.*</title>', '', content)
1082 content = re.sub('xlink:title="[^"]*"', '', content)
1083 with open(svg, 'w') as fp:
1084 fp.write(content)
1085
1086 # Post-process generated overview-summary.html files
1087 top = join(tmpbase, 'all', 'overview-summary.html')
1088 for root, _, files in os.walk(tmpbase):
1089 for f in files:
1090 if f == 'overview-summary.html':
1091 path = join(root, f)
1092 topLink = ''
1093 if top != path:
1094 link = os.path.relpath(join(tmpbase, 'all', 'index.html'), dirname(path))
1095 topLink = '<p><a href="' + link + '", target="_top"><b>[return to the overall Graal documentation]</b></a></p>'
1096 _fix_overview_summary(path, topLink)
1097
1098
1099 if exists(args.base):
1100 shutil.rmtree(args.base)
1101 shutil.move(tmpbase, args.base)
1102
1103 print 'Created website - root is ' + join(args.base, 'all', 'index.html')
1104
1105 finally:
1106 if exists(tmpbase):
1107 shutil.rmtree(tmpbase)
1108 979
1109 def mx_init(): 980 def mx_init():
1110 _vmbuild = 'product' 981 _vmbuild = 'product'
1111 commands = { 982 commands = {
1112 'build': [build, '[-options]'], 983 'build': [build, '[-options]'],