source: rtems-docs/common/waf.py @ 7c1f215

4.115
Last change on this file since 7c1f215 was 7c1f215, checked in by Amar Takhar <amar@…>, on 01/20/16 at 02:03:57

Only require makeindex and pdflatex when trying to build PDF.

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