]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | #!/usr/bin/env python |
2 | # Build the documentation. | |
3 | ||
4 | from __future__ import print_function | |
5 | import errno, os, shutil, sys, tempfile | |
6 | from subprocess import check_call, check_output, CalledProcessError, Popen, PIPE | |
7 | from distutils.version import LooseVersion | |
8 | ||
9f95a23c | 9 | versions = ['1.0.0', '1.1.0', '2.0.0', '3.0.2', '4.0.0', '4.1.0', '5.0.0', '5.1.0', '5.2.0', '5.2.1', '5.3.0'] |
11fdf7f2 TL |
10 | |
11 | def pip_install(package, commit=None, **kwargs): | |
12 | "Install package using pip." | |
13 | min_version = kwargs.get('min_version') | |
14 | if min_version: | |
15 | from pkg_resources import get_distribution, DistributionNotFound | |
16 | try: | |
17 | installed_version = get_distribution(os.path.basename(package)).version | |
18 | if LooseVersion(installed_version) >= min_version: | |
19 | print('{} {} already installed'.format(package, min_version)) | |
20 | return | |
21 | except DistributionNotFound: | |
22 | pass | |
23 | if commit: | |
24 | package = 'git+https://github.com/{0}.git@{1}'.format(package, commit) | |
25 | print('Installing {0}'.format(package)) | |
26 | check_call(['pip', 'install', package]) | |
27 | ||
28 | def create_build_env(dirname='virtualenv'): | |
29 | # Create virtualenv. | |
30 | if not os.path.exists(dirname): | |
31 | check_call(['virtualenv', dirname]) | |
32 | import sysconfig | |
33 | scripts_dir = os.path.basename(sysconfig.get_path('scripts')) | |
34 | activate_this_file = os.path.join(dirname, scripts_dir, 'activate_this.py') | |
35 | with open(activate_this_file) as f: | |
36 | exec(f.read(), dict(__file__=activate_this_file)) | |
37 | # Import get_distribution after activating virtualenv to get info about | |
38 | # the correct packages. | |
39 | from pkg_resources import get_distribution, DistributionNotFound | |
40 | # Upgrade pip because installation of sphinx with pip 1.1 available on Travis | |
41 | # is broken (see #207) and it doesn't support the show command. | |
42 | pip_version = get_distribution('pip').version | |
43 | if LooseVersion(pip_version) < LooseVersion('1.5.4'): | |
44 | print("Updating pip") | |
45 | check_call(['pip', 'install', '--upgrade', 'pip']) | |
46 | # Upgrade distribute because installation of sphinx with distribute 0.6.24 | |
47 | # available on Travis is broken (see #207). | |
48 | try: | |
49 | distribute_version = get_distribution('distribute').version | |
50 | if LooseVersion(distribute_version) <= LooseVersion('0.6.24'): | |
51 | print("Updating distribute") | |
52 | check_call(['pip', 'install', '--upgrade', 'distribute']) | |
53 | except DistributionNotFound: | |
54 | pass | |
55 | # Install Sphinx and Breathe. | |
56 | pip_install('sphinx-doc/sphinx', '12b83372ac9316e8cbe86e7fed889296a4cc29ee', | |
57 | min_version='1.4.1.dev20160531') | |
58 | pip_install('michaeljones/breathe', | |
59 | '129222318f7c8f865d2631e7da7b033567e7f56a', | |
60 | min_version='4.2.0') | |
61 | ||
62 | def build_docs(version='dev', **kwargs): | |
63 | doc_dir = kwargs.get('doc_dir', os.path.dirname(os.path.realpath(__file__))) | |
64 | work_dir = kwargs.get('work_dir', '.') | |
65 | include_dir = kwargs.get( | |
66 | 'include_dir', os.path.join(os.path.dirname(doc_dir), 'include', 'fmt')) | |
67 | # Build docs. | |
68 | cmd = ['doxygen', '-'] | |
69 | p = Popen(cmd, stdin=PIPE) | |
70 | doxyxml_dir = os.path.join(work_dir, 'doxyxml') | |
71 | p.communicate(input=r''' | |
72 | PROJECT_NAME = fmt | |
73 | GENERATE_LATEX = NO | |
74 | GENERATE_MAN = NO | |
75 | GENERATE_RTF = NO | |
76 | CASE_SENSE_NAMES = NO | |
77 | INPUT = {0}/core.h {0}/format.h {0}/ostream.h \ | |
78 | {0}/printf.h {0}/time.h | |
79 | QUIET = YES | |
80 | JAVADOC_AUTOBRIEF = YES | |
81 | AUTOLINK_SUPPORT = NO | |
82 | GENERATE_HTML = NO | |
83 | GENERATE_XML = YES | |
84 | XML_OUTPUT = {1} | |
85 | ALIASES = "rst=\verbatim embed:rst" | |
86 | ALIASES += "endrst=\endverbatim" | |
9f95a23c | 87 | INLINE_INHERITED_MEMBERS = YES |
11fdf7f2 TL |
88 | MACRO_EXPANSION = YES |
89 | PREDEFINED = _WIN32=1 \ | |
90 | FMT_USE_VARIADIC_TEMPLATES=1 \ | |
91 | FMT_USE_RVALUE_REFERENCES=1 \ | |
92 | FMT_USE_USER_DEFINED_LITERALS=1 \ | |
eafe8130 | 93 | FMT_USE_ALIAS_TEMPLATES=1 \ |
11fdf7f2 TL |
94 | FMT_API= \ |
95 | "FMT_BEGIN_NAMESPACE=namespace fmt {{" \ | |
96 | "FMT_END_NAMESPACE=}}" \ | |
9f95a23c TL |
97 | "FMT_STRING_ALIAS=1" \ |
98 | "FMT_ENABLE_IF_T(B, T)=T" | |
11fdf7f2 TL |
99 | EXCLUDE_SYMBOLS = fmt::internal::* StringValue write_str |
100 | '''.format(include_dir, doxyxml_dir).encode('UTF-8')) | |
101 | if p.returncode != 0: | |
102 | raise CalledProcessError(p.returncode, cmd) | |
103 | html_dir = os.path.join(work_dir, 'html') | |
104 | main_versions = reversed(versions[-3:]) | |
105 | check_call(['sphinx-build', | |
106 | '-Dbreathe_projects.format=' + os.path.abspath(doxyxml_dir), | |
107 | '-Dversion=' + version, '-Drelease=' + version, | |
108 | '-Aversion=' + version, '-Aversions=' + ','.join(main_versions), | |
109 | '-b', 'html', doc_dir, html_dir]) | |
110 | try: | |
111 | check_call(['lessc', '--clean-css', | |
112 | '--include-path=' + os.path.join(doc_dir, 'bootstrap'), | |
113 | os.path.join(doc_dir, 'fmt.less'), | |
114 | os.path.join(html_dir, '_static', 'fmt.css')]) | |
115 | except OSError as e: | |
116 | if e.errno != errno.ENOENT: | |
117 | raise | |
118 | print('lessc not found; make sure that Less (http://lesscss.org/) ' + | |
119 | 'is installed') | |
120 | sys.exit(1) | |
121 | return html_dir | |
122 | ||
123 | if __name__ == '__main__': | |
124 | create_build_env() | |
125 | build_docs(sys.argv[1]) |