fmt/doc/build.py

119 lines
4.6 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# Build the documentation.
import errno, os, re, sys
from subprocess import check_call, CalledProcessError, Popen, PIPE, STDOUT
2022-01-02 20:01:32 +03:00
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', '8.0.0', '8.0.1', '8.1.0']
2017-07-01 17:30:51 +03:00
class Pip:
def __init__(self, venv_dir):
self.path = os.path.join(venv_dir, 'bin', 'pip')
def install(self, package, commit=None):
"Install package using pip."
if commit:
package = 'git+https://github.com/{0}.git@{1}'.format(package, commit)
print('Installing {0}'.format(package))
check_call([self.path, 'install', package])
def create_build_env(venv_dir='virtualenv'):
# Create virtualenv.
if not os.path.exists(venv_dir):
check_call(['python3', '-m', 'venv', venv_dir])
2020-10-07 18:11:59 +03:00
# Install Sphinx and Breathe. Require the exact version of Sphinx which is
# compatible with Breathe.
pip = Pip(venv_dir)
2021-06-03 19:10:07 +03:00
pip.install('wheel')
2020-11-29 20:13:14 +03:00
pip.install('six')
# See: https://github.com/sphinx-doc/sphinx/issues/9777
pip.install('docutils==0.17.1')
pip.install('sphinx-doc/sphinx', 'v3.3.0')
2021-06-27 18:10:37 +03:00
pip.install('michaeljones/breathe', 'v4.25.0')
2016-05-08 18:03:01 +03:00
def build_docs(version='dev', **kwargs):
2016-05-09 18:36:16 +03:00
doc_dir = kwargs.get('doc_dir', os.path.dirname(os.path.realpath(__file__)))
2016-05-26 17:35:10 +03:00
work_dir = kwargs.get('work_dir', '.')
2018-02-11 20:23:17 +03:00
include_dir = kwargs.get(
'include_dir', os.path.join(os.path.dirname(doc_dir), 'include', 'fmt'))
# Build docs.
2015-05-20 18:06:12 +03:00
cmd = ['doxygen', '-']
2020-11-08 17:16:49 +03:00
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
2016-05-26 17:35:10 +03:00
doxyxml_dir = os.path.join(work_dir, 'doxyxml')
2020-11-08 17:13:56 +03:00
out, _ = p.communicate(input=r'''
2016-04-28 17:00:22 +03:00
PROJECT_NAME = fmt
GENERATE_LATEX = NO
GENERATE_MAN = NO
GENERATE_RTF = NO
CASE_SENSE_NAMES = NO
2020-10-07 18:11:59 +03:00
INPUT = {0}/chrono.h {0}/color.h {0}/core.h {0}/compile.h \
2021-06-02 18:19:54 +03:00
{0}/format.h {0}/os.h {0}/ostream.h {0}/printf.h \
{0}/xchar.h
QUIET = YES
JAVADOC_AUTOBRIEF = YES
AUTOLINK_SUPPORT = NO
GENERATE_HTML = NO
GENERATE_XML = YES
2016-05-26 17:35:10 +03:00
XML_OUTPUT = {1}
ALIASES = "rst=\verbatim embed:rst"
ALIASES += "endrst=\endverbatim"
MACRO_EXPANSION = YES
PREDEFINED = _WIN32=1 \
2021-01-09 18:18:56 +03:00
__linux__=1 \
2021-10-03 17:05:31 +03:00
FMT_ENABLE_IF(...)= \
FMT_USE_VARIADIC_TEMPLATES=1 \
FMT_USE_RVALUE_REFERENCES=1 \
2015-12-18 18:13:43 +03:00
FMT_USE_USER_DEFINED_LITERALS=1 \
2018-10-07 17:48:27 +03:00
FMT_USE_ALIAS_TEMPLATES=1 \
2018-05-12 22:57:16 +03:00
FMT_API= \
2018-05-12 23:12:04 +03:00
"FMT_BEGIN_NAMESPACE=namespace fmt {{" \
2018-09-13 17:20:43 +03:00
"FMT_END_NAMESPACE=}}" \
2018-12-13 04:50:50 +03:00
"FMT_STRING_ALIAS=1" \
2021-06-27 16:41:54 +03:00
"FMT_VARIADIC(...)=" \
"FMT_VARIADIC_W(...)=" \
"FMT_DOC=1"
EXCLUDE_SYMBOLS = fmt::formatter fmt::printf_formatter fmt::arg_join \
fmt::basic_format_arg::handle
2016-05-26 17:35:10 +03:00
'''.format(include_dir, doxyxml_dir).encode('UTF-8'))
2021-06-03 19:32:12 +03:00
out = out.decode('utf-8')
2020-11-08 17:48:34 +03:00
internal_symbols = [
'fmt::detail::.*',
'basic_data<>',
2020-11-08 17:58:41 +03:00
'fmt::type_identity',
2020-11-08 17:48:34 +03:00
'fmt::dynamic_formatter'
]
2020-11-08 17:58:41 +03:00
noisy_warnings = [
2020-11-08 18:04:42 +03:00
'warning: (Compound|Member .* of class) (' + '|'.join(internal_symbols) + \
') is not documented.',
2020-11-08 17:58:41 +03:00
'warning: Internal inconsistency: .* does not belong to any container!'
]
for w in noisy_warnings:
2020-11-08 17:29:50 +03:00
out = re.sub('.*' + w + '\n', '', out)
2020-11-08 17:13:56 +03:00
print(out)
if p.returncode != 0:
2015-05-20 18:06:12 +03:00
raise CalledProcessError(p.returncode, cmd)
2020-11-08 17:13:56 +03:00
2016-05-26 17:35:10 +03:00
html_dir = os.path.join(work_dir, 'html')
2017-07-01 17:30:51 +03:00
main_versions = reversed(versions[-3:])
2021-06-19 16:31:19 +03:00
check_call([os.path.join(work_dir, 'virtualenv', 'bin', 'sphinx-build'),
'-Dbreathe_projects.format=' + os.path.abspath(doxyxml_dir),
'-Dversion=' + version, '-Drelease=' + version,
2017-07-01 17:30:51 +03:00
'-Aversion=' + version, '-Aversions=' + ','.join(main_versions),
2016-06-02 16:41:25 +03:00
'-b', 'html', doc_dir, html_dir])
try:
2020-11-07 20:27:06 +03:00
check_call(['lessc', '--verbose', '--clean-css',
'--include-path=' + os.path.join(doc_dir, 'bootstrap'),
os.path.join(doc_dir, 'fmt.less'),
os.path.join(html_dir, '_static', 'fmt.css')])
except OSError as e:
if e.errno != errno.ENOENT:
raise
print('lessc not found; make sure that Less (http://lesscss.org/) ' +
'is installed')
sys.exit(1)
2016-05-26 17:35:10 +03:00
return html_dir
2015-05-20 18:06:12 +03:00
if __name__ == '__main__':
2016-05-08 18:03:01 +03:00
create_build_env()
build_docs(sys.argv[1])