build.py revision dd6a3bbc7c86256fbaeaa83683a90917b61ae1b0
1#!/usr/bin/env python
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 p.returncode != 0:
15      # Check if pip supports the show command.
16      if 'No command by the name pip show' not in stderr:
17        raise CalledProcessError(p.returncode, cmd)
18    elif stdout:
19      return # Already installed
20    package = 'git+git://github.com/{0}.git@{1}'.format(package, commit)
21  check_call(['pip', 'install', '-q', package])
22
23def build_docs():
24  # Create virtualenv.
25  doc_dir = os.path.dirname(os.path.realpath(__file__))
26  virtualenv_dir = 'virtualenv'
27  check_call(['virtualenv', virtualenv_dir])
28  activate_this_file = os.path.join(virtualenv_dir, 'bin', 'activate_this.py')
29  execfile(activate_this_file, dict(__file__=activate_this_file))
30  # Install Sphinx and Breathe.
31  pip_install('sphinx==1.3.1')
32  pip_install('michaeljones/breathe', '511b0887293e7c6b12310bb61b3659068f48f0f4')
33  # Build docs.
34  cmd = ['doxygen', '-']
35  p = Popen(cmd, stdin=PIPE)
36  p.communicate(input=r'''
37      PROJECT_NAME      = C++ Format
38      GENERATE_LATEX    = NO
39      GENERATE_MAN      = NO
40      GENERATE_RTF      = NO
41      CASE_SENSE_NAMES  = NO
42      INPUT             = {0}/format.h
43      EXCLUDE_SYMBOLS   = fmt::internal::*
44      QUIET             = YES
45      JAVADOC_AUTOBRIEF = YES
46      AUTOLINK_SUPPORT  = NO
47      GENERATE_HTML     = NO
48      GENERATE_XML      = YES
49      XML_OUTPUT        = doxyxml
50      ALIASES           = "rst=\verbatim embed:rst"
51      ALIASES          += "endrst=\endverbatim"
52      PREDEFINED        = _WIN32=1 \
53                          FMT_USE_VARIADIC_TEMPLATES=1 \
54                          FMT_USE_RVALUE_REFERENCES=1
55      EXCLUDE_SYMBOLS   = fmt::internal::* StringValue write_str
56    '''.format(os.path.dirname(doc_dir)))
57  if p.returncode != 0:
58    raise CalledProcessError(p.returncode, cmd)
59  check_call(['sphinx-build', '-D', 'breathe_projects.format=doxyxml',
60              '-b', 'html', doc_dir, 'html'])
61  #check_call(['lessc', '--clean-css', '--include-path=bootstrap', 'cppformat.less',
62  #            'html/_static/cppformat.css'], cwd=doc_dir)
63  return 'html'
64
65if __name__ == '__main__':
66  build_docs()
67