]>
Commit | Line | Data |
---|---|---|
20effc67 | 1 | #!/usr/bin/env python3 |
11fdf7f2 TL |
2 | # Build the documentation. |
3 | ||
20effc67 TL |
4 | import errno, os, re, sys |
5 | from subprocess import check_call, CalledProcessError, Popen, PIPE, STDOUT | |
11fdf7f2 | 6 | |
20effc67 | 7 | 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', '6.0.0', '6.1.0', '6.1.1', '6.1.2', '6.2.0', '6.2.1', '7.0.0', '7.0.1', '7.0.2', '7.0.3', '7.1.0', '7.1.1', '7.1.2', '7.1.3'] |
11fdf7f2 | 8 | |
20effc67 TL |
9 | class Pip: |
10 | def __init__(self, venv_dir): | |
11 | self.path = os.path.join(venv_dir, 'bin', 'pip') | |
11fdf7f2 | 12 | |
20effc67 TL |
13 | def install(self, package, commit=None): |
14 | "Install package using pip." | |
15 | if commit: | |
16 | package = 'git+https://github.com/{0}.git@{1}'.format(package, commit) | |
17 | print('Installing {0}'.format(package)) | |
18 | check_call([self.path, 'install', package]) | |
19 | ||
20 | def create_build_env(venv_dir='virtualenv'): | |
11fdf7f2 | 21 | # Create virtualenv. |
20effc67 TL |
22 | if not os.path.exists(venv_dir): |
23 | check_call(['python3', '-m', 'venv', venv_dir]) | |
24 | # Install Sphinx and Breathe. Require the exact version of Sphinx which is | |
25 | # compatible with Breathe. | |
26 | pip = Pip(venv_dir) | |
27 | pip.install('wheel') | |
28 | pip.install('six') | |
29 | pip.install('sphinx-doc/sphinx', 'v3.3.0') | |
30 | pip.install('michaeljones/breathe', 'v4.23.0') | |
11fdf7f2 TL |
31 | |
32 | def build_docs(version='dev', **kwargs): | |
33 | doc_dir = kwargs.get('doc_dir', os.path.dirname(os.path.realpath(__file__))) | |
34 | work_dir = kwargs.get('work_dir', '.') | |
35 | include_dir = kwargs.get( | |
36 | 'include_dir', os.path.join(os.path.dirname(doc_dir), 'include', 'fmt')) | |
37 | # Build docs. | |
38 | cmd = ['doxygen', '-'] | |
20effc67 | 39 | p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT) |
11fdf7f2 | 40 | doxyxml_dir = os.path.join(work_dir, 'doxyxml') |
20effc67 | 41 | out, _ = p.communicate(input=r''' |
11fdf7f2 TL |
42 | PROJECT_NAME = fmt |
43 | GENERATE_LATEX = NO | |
44 | GENERATE_MAN = NO | |
45 | GENERATE_RTF = NO | |
46 | CASE_SENSE_NAMES = NO | |
20effc67 TL |
47 | INPUT = {0}/chrono.h {0}/color.h {0}/core.h {0}/compile.h \ |
48 | {0}/format.h {0}/os.h {0}/ostream.h {0}/printf.h \ | |
49 | {0}/xchar.h | |
11fdf7f2 TL |
50 | QUIET = YES |
51 | JAVADOC_AUTOBRIEF = YES | |
52 | AUTOLINK_SUPPORT = NO | |
53 | GENERATE_HTML = NO | |
54 | GENERATE_XML = YES | |
55 | XML_OUTPUT = {1} | |
56 | ALIASES = "rst=\verbatim embed:rst" | |
57 | ALIASES += "endrst=\endverbatim" | |
58 | MACRO_EXPANSION = YES | |
59 | PREDEFINED = _WIN32=1 \ | |
20effc67 | 60 | __linux__=1 \ |
11fdf7f2 TL |
61 | FMT_USE_VARIADIC_TEMPLATES=1 \ |
62 | FMT_USE_RVALUE_REFERENCES=1 \ | |
63 | FMT_USE_USER_DEFINED_LITERALS=1 \ | |
eafe8130 | 64 | FMT_USE_ALIAS_TEMPLATES=1 \ |
11fdf7f2 TL |
65 | FMT_API= \ |
66 | "FMT_BEGIN_NAMESPACE=namespace fmt {{" \ | |
67 | "FMT_END_NAMESPACE=}}" \ | |
9f95a23c | 68 | "FMT_STRING_ALIAS=1" \ |
20effc67 TL |
69 | "FMT_DOC=1" |
70 | EXCLUDE_SYMBOLS = fmt::formatter fmt::printf_formatter fmt::arg_join \ | |
71 | fmt::basic_format_arg::handle | |
11fdf7f2 | 72 | '''.format(include_dir, doxyxml_dir).encode('UTF-8')) |
20effc67 TL |
73 | out = out.decode('utf-8') |
74 | internal_symbols = [ | |
75 | 'fmt::detail::.*', | |
76 | 'basic_data<>', | |
77 | 'fmt::type_identity', | |
78 | 'fmt::dynamic_formatter' | |
79 | ] | |
80 | noisy_warnings = [ | |
81 | 'warning: (Compound|Member .* of class) (' + '|'.join(internal_symbols) + \ | |
82 | ') is not documented.', | |
83 | 'warning: Internal inconsistency: .* does not belong to any container!' | |
84 | ] | |
85 | for w in noisy_warnings: | |
86 | out = re.sub('.*' + w + '\n', '', out) | |
87 | print(out) | |
11fdf7f2 TL |
88 | if p.returncode != 0: |
89 | raise CalledProcessError(p.returncode, cmd) | |
20effc67 | 90 | |
11fdf7f2 TL |
91 | html_dir = os.path.join(work_dir, 'html') |
92 | main_versions = reversed(versions[-3:]) | |
20effc67 | 93 | check_call([os.path.join('virtualenv', 'bin', 'sphinx-build'), |
11fdf7f2 TL |
94 | '-Dbreathe_projects.format=' + os.path.abspath(doxyxml_dir), |
95 | '-Dversion=' + version, '-Drelease=' + version, | |
96 | '-Aversion=' + version, '-Aversions=' + ','.join(main_versions), | |
97 | '-b', 'html', doc_dir, html_dir]) | |
98 | try: | |
20effc67 | 99 | check_call(['lessc', '--verbose', '--clean-css', |
11fdf7f2 TL |
100 | '--include-path=' + os.path.join(doc_dir, 'bootstrap'), |
101 | os.path.join(doc_dir, 'fmt.less'), | |
102 | os.path.join(html_dir, '_static', 'fmt.css')]) | |
103 | except OSError as e: | |
104 | if e.errno != errno.ENOENT: | |
105 | raise | |
106 | print('lessc not found; make sure that Less (http://lesscss.org/) ' + | |
107 | 'is installed') | |
108 | sys.exit(1) | |
109 | return html_dir | |
110 | ||
111 | if __name__ == '__main__': | |
112 | create_build_env() | |
113 | build_docs(sys.argv[1]) |