build.py revision 583f7e9e1cf798616a78a503eebfd017af5f26ea
1#!/usr/bin/env python2
2# Build the documentation.
3
4from __future__ import print_function
5import os, shutil, tempfile
6from subprocess import check_call, CalledProcessError, Popen, PIPE
7
8def pip_install(package, commit=None):
9  "Install package using pip."
10  if commit:
11    cmd = ['pip', 'show', package.split('/')[1]]
12    p = Popen(cmd, stdout=PIPE, stderr=PIPE)
13    stdout, stderr = p.communicate()
14    if stdout:
15      return # Already installed
16    elif p.returncode != 0:
17      # Old versions of pip such as the one installed on Travis don't support
18      # the show command - continue installation in this case.
19      # Otherwise throw CalledProcessError.
20      if p.returncode > 1 and 'No command by the name pip show' not in stderr:
21        raise CalledProcessError(p.returncode, cmd)
22    package = 'git+git://github.com/{0}.git@{1}'.format(package, commit)
23  check_call(['pip', 'install', '-q', package])
24
25def build_docs():
26  # Create virtualenv.
27  doc_dir = os.path.dirname(os.path.realpath(__file__))
28  virtualenv_dir = 'virtualenv'
29  check_call(['virtualenv', virtualenv_dir])
30  activate_this_file = os.path.join(virtualenv_dir, 'bin', 'activate_this.py')
31  execfile(activate_this_file, dict(__file__=activate_this_file))
32  # Install Sphinx and Breathe.
33  pip_install('sphinx==1.3.1')
34  pip_install('michaeljones/breathe',
35              '511b0887293e7c6b12310bb61b3659068f48f0f4')
36  # Build docs.
37  cmd = ['doxygen', '-']
38  p = Popen(cmd, stdin=PIPE)
39  p.communicate(input=r'''
40      PROJECT_NAME      = C++ Format
41      GENERATE_LATEX    = NO
42      GENERATE_MAN      = NO
43      GENERATE_RTF      = NO
44      CASE_SENSE_NAMES  = NO
45      INPUT             = {0}/format.h
46      EXCLUDE_SYMBOLS   = fmt::internal::*
47      QUIET             = YES
48      JAVADOC_AUTOBRIEF = YES
49      AUTOLINK_SUPPORT  = NO
50      GENERATE_HTML     = NO
51      GENERATE_XML      = YES
52      XML_OUTPUT        = doxyxml
53      ALIASES           = "rst=\verbatim embed:rst"
54      ALIASES          += "endrst=\endverbatim"
55      PREDEFINED        = _WIN32=1 \
56                          FMT_USE_VARIADIC_TEMPLATES=1 \
57                          FMT_USE_RVALUE_REFERENCES=1
58      EXCLUDE_SYMBOLS   = fmt::internal::* StringValue write_str
59    '''.format(os.path.dirname(doc_dir)))
60  if p.returncode != 0:
61    raise CalledProcessError(p.returncode, cmd)
62  check_call(['sphinx-build', '-D',
63              'breathe_projects.format=' + os.path.join(os.getcwd(), 'doxyxml'),
64              '-b', 'html', doc_dir, 'html'])
65  check_call(['lessc', '--clean-css',
66              '--include-path=' + os.path.join(doc_dir, 'bootstrap'),
67              os.path.join(doc_dir, 'cppformat.less'),
68              'html/_static/cppformat.css'])
69  return 'html'
70
71if __name__ == '__main__':
72  build_docs()
73