diff options
author | 2015-07-02 16:53:38 -0500 | |
---|---|---|
committer | 2015-07-08 14:31:26 -0500 | |
commit | 21b5ebeba7dc4ef9d8b1f809741ad73418989a16 (patch) | |
tree | d163ac2b76b5362c8da954ee8221922c6eb126dc /3rdparty/jsoncpp/doxybuild.py | |
parent | 1e37ed88936371ede63ada5b7aea9dd1d0bc287c (diff) |
github version of jsoncpp with some fixes: pedantic and C++98 and others. please try to compile for all platforms
Diffstat (limited to '3rdparty/jsoncpp/doxybuild.py')
-rw-r--r-- | 3rdparty/jsoncpp/doxybuild.py | 144 |
1 files changed, 82 insertions, 62 deletions
diff --git a/3rdparty/jsoncpp/doxybuild.py b/3rdparty/jsoncpp/doxybuild.py index 0b61c397e43..f18c9c0697b 100644 --- a/3rdparty/jsoncpp/doxybuild.py +++ b/3rdparty/jsoncpp/doxybuild.py @@ -1,22 +1,37 @@ """Script to generate doxygen documentation. """ from __future__ import print_function +from __future__ import unicode_literals from devtools import tarball +from contextlib import contextmanager +import subprocess +import traceback import re import os -import os.path import sys import shutil +@contextmanager +def cd(newdir): + """ + http://stackoverflow.com/questions/431684/how-do-i-cd-in-python + """ + prevdir = os.getcwd() + os.chdir(newdir) + try: + yield + finally: + os.chdir(prevdir) + def find_program(*filenames): """find a program in folders path_lst, and sets env[var] @param filenames: a list of possible names of the program to search for @return: the full path of the filename if found, or '' if filename could not be found """ paths = os.environ.get('PATH', '').split(os.pathsep) - suffixes = ('win32' in sys.platform ) and '.exe .com .bat .cmd' or '' + suffixes = ('win32' in sys.platform) and '.exe .com .bat .cmd' or '' for filename in filenames: - for name in [filename+ext for ext in suffixes.split()]: + for name in [filename+ext for ext in suffixes.split(' ')]: for directory in paths: full_path = os.path.join(directory, name) if os.path.isfile(full_path): @@ -28,53 +43,56 @@ def do_subst_in_file(targetfile, sourcefile, dict): For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'}, then all instances of %VERSION% in the file will be replaced with 1.2345 etc. """ - try: - f = open(sourcefile, 'rb') + with open(sourcefile, 'r') as f: contents = f.read() - f.close() - except: - print("Can't read source file %s"%sourcefile) - raise for (k,v) in list(dict.items()): v = v.replace('\\','\\\\') contents = re.sub(k, v, contents) - try: - f = open(targetfile, 'wb') + with open(targetfile, 'w') as f: f.write(contents) - f.close() + +def getstatusoutput(cmd): + """cmd is a list. + """ + try: + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + output, _ = process.communicate() + status = process.returncode except: - print("Can't write target file %s"%targetfile) - raise + status = -1 + output = traceback.format_exc() + return status, output + +def run_cmd(cmd, silent=False): + """Raise exception on failure. + """ + info = 'Running: %r in %r' %(' '.join(cmd), os.getcwd()) + print(info) + sys.stdout.flush() + if silent: + status, output = getstatusoutput(cmd) + else: + status, output = subprocess.call(cmd), '' + if status: + msg = 'Error while %s ...\n\terror=%d, output="""%s"""' %(info, status, output) + raise Exception(msg) + +def assert_is_exe(path): + if not path: + raise Exception('path is empty.') + if not os.path.isfile(path): + raise Exception('%r is not a file.' %path) + if not os.access(path, os.X_OK): + raise Exception('%r is not executable by this user.' %path) def run_doxygen(doxygen_path, config_file, working_dir, is_silent): - config_file = os.path.abspath( config_file ) - doxygen_path = doxygen_path - old_cwd = os.getcwd() - try: - os.chdir( working_dir ) + assert_is_exe(doxygen_path) + config_file = os.path.abspath(config_file) + with cd(working_dir): cmd = [doxygen_path, config_file] - print('Running:', ' '.join( cmd )) - try: - import subprocess - except: - if os.system( ' '.join( cmd ) ) != 0: - print('Documentation generation failed') - return False - else: - if is_silent: - process = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) - else: - process = subprocess.Popen( cmd ) - stdout, _ = process.communicate() - if process.returncode: - print('Documentation generation failed:') - print(stdout) - return False - return True - finally: - os.chdir( old_cwd ) + run_cmd(cmd, is_silent) -def build_doc( options, make_release=False ): +def build_doc(options, make_release=False): if make_release: options.make_tarball = True options.with_dot = True @@ -83,56 +101,56 @@ def build_doc( options, make_release=False ): options.open = False options.silent = True - version = open('version','rt').read().strip() + version = open('version', 'rt').read().strip() output_dir = 'dist/doxygen' # relative to doc/doxyfile location. - if not os.path.isdir( output_dir ): - os.makedirs( output_dir ) - top_dir = os.path.abspath( '.' ) + if not os.path.isdir(output_dir): + os.makedirs(output_dir) + top_dir = os.path.abspath('.') html_output_dirname = 'jsoncpp-api-html-' + version - tarball_path = os.path.join( 'dist', html_output_dirname + '.tar.gz' ) - warning_log_path = os.path.join( output_dir, '../jsoncpp-doxygen-warning.log' ) - html_output_path = os.path.join( output_dir, html_output_dirname ) - def yesno( bool ): + tarball_path = os.path.join('dist', html_output_dirname + '.tar.gz') + warning_log_path = os.path.join(output_dir, '../jsoncpp-doxygen-warning.log') + html_output_path = os.path.join(output_dir, html_output_dirname) + def yesno(bool): return bool and 'YES' or 'NO' subst_keys = { '%JSONCPP_VERSION%': version, '%DOC_TOPDIR%': '', '%TOPDIR%': top_dir, - '%HTML_OUTPUT%': os.path.join( '..', output_dir, html_output_dirname ), + '%HTML_OUTPUT%': os.path.join('..', output_dir, html_output_dirname), '%HAVE_DOT%': yesno(options.with_dot), '%DOT_PATH%': os.path.split(options.dot_path)[0], '%HTML_HELP%': yesno(options.with_html_help), '%UML_LOOK%': yesno(options.with_uml_look), - '%WARNING_LOG_PATH%': os.path.join( '..', warning_log_path ) + '%WARNING_LOG_PATH%': os.path.join('..', warning_log_path) } - if os.path.isdir( output_dir ): + if os.path.isdir(output_dir): print('Deleting directory:', output_dir) - shutil.rmtree( output_dir ) - if not os.path.isdir( output_dir ): - os.makedirs( output_dir ) + shutil.rmtree(output_dir) + if not os.path.isdir(output_dir): + os.makedirs(output_dir) - do_subst_in_file( 'doc/doxyfile', 'doc/doxyfile.in', subst_keys ) - ok = run_doxygen( options.doxygen_path, 'doc/doxyfile', 'doc', is_silent=options.silent ) + do_subst_in_file('doc/doxyfile', options.doxyfile_input_path, subst_keys) + run_doxygen(options.doxygen_path, 'doc/doxyfile', 'doc', is_silent=options.silent) if not options.silent: - print(open(warning_log_path, 'rb').read()) + print(open(warning_log_path, 'r').read()) index_path = os.path.abspath(os.path.join('doc', subst_keys['%HTML_OUTPUT%'], 'index.html')) print('Generated documentation can be found in:') print(index_path) if options.open: import webbrowser - webbrowser.open( 'file://' + index_path ) + webbrowser.open('file://' + index_path) if options.make_tarball: print('Generating doc tarball to', tarball_path) tarball_sources = [ output_dir, - 'README.txt', + 'README.md', 'LICENSE', 'NEWS.txt', 'version' ] - tarball_basedir = os.path.join( output_dir, html_output_dirname ) - tarball.make_tarball( tarball_path, tarball_sources, tarball_basedir, html_output_dirname ) + tarball_basedir = os.path.join(output_dir, html_output_dirname) + tarball.make_tarball(tarball_path, tarball_sources, tarball_basedir, html_output_dirname) return tarball_path, html_output_dirname def main(): @@ -151,6 +169,8 @@ def main(): help="""Path to GraphViz dot tool. Must be full qualified path. [Default: %default]""") parser.add_option('--doxygen', dest="doxygen_path", action='store', default=find_program('doxygen'), help="""Path to Doxygen tool. [Default: %default]""") + parser.add_option('--in', dest="doxyfile_input_path", action='store', default='doc/doxyfile.in', + help="""Path to doxygen inputs. [Default: %default]""") parser.add_option('--with-html-help', dest="with_html_help", action='store_true', default=False, help="""Enable generation of Microsoft HTML HELP""") parser.add_option('--no-uml-look', dest="with_uml_look", action='store_false', default=True, @@ -163,7 +183,7 @@ def main(): help="""Hides doxygen output""") parser.enable_interspersed_args() options, args = parser.parse_args() - build_doc( options ) + build_doc(options) if __name__ == '__main__': main() |