source: rtems-docs/common/waf.py @ bc37517

4.115
Last change on this file since bc37517 was 2bcd424, checked in by Amar Takhar <amar@…>, on 03/10/16 at 16:48:15

Switch to using Minted and splitting long lines in verbatim.

  • Property mode set to 100644
File size: 5.4 KB
Line 
1import sys, os
2from waflib.Build import BuildContext
3
4sphinx_min_version = (1,3)
5
6
7def cmd_spell(ctx):
8        from waflib import Options
9        from sys import argv
10        from subprocess import call
11
12        Options.commands = None # stop warnings about knowing commands.
13
14        if not ctx.env.BIN_ASPELL:
15                ctx.fatal("'aspell' is required please add binary to your path and re-run configure.")
16
17        if len(argv) < 3:
18                ctx.fatal("Please supply at least one file name")
19
20        files = argv[2:]
21
22        path = ctx.path.parent.abspath()
23
24        # XXX: add error checking eg check if file exists.
25        for file in files:
26                cmd = ctx.env.BIN_ASPELL + ["-c", "--personal=%s/common/spell/dict/rtems" % path, "--extra-dicts=%s/common/spell/en_GB-ise-w_accents.multi" % path, file]
27
28                print("running:", cmd)
29                call(cmd)
30
31
32def cmd_linkcheck(ctx, conf_dir=".", source_dir="."):
33        ctx(
34                rule    = "${BIN_SPHINX_BUILD} -b linkcheck -c %s -j %d -d build/doctrees %s build/linkcheck" % (conf_dir, ctx.options.jobs, source_dir),
35                cwd             = ctx.path.abspath(),
36                source  = ctx.path.ant_glob('**/*.rst'),
37                target  = "linkcheck/output.txt"
38        )
39
40
41class spell(BuildContext):
42        __doc__ = "Check spelling.  Supply a list of files or a glob (*.rst)"
43        cmd = 'spell'
44        fun = 'cmd_spell'
45
46
47class linkcheck(BuildContext):
48        __doc__ = "Check all external URL references."
49        cmd = 'linkcheck'
50        fun = 'cmd_linkcheck'
51
52
53def check_sphinx_version(ctx, minver):
54        version = ctx.cmd_and_log(ctx.env.BIN_SPHINX_BUILD + ['--version']).split(" ")[-1:][0].strip()
55        try:
56                ver = tuple(map(int, version.split(".")))
57        except:
58                ctx.fatal("Sphinx version cannot be checked: %s" % version)
59        if ver < minver:
60                ctx.fatal("Sphinx version is too old: %s" % ".".join(map(str, ver)))
61
62        return ver
63
64
65def cmd_configure(ctx):
66        ctx.load('tex')
67
68        ctx.env.append_value('PDFLATEXFLAGS', '-shell-escape')
69
70        ctx.find_program("sphinx-build", var="BIN_SPHINX_BUILD", mandatory=True)
71        ctx.find_program("aspell", var="BIN_ASPELL", mandatory=False)
72        ctx.find_program("inliner", var="BIN_INLINER", mandatory=False)
73
74        ctx.start_msg("Checking if Sphinx is at least %s.%s" % sphinx_min_version)
75        ver = check_sphinx_version(ctx, sphinx_min_version)
76
77        ctx.end_msg("yes (%s)" % ".".join(map(str, ver)))
78
79
80def doc_pdf(ctx, source_dir, conf_dir):
81        if not ctx.env.PDFLATEX or not ctx.env.MAKEINDEX:
82                ctx.fatal('The programs pdflatex and makeindex are required')
83
84        ctx(
85                rule    = "${BIN_SPHINX_BUILD} -b latex -c %s -j %d -d build/doctrees %s build/latex" % (conf_dir, ctx.options.jobs, source_dir),
86                cwd             = ctx.path.abspath(),
87                source  = ctx.path.ant_glob('**/*.rst'),
88                target  = "latex/%s.tex" % ctx.path.name
89        )
90
91        ctx.add_group()
92
93        ctx(
94                features        = 'tex',
95                cwd                     = "%s/latex/" % ctx.path.get_bld().abspath(),
96                type            = 'pdflatex',
97                source          = ctx.bldnode.find_or_declare("latex/%s.tex" % ctx.path.name),
98                prompt          = 0
99        )
100
101def doc_singlehtml(ctx, source_dir, conf_dir):
102        if not ctx.env.BIN_INLINER:
103                ctx.fatal("Node inliner is required install with 'npm install -g inliner' (https://github.com/remy/inliner)")
104
105        ctx(
106                rule    = "${BIN_SPHINX_BUILD} -b singlehtml -c %s -j %d -d build/doctrees %s build/singlehtml" % (conf_dir, ctx.options.jobs, source_dir),
107                cwd             = ctx.path.abspath(),
108                source  = ctx.path.ant_glob('**/*.rst'),
109                target  = "singlehtml/index.html"
110        )
111
112        ctx.add_group()
113
114        ctx(
115                rule    = "${BIN_INLINER} ${SRC} > ${TGT}",
116                source  = "singlehtml/index.html",
117                target  = "singlehtml/%s.html" % ctx.path.name
118        )
119
120
121def html_resources(ctx):
122        for dir in ["_static", "_templates"]:
123                files = ctx.path.parent.find_node("common").ant_glob("%s/*" % dir)
124                ctx.path.get_bld().make_node(dir).mkdir() # dirs
125
126                ctx(
127                        features    = "subst",
128                        is_copy     = True,
129                        source      = files,
130                        target      = [ctx.bldnode.find_node(dir).get_bld().make_node(x.name) for x in files]
131                )
132
133
134def cmd_build(ctx, conf_dir=".", source_dir="."):
135        srcnode = ctx.srcnode.abspath()
136
137        if ctx.options.pdf:
138                doc_pdf(ctx, source_dir, conf_dir)
139        elif ctx.options.singlehtml:
140                html_resources(ctx)
141                doc_singlehtml(ctx, source_dir, conf_dir)
142        else:
143                html_resources(ctx)
144                ctx(
145                        rule   = "${BIN_SPHINX_BUILD} -b html -c %s -j %d -d build/doctrees %s build/html" % (conf_dir, ctx.options.jobs, source_dir),
146                        cwd     = ctx.path.abspath(),
147                        source =  ctx.path.ant_glob('**/*.rst'),# + ctx.path.ant_glob('conf.py'),
148                        target = ctx.path.find_or_declare('html/index.html')
149                )
150
151def cmd_options(ctx):
152        ctx.add_option('--pdf', action='store_true', default=False, help="Build PDF.")
153        ctx.add_option('--singlehtml', action='store_true', default=False, help="Build Single HTML file, requires Node Inliner")
154
155
156def cmd_options_path(ctx):
157        cmd_options(ctx)
158        ctx.add_option('--rtems-path-py', type='string', help="Full path to py/ in RTEMS source repository.")
159
160
161def cmd_configure_path(ctx):
162        if not ctx.options.rtems_path_py:
163                ctx.fatal("--rtems-path-py is required")
164
165        ctx.env.RTEMS_PATH = ctx.options.rtems_path_py
166
167        cmd_configure(ctx)
168
169
170CONF_FRAG = """
171sys.path.append(os.path.abspath('../../common/'))
172sys.path.append('%s')
173templates_path = ['_templates']
174html_static_path = ['_static']
175"""
176
177
178# XXX: fix this ugly hack.  No time to waste on it.
179def cmd_build_path(ctx):
180        def run(task):
181
182                with open("conf.py") as fp:
183                        conf = "import sys, os\nsys.path.append(os.path.abspath('../../common/'))\n"
184                        conf += fp.read()
185
186                task.inputs[0].abspath()
187                task.outputs[0].write(conf + (CONF_FRAG % ctx.env.RTEMS_PATH))
188
189        ctx(
190                rule   = run,
191                source = [ctx.path.parent.find_node("common/conf.py"), ctx.path.find_node("./conf.py")],
192                target = ctx.path.get_bld().make_node('conf.py')
193    )
194
195        cmd_build(ctx, conf_dir="build", source_dir="build")
Note: See TracBrowser for help on using the repository browser.