source: rtems-docs/common/latex.py @ 07f151f

5
Last change on this file since 07f151f was 07f151f, checked in by Chris Johns <chrisj@…>, on 11/10/22 at 04:32:44

waf: Backport from main build fixes

Closes #4752

  • Property mode set to 100644
File size: 6.0 KB
Line 
1#
2# Support for Latex used to build the PDF output format.
3#
4
5import os
6import re
7
8package_test_preamble = ['\\newif\\ifsphinxKeepOldNames \\sphinxKeepOldNamestrue',
9                         '\documentclass[a4paper,11pt,english]{report}']
10package_test_postamble = ['\\begin{document} test \\end{document}']
11package_tests = {
12    'Bjarne'         : ['\\usepackage[Bjarne]{fncychap}'],
13    'alltt'          : ['\\usepackage{alltt}'],
14    'amsmath'        : ['\\usepackage{amsmath}'],
15    'amssymb'        : ['\\usepackage{amssymb}'],
16    'amstext'        : ['\\usepackage{amstext}'],
17    'anyfontsize'    : ['\\usepackage{anyfontsize}'],
18    'array'          : ['\\usepackage{array}'],
19    'atbegshi'       : ['\\usepackage{atbegshi}'],
20    'babel'          : ['\\usepackage{babel}'],
21    'babel'          : ['\\usepackage{babel}'],
22    'calc'           : ['\\usepackage{calc}'],
23    'capt-of'        : ['\\usepackage{capt-of}'],
24    'charter'        : ['\\usepackage{charter}'],
25    'cmap'           : ['\\usepackage{cmap}'],
26    'color'          : ['\\usepackage{color}'],
27    'eqparbox'       : ['\\usepackage{eqparbox}'],
28    'enumitem'       : ['\\usepackage{enumitem}'],
29    'etoolbox'       : ['\\usepackage{etoolbox}'],
30    'fancybox'       : ['\\usepackage{fancybox}'],
31    'fancyhdr'       : ['\\usepackage{fancyhdr}'],
32    'fancyvrb'       : ['\\usepackage{fancyvrb}'],
33    'float'          : ['\\usepackage{float}'],
34    'fncychap'       : ['\\usepackage{fncychap}'],
35    'fontenc'        : ['\\usepackage[T1]{fontenc}'],
36    'footnote'       : ['\\usepackage{footnote}'],
37    'framed'         : ['\\usepackage{framed}'],
38    'graphicx'       : ['\\usepackage{graphicx}'],
39    'hypcap'         : ['\\usepackage{hyperref}',
40                        '\\usepackage{hypcap}'],
41    'hyperref'       : ['\\usepackage{hyperref}'],
42    'inconsolata'    : ['\\usepackage{inconsolata}'],
43    'ifplatform'     : ['\\usepackage{ifplatform}'],
44    'ifthen'         : ['\\usepackage{ifthen}'],
45    'inputenc'       : ['\\usepackage{inputenc}'],
46    'keyval'         : ['\\usepackage{keyval}'],
47    'kvoptions'      : ['\\usepackage{kvoptions}'],
48    'lato'           : ['\\usepackage{lato}'],
49    'lineno'         : ['\\usepackage{lineno}'],
50    'longtable'      : ['\\usepackage{longtable}'],
51    'makeidx'        : ['\\usepackage{makeidx}'],
52    'multirow'       : ['\\usepackage{multirow}'],
53    'parskip'        : ['\\usepackage{parskip}'],
54    'pdftexcmds'     : ['\\usepackage{pdftexcmds}'],
55    'textcomp'       : ['\\usepackage{textcomp}'],
56    'threeparttable' : ['\\usepackage{threeparttable}'],
57    'times'          : ['\\usepackage{times}'],
58    'titlesec'       : ['\\usepackage{titlesec}'],
59    'upquote'        : ['\\usepackage{upquote}'],
60    'utf8'           : ['\\usepackage[utf8]{inputenc}'],
61    'wrapfig'        : ['\\usepackage{wrapfig}'],
62    'xcolor'         : ['\\usepackage{xcolor}'],
63    'xstring'        : ['\\usepackage{xstring}'],
64}
65package_optional = ['inconsolata',
66                    'lato']
67
68#
69# Add per host support. If there is a version clash for the same texlive
70# package create a directory, add to that directory and use the path in this
71# name here.
72#
73hosts = {
74}
75
76def tex_test(test):
77    return os.linesep.join(package_test_preamble +
78                           package_tests[test] +
79                           package_test_postamble)
80
81def host_name():
82    uname = os.uname()
83    if uname[0] == 'Linux':
84        try:
85            from distro import linux_distribution
86        except:
87            from platform import linux_distribution
88        distro = linux_distribution()
89        name = '%s/%s' % (uname[0], distro[0])
90        version = distro[1]
91    else:
92        name = uname[0]
93        version = uname[2]
94    return name, version
95
96def local_packages():
97    host, version = host_name()
98    packages = None
99    if host in hosts:
100        for hv in list(hosts[host].keys()):
101            if re.compile(hv).match(version) is not None:
102                packages = hosts[host][hv]
103    return packages
104
105def configure_tests(conf):
106    #
107    # Using a hint from ita (thank you) :
108    #  https://github.com/waf-project/waf/blob/master/demos/tex/wscript
109    #
110    def build_latex_test(bld):
111        def write_tex_test(tsk):
112            tsk.outputs[0].write(tex_test(tsk.env.TEST))
113
114        test = bld.kw['tex_test']
115        bld.env.TEST = test
116
117        bld.to_log('%s.tex %s' % (test, '=' * (40 - len(test) + 5)))
118        bld.to_log(tex_test(test))
119        bld.to_log('=' * 40)
120
121        bld(rule = write_tex_test, target = 'main.tex')
122        bld(features = 'tex', type = 'pdflatex', source = 'main.tex', prompt = 0)
123
124    tests = sorted(package_tests.keys())
125    local_packs = local_packages()
126    excludes = [p for p in package_optional]
127    if local_packs is not None:
128        excludes += [p[:p.rfind('.')] for p in local_packs]
129    for e in excludes:
130        if e in tests:
131            tests.remove(e)
132
133    fails = 0
134    r = conf.find_program("pygmentize", mandatory = False)
135    if r is None:
136        fails += 1
137    for t in tests:
138        r = conf.test(build_fun = build_latex_test,
139                      msg = "Checking for Tex package '%s'" % (t),
140                      tex_test = t,
141                      okmsg = 'ok',
142                      errmsg = 'not found (please install)',
143                      mandatory = False)
144        if r is None:
145            fails += 1
146    if fails > 0:
147        conf.fatal('There are %d Tex package failures. Please fix.' % (fails))
148
149    fails = 0
150    for t in package_optional:
151        r = conf.test(build_fun = build_latex_test,
152                      msg = "Checking for Tex package '%s'" % (t),
153                      tex_test = t,
154                      okmsg = 'ok',
155                      errmsg = 'not found (degraded fonts)',
156                      mandatory = False)
157        if r is None:
158            fails += 1
159    if fails == 0:
160        conf.env.RTEMSEXTRAFONTS = 'rtemsextrafonts.sty'
161    else:
162        if not conf.options.disable_extra_fonts:
163            conf.fatal('Extra fonts not found, install or use --disable-extra-fonts')
164        conf.env.RTEMSEXTRAFONTS = 'rtemsextrafonts-null.sty'
Note: See TracBrowser for help on using the repository browser.