]>
git.proxmox.com Git - ceph.git/blob - ceph/src/fmt/doc/build.py
2 # Build the documentation.
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
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']
11 def pip_install(package
, commit
=None, **kwargs
):
12 "Install package using pip."
13 min_version
= kwargs
.get('min_version')
15 from pkg_resources
import get_distribution
, DistributionNotFound
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
))
21 except DistributionNotFound
:
24 package
= 'git+https://github.com/{0}.git@{1}'.format(package
, commit
)
25 print('Installing {0}'.format(package
))
26 check_call(['pip', 'install', package
])
28 def create_build_env(dirname
='virtualenv'):
30 if not os
.path
.exists(dirname
):
31 check_call(['virtualenv', dirname
])
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'):
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).
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
:
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',
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'))
68 cmd
= ['doxygen', '-']
69 p
= Popen(cmd
, stdin
=PIPE
)
70 doxyxml_dir
= os
.path
.join(work_dir
, 'doxyxml')
71 p
.communicate(input=r
'''
77 INPUT = {0}/core.h {0}/format.h {0}/ostream.h \
78 {0}/printf.h {0}/time.h
80 JAVADOC_AUTOBRIEF = YES
85 ALIASES = "rst=\verbatim embed:rst"
86 ALIASES += "endrst=\endverbatim"
87 INLINE_INHERITED_MEMBERS = YES
89 PREDEFINED = _WIN32=1 \
90 FMT_USE_VARIADIC_TEMPLATES=1 \
91 FMT_USE_RVALUE_REFERENCES=1 \
92 FMT_USE_USER_DEFINED_LITERALS=1 \
93 FMT_USE_ALIAS_TEMPLATES=1 \
95 "FMT_BEGIN_NAMESPACE=namespace fmt {{" \
96 "FMT_END_NAMESPACE=}}" \
97 "FMT_STRING_ALIAS=1" \
98 "FMT_ENABLE_IF_T(B, T)=T"
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
])
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')])
116 if e
.errno
!= errno
.ENOENT
:
118 print('lessc not found; make sure that Less (http://lesscss.org/) ' +
123 if __name__
== '__main__':
125 build_docs(sys
.argv
[1])