build.py revision 7bb1b50835e8a1595454b4251412f8528c3443e8
1#!/usr/bin/env python 2# Build the documentation. 3 4from __future__ import print_function 5import errno, os, shutil, sys, tempfile 6from subprocess import check_call, check_output, CalledProcessError, Popen, PIPE 7from distutils.version import LooseVersion 8 9def pip_install(package, commit=None, **kwargs): 10 "Install package using pip." 11 if commit: 12 package = 'git+git://github.com/{0}.git@{1}'.format(package, commit) 13 print('Installing {}'.format(package)) 14 check_call(['pip', 'install', '--upgrade', package]) 15 16def create_build_env(): 17 # Create virtualenv. 18 virtualenv_dir = 'virtualenv' 19 check_call(['virtualenv', virtualenv_dir]) 20 import sysconfig 21 scripts_dir = os.path.basename(sysconfig.get_path('scripts')) 22 activate_this_file = os.path.join(virtualenv_dir, scripts_dir, 23 'activate_this.py') 24 with open(activate_this_file) as f: 25 exec(f.read(), dict(__file__=activate_this_file)) 26 # Upgrade pip because installation of sphinx with pip 1.1 available on Travis 27 # is broken (see #207) and it doesn't support the show command. 28 from pkg_resources import get_distribution, DistributionNotFound 29 pip_version = get_distribution('pip').version 30 if LooseVersion(pip_version) < LooseVersion('1.5.4'): 31 print("Updating pip") 32 check_call(['pip', 'install', '--upgrade', 'pip']) 33 # Upgrade distribute because installation of sphinx with distribute 0.6.24 34 # available on Travis is broken (see #207). 35 try: 36 distribute_version = get_distribution('distribute').version 37 if LooseVersion(distribute_version) <= LooseVersion('0.6.24'): 38 print("Updating distribute") 39 check_call(['pip', 'install', '--upgrade', 'distribute']) 40 except DistributionNotFound: 41 pass 42 # Install Sphinx and Breathe. 43 pip_install('sphinx-doc/sphinx', 44 '12b83372ac9316e8cbe86e7fed889296a4cc29ee', 45 check_version='1.4a0.dev-20151013') 46 pip_install('michaeljones/breathe', 47 '6b1c5bb7a1866f15fc328b8716258354b10c1daa') 48 49def build_docs(version='dev', **kwargs): 50 doc_dir = kwargs.get('doc_dir', os.path.dirname(os.path.realpath(__file__))) 51 include_dir = kwargs.get('include_dir', os.path.join(os.path.dirname(doc_dir), 'fmt')) 52 # Build docs. 53 cmd = ['doxygen', '-'] 54 p = Popen(cmd, stdin=PIPE) 55 p.communicate(input=r''' 56 PROJECT_NAME = fmt 57 GENERATE_LATEX = NO 58 GENERATE_MAN = NO 59 GENERATE_RTF = NO 60 CASE_SENSE_NAMES = NO 61 INPUT = {0}/format.h {0}/ostream.h {0}/string.h 62 QUIET = YES 63 JAVADOC_AUTOBRIEF = YES 64 AUTOLINK_SUPPORT = NO 65 GENERATE_HTML = NO 66 GENERATE_XML = YES 67 XML_OUTPUT = doxyxml 68 ALIASES = "rst=\verbatim embed:rst" 69 ALIASES += "endrst=\endverbatim" 70 MACRO_EXPANSION = YES 71 PREDEFINED = _WIN32=1 \ 72 FMT_USE_VARIADIC_TEMPLATES=1 \ 73 FMT_USE_RVALUE_REFERENCES=1 \ 74 FMT_USE_USER_DEFINED_LITERALS=1 \ 75 FMT_API= 76 EXCLUDE_SYMBOLS = fmt::internal::* StringValue write_str 77 '''.format(include_dir).encode('UTF-8')) 78 if p.returncode != 0: 79 raise CalledProcessError(p.returncode, cmd) 80 check_call(['sphinx-build', 81 '-Dbreathe_projects.format=' + os.path.join(os.getcwd(), 'doxyxml'), 82 '-Dversion=' + version, '-Drelease=' + version, '-Aversion=' + version, 83 '-b', 'html', doc_dir, 'html']) 84 try: 85 check_call(['lessc', #'--clean-css', 86 '--include-path=' + os.path.join(doc_dir, 'bootstrap'), 87 os.path.join(doc_dir, 'fmt.less'), 88 'html/_static/fmt.css']) 89 except OSError as e: 90 if e.errno != errno.ENOENT: 91 raise 92 print('lessc not found; make sure that Less (http://lesscss.org/) is installed') 93 sys.exit(1) 94 return 'html' 95 96if __name__ == '__main__': 97 create_build_env() 98 build_docs(sys.argv[1]) 99