build.py revision 418cd1c82aca938cdba4e0d7f8f21f2af9e11263
1#!/usr/bin/env python2
2# Build the documentation.
3
4from __future__ import print_function
5import os, shutil, 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    check_version = kwargs.get('check_version', '')
13    #output = check_output(['pip', 'show', package.split('/')[1]])
14    #if check_version in output:
15    #  print('{} already installed'.format(package))
16    #  return
17    package = 'git+git://github.com/{0}.git@{1}'.format(package, commit)
18  print('Installing {}'.format(package))
19  check_call(['pip', 'install', '--upgrade', package])
20
21def build_docs():
22  # Create virtualenv.
23  doc_dir = os.path.dirname(os.path.realpath(__file__))
24  virtualenv_dir = 'virtualenv'
25  check_call(['virtualenv', virtualenv_dir])
26  activate_this_file = os.path.join(virtualenv_dir, 'bin', 'activate_this.py')
27  execfile(activate_this_file, dict(__file__=activate_this_file))
28  # Upgrade pip because installation of sphinx with pip 1.1 available on Travis
29  # is broken (see #207) and it doesn't support the show command.
30  import pkg_resources
31  pip_version = pkg_resources.get_distribution('pip').version
32  print('pip version: ' + pip_version)
33  if LooseVersion(pip_version) < LooseVersion('1.5.4'):
34    print("Updating pip")
35    check_call(['pip', 'install', '--upgrade', 'pip'])
36  # Install Sphinx and Breathe.
37  pip_install('cppformat/sphinx',
38              '12dde8afdb0a7bb5576e2656692c3478c69d8cc3',
39              check_version='1.4a0.dev-20151013')
40  pip_install('michaeljones/breathe',
41              '511b0887293e7c6b12310bb61b3659068f48f0f4')
42  print(check_output(['pip', '--version']))
43  print(check_output(['sphinx-build', '--version']))
44  print('PATH:', os.environ['PATH'])
45  print(check_output(['which', 'sphinx-build']))
46  import sphinx
47  print(sphinx.__version__)
48  # Build docs.
49  cmd = ['doxygen', '-']
50  p = Popen(cmd, stdin=PIPE)
51  p.communicate(input=r'''
52      PROJECT_NAME      = C++ Format
53      GENERATE_LATEX    = NO
54      GENERATE_MAN      = NO
55      GENERATE_RTF      = NO
56      CASE_SENSE_NAMES  = NO
57      INPUT             = {0}/format.h
58      QUIET             = YES
59      JAVADOC_AUTOBRIEF = YES
60      AUTOLINK_SUPPORT  = NO
61      GENERATE_HTML     = NO
62      GENERATE_XML      = YES
63      XML_OUTPUT        = doxyxml
64      ALIASES           = "rst=\verbatim embed:rst"
65      ALIASES          += "endrst=\endverbatim"
66      PREDEFINED        = _WIN32=1 \
67                          FMT_USE_VARIADIC_TEMPLATES=1 \
68                          FMT_USE_RVALUE_REFERENCES=1 \
69                          FMT_USE_USER_DEFINED_LITERALS=1
70      EXCLUDE_SYMBOLS   = fmt::internal::* StringValue write_str
71    '''.format(os.path.dirname(doc_dir)))
72  if p.returncode != 0:
73    raise CalledProcessError(p.returncode, cmd)
74  check_call(['sphinx-build', '-D',
75              'breathe_projects.format=' + os.path.join(os.getcwd(), 'doxyxml'),
76              '-b', 'html', doc_dir, 'html'])
77  check_call(['lessc', '--clean-css',
78              '--include-path=' + os.path.join(doc_dir, 'bootstrap'),
79              os.path.join(doc_dir, 'cppformat.less'),
80              'html/_static/cppformat.css'])
81  return 'html'
82
83if __name__ == '__main__':
84  build_docs()
85