1*84e872a0SLloyd Pique#!/usr/bin/env python3 2*84e872a0SLloyd Pique 3*84e872a0SLloyd Piqueimport argparse 4*84e872a0SLloyd Piqueimport datetime 5*84e872a0SLloyd Piqueimport errno 6*84e872a0SLloyd Piqueimport os 7*84e872a0SLloyd Piqueimport subprocess 8*84e872a0SLloyd Piqueimport sys 9*84e872a0SLloyd Pique 10*84e872a0SLloyd Pique# Custom configuration for each documentation format 11*84e872a0SLloyd Piquedoxygen_templates = { 12*84e872a0SLloyd Pique 'xml': [ 13*84e872a0SLloyd Pique 'GENERATE_XML=YES\n', 14*84e872a0SLloyd Pique 'XML_OUTPUT={format}/{section}\n', 15*84e872a0SLloyd Pique 'INPUT= {files}\n', 16*84e872a0SLloyd Pique ], 17*84e872a0SLloyd Pique 'html': [ 18*84e872a0SLloyd Pique 'GENERATE_HTML=YES\n', 19*84e872a0SLloyd Pique 'HTML_OUTPUT={format}/{section}\n', 20*84e872a0SLloyd Pique 'PROJECT_NAME=\"Wayland {section} API\"\n', 21*84e872a0SLloyd Pique 'INPUT= {files}\n', 22*84e872a0SLloyd Pique ], 23*84e872a0SLloyd Pique 'man': [ 24*84e872a0SLloyd Pique 'GENERATE_MAN=YES\n', 25*84e872a0SLloyd Pique 'MAN_OUTPUT={format}\n', 26*84e872a0SLloyd Pique 'MAN_SUBDIR=.\n', 27*84e872a0SLloyd Pique 'JAVADOC_AUTOBRIEF=NO\n', 28*84e872a0SLloyd Pique 'INPUT= {files}\n', 29*84e872a0SLloyd Pique ], 30*84e872a0SLloyd Pique} 31*84e872a0SLloyd Pique 32*84e872a0SLloyd Piquedef load_doxygen_file(doxyfile): 33*84e872a0SLloyd Pique with open(doxyfile, 'r') as f: 34*84e872a0SLloyd Pique res = f.readlines() 35*84e872a0SLloyd Pique return res 36*84e872a0SLloyd Pique 37*84e872a0SLloyd Piquedef get_template(outformat): 38*84e872a0SLloyd Pique for (k,v) in doxygen_templates.items(): 39*84e872a0SLloyd Pique if outformat.startswith(k): 40*84e872a0SLloyd Pique return v 41*84e872a0SLloyd Pique 42*84e872a0SLloyd Piquedef gen_doxygen_file(data, outformat, section, files): 43*84e872a0SLloyd Pique for l in get_template(outformat): 44*84e872a0SLloyd Pique data.append(l.format(format=outformat, section=section, files=' '.join(files))) 45*84e872a0SLloyd Pique return data 46*84e872a0SLloyd Pique 47*84e872a0SLloyd Piqueparser = argparse.ArgumentParser(description='Generate docs with Doxygen') 48*84e872a0SLloyd Piqueparser.add_argument('doxygen_file', 49*84e872a0SLloyd Pique help='The doxygen file to use') 50*84e872a0SLloyd Piqueparser.add_argument('files', 51*84e872a0SLloyd Pique help='The list of files to parse', 52*84e872a0SLloyd Pique metavar='FILES', 53*84e872a0SLloyd Pique nargs='+') 54*84e872a0SLloyd Piqueparser.add_argument('--builddir', 55*84e872a0SLloyd Pique help='The build directory', 56*84e872a0SLloyd Pique metavar='DIR', 57*84e872a0SLloyd Pique default='.') 58*84e872a0SLloyd Piqueparser.add_argument('--section', 59*84e872a0SLloyd Pique help='The section to build', 60*84e872a0SLloyd Pique metavar='NAME', 61*84e872a0SLloyd Pique default='Client') 62*84e872a0SLloyd Piqueparser.add_argument('--output-format', 63*84e872a0SLloyd Pique help='The output format: xml, html, man', 64*84e872a0SLloyd Pique metavar='FORMAT', 65*84e872a0SLloyd Pique default='xml') 66*84e872a0SLloyd Piqueparser.add_argument('--stamp', 67*84e872a0SLloyd Pique help='Stamp file to output', 68*84e872a0SLloyd Pique metavar='STAMP_FILE', 69*84e872a0SLloyd Pique nargs='?', 70*84e872a0SLloyd Pique type=argparse.FileType('w')) 71*84e872a0SLloyd Pique 72*84e872a0SLloyd Piqueargs = parser.parse_args() 73*84e872a0SLloyd Pique 74*84e872a0SLloyd Pique# Merge the doxyfile with our custom templates 75*84e872a0SLloyd Piqueconf = load_doxygen_file(args.doxygen_file) 76*84e872a0SLloyd Piqueconf = gen_doxygen_file(conf, args.output_format, args.section, args.files) 77*84e872a0SLloyd Pique 78*84e872a0SLloyd Pique# Doxygen is not clever enough to create the directories it 79*84e872a0SLloyd Pique# needs beforehand 80*84e872a0SLloyd Piquetry: 81*84e872a0SLloyd Pique os.makedirs(os.path.join(args.builddir, args.output_format)) 82*84e872a0SLloyd Piqueexcept OSError as e: 83*84e872a0SLloyd Pique if e.errno != errno.EEXIST: 84*84e872a0SLloyd Pique raise e 85*84e872a0SLloyd Pique 86*84e872a0SLloyd Pique# Run Doxygen with the generated doxyfile 87*84e872a0SLloyd Piquecmd = subprocess.Popen(['doxygen', '-'], stdin=subprocess.PIPE) 88*84e872a0SLloyd Piquecmd.stdin.write(''.join(conf).encode('utf-8')) 89*84e872a0SLloyd Piquecmd.stdin.close() 90*84e872a0SLloyd Piqueif cmd.wait() != 0: 91*84e872a0SLloyd Pique sys.exit(1) 92*84e872a0SLloyd Pique 93*84e872a0SLloyd Pique# This is a bit of a hack; Doxygen will generate way more files than we 94*84e872a0SLloyd Pique# want to install, but there's no way to know how many at configuration 95*84e872a0SLloyd Pique# time. Since we want to install only the wl_* man pages anyway, we can 96*84e872a0SLloyd Pique# delete the other files and let Meson install the whole man3 subdirectory 97*84e872a0SLloyd Piqueif args.output_format.startswith('man'): 98*84e872a0SLloyd Pique manpath = os.path.join(args.builddir, args.output_format) 99*84e872a0SLloyd Pique for filename in os.listdir(manpath): 100*84e872a0SLloyd Pique full_path = os.path.join(manpath, filename) 101*84e872a0SLloyd Pique if not filename.startswith('wl_'): 102*84e872a0SLloyd Pique os.remove(full_path) 103*84e872a0SLloyd Pique 104*84e872a0SLloyd Piqueif args.stamp: 105*84e872a0SLloyd Pique args.stamp.write(str(datetime.datetime.now())) 106