source: rtems-docs/common/waf.py @ 0f5ccd4

4.115
Last change on this file since 0f5ccd4 was 0f5ccd4, checked in by Chris Johns <chrisj@…>, on 01/23/16 at 05:01:45

Generate a fatal error on a Sphinx beta version that cannot be parsed.

  • 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.find_program("sphinx-build", var="BIN_SPHINX_BUILD", mandatory=True)
69        ctx.find_program("aspell", var="BIN_ASPELL", mandatory=False)
70        ctx.find_program("inliner", var="BIN_INLINER", mandatory=False)
71
72        ctx.start_msg("Checking if Sphinx is at least %s.%s" % sphinx_min_version)
73        ver = check_sphinx_version(ctx, sphinx_min_version)
74
75        ctx.end_msg("yes (%s)" % ".".join(map(str, ver)))
76
77
78def doc_pdf(ctx, source_dir, conf_dir):
79        if not ctx.env.PDFLATEX or not ctx.env.MAKEINDEX:
80                ctx.fatal('The programs pdflatex and makeindex are required')
81
82        ctx(
83                rule    = "${BIN_SPHINX_BUILD} -b latex -c %s -j %d -d build/doctrees %s build/latex" % (conf_dir, ctx.options.jobs, source_dir),
84                cwd             = ctx.path.abspath(),
85                source  = ctx.path.ant_glob('**/*.rst'),
86                target  = "latex/%s.tex" % ctx.path.name
87        )
88
89        ctx.add_group()
90
91        ctx(
92                features        = 'tex',
93                cwd                     = "%s/latex/" % ctx.path.get_bld().abspath(),
94                type            = 'pdflatex',
95                source          = ctx.bldnode.find_or_declare("latex/%s.tex" % ctx.path.name),
96                prompt          = 0
97        )
98
99def doc_singlehtml(ctx, source_dir, conf_dir):
100        if not ctx.env.BIN_INLINER:
101                ctx.fatal("Node inliner is required install with 'npm install -g inliner' (https://github.com/remy/inliner)")
102
103        ctx(
104                rule    = "${BIN_SPHINX_BUILD} -b singlehtml -c %s -j %d -d build/doctrees %s build/singlehtml" % (conf_dir, ctx.options.jobs, source_dir),
105                cwd             = ctx.path.abspath(),
106                source  = ctx.path.ant_glob('**/*.rst'),
107                target  = "singlehtml/index.html"
108        )
109
110        ctx.add_group()
111
112        ctx(
113                rule    = "${BIN_INLINER} ${SRC} > ${TGT}",
114                source  = "singlehtml/index.html",
115                target  = "singlehtml/%s.html" % ctx.path.name
116        )
117
118
119def html_resources(ctx):
120        for dir in ["_static", "_templates"]:
121                files = ctx.path.parent.find_node("common").ant_glob("%s/*" % dir)
122                ctx.path.get_bld().make_node(dir).mkdir() # dirs
123
124                ctx(
125                        features    = "subst",
126                        is_copy     = True,
127                        source      = files,
128                        target      = [ctx.bldnode.find_node(dir).get_bld().make_node(x.name) for x in files]
129                )
130
131
132def cmd_build(ctx, conf_dir=".", source_dir="."):
133        srcnode = ctx.srcnode.abspath()
134
135        if ctx.options.pdf:
136                doc_pdf(ctx, source_dir, conf_dir)
137        elif ctx.options.singlehtml:
138                html_resources(ctx)
139                doc_singlehtml(ctx, source_dir, conf_dir)
140        else:
141                html_resources(ctx)
142                ctx(
143                        rule   = "${BIN_SPHINX_BUILD} -b html -c %s -j %d -d build/doctrees %s build/html" % (conf_dir, ctx.options.jobs, source_dir),
144                        cwd     = ctx.path.abspath(),
145                        source =  ctx.path.ant_glob('**/*.rst'),# + ctx.path.ant_glob('conf.py'),
146                        target = ctx.path.find_or_declare('html/index.html')
147                )
148
149def cmd_options(ctx):
150        ctx.add_option('--pdf', action='store_true', default=False, help="Build PDF.")
151        ctx.add_option('--singlehtml', action='store_true', default=False, help="Build Single HTML file, requires Node Inliner")
152
153
154def cmd_options_path(ctx):
155        cmd_options(ctx)
156        ctx.add_option('--rtems-path-py', type='string', help="Full path to py/ in RTEMS source repository.")
157
158
159def cmd_configure_path(ctx):
160        if not ctx.options.rtems_path_py:
161                ctx.fatal("--rtems-path-py is required")
162
163        ctx.env.RTEMS_PATH = ctx.options.rtems_path_py
164
165        cmd_configure(ctx)
166
167
168CONF_FRAG = """
169sys.path.append(os.path.abspath('../../common/'))
170sys.path.append('%s')
171templates_path = ['_templates']
172html_static_path = ['_static']
173"""
174
175
176# XXX: fix this ugly hack.  No time to waste on it.
177def cmd_build_path(ctx):
178        def run(task):
179
180                with open("conf.py") as fp:
181                        conf = "import sys, os\nsys.path.append(os.path.abspath('../../common/'))\n"
182                        conf += fp.read()
183
184                task.inputs[0].abspath()
185                task.outputs[0].write(conf + (CONF_FRAG % ctx.env.RTEMS_PATH))
186
187        ctx(
188                rule   = run,
189                source = [ctx.path.parent.find_node("common/conf.py"), ctx.path.find_node("./conf.py")],
190                target = ctx.path.get_bld().make_node('conf.py')
191    )
192
193        cmd_build(ctx, conf_dir="build", source_dir="build")
Note: See TracBrowser for help on using the repository browser.