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