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

4.115
Last change on this file since ed3794e was ed3794e, checked in by Amar Takhar <amar@…>, on 01/20/16 at 04:00:32

Add 'waf linkcheck' to check external references.

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