source: rtems-docs/common/waf.py @ 89f2347

4.115
Last change on this file since 89f2347 was 89f2347, checked in by Amar Takhar <amar@…>, on 01/20/16 at 00:33:59

Fix typo and add another dependency.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1import sys, os
2from waflib.Build import BuildContext
3
4
5sphinx_min_version = (1,3)
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
38
39def check_sphinx_version(ctx, minver):
40#       try:
41        version = ctx.cmd_and_log(ctx.env.BIN_SPHINX_BUILD + ['--version']).split(" ")[-1:][0]
42        ver = tuple(map(int, version.split(".")))
43#       except Exception:
44#               ctx.fatal("Version check failed please report")
45
46        if ver < minver:
47                ctx.fatal("Sphinx version is too old: %s" % ".".join(map(str, ver)))
48
49        return ver
50
51def cmd_configure(ctx):
52        ctx.load('tex')
53
54
55        if not ctx.env.PDFLATEX or not ctx.env.MAKEINDEX:
56                ctx.fatal('The programs pdflatex and makeindex are required')
57
58        ctx.find_program("sphinx-build", var="BIN_SPHINX_BUILD", mandatory=True)
59        ctx.find_program("aspell", var="BIN_ASPELL", mandatory=False)
60
61
62        ctx.start_msg("Checking if Sphinx is at least %s.%s" % sphinx_min_version)
63        ver = check_sphinx_version(ctx, sphinx_min_version)
64
65        ctx.end_msg("yes (%s)" % ".".join(map(str, ver)))
66
67
68
69def cmd_build(ctx, conf_dir=".", source_dir="."):
70        srcnode = ctx.srcnode.abspath()
71
72        if ctx.options.pdf:
73
74                ctx(
75                        rule    = "${BIN_SPHINX_BUILD} -b latex -c %s -j %d -d build/doctrees %s build/latex" % (conf_dir, ctx.options.jobs, source_dir),
76                        cwd             = ctx.path.abspath(),
77                        source  = ctx.path.ant_glob('**/*.rst'),
78                        target  = "latex/%s.tex" % ctx.path.name
79                )
80
81                ctx.add_group()
82
83                ctx(
84                        features        = 'tex',
85                        cwd                     = "%s/latex/" % ctx.path.get_bld().abspath(),
86                        type            = 'pdflatex',
87                        source          = ctx.bldnode.find_or_declare("latex/%s.tex" % ctx.path.name),
88                        prompt          = 0
89                )
90
91        else:
92        # Copy HTML resources.
93                for dir in ["_static", "_templates"]:
94                        files = ctx.path.parent.find_node("common").ant_glob("%s/*" % dir)
95                        ctx.path.get_bld().make_node(dir).mkdir() # dirs
96
97                        ctx(
98                                features    = "subst",
99                                is_copy     = True,
100                                source      = files,
101                                target      = [ctx.bldnode.find_node(dir).get_bld().make_node(x.name) for x in files]
102                        )
103
104                ctx(
105                        rule   = "${BIN_SPHINX_BUILD} -b html -c %s -j %d -d build/doctrees %s build/html" % (conf_dir, ctx.options.jobs, source_dir),
106                        cwd     = ctx.path.abspath(),
107                        source =  ctx.path.ant_glob('**/*.rst'),# + ctx.path.ant_glob('conf.py'),
108                        target = ctx.path.find_or_declare('html/index.html')
109                )
110
111def cmd_options(ctx):
112        ctx.add_option('--pdf', action='store_true', default=False, help="Build PDF.")
113
114def cmd_options_path(ctx):
115        cmd_options(ctx)
116        ctx.add_option('--rtems-path-py', type='string', help="Full path to py/ in RTEMS source repository.")
117
118
119def cmd_configure_path(ctx):
120        if not ctx.options.rtems_path_py:
121                ctx.fatal("--rtems-path-py is required")
122
123        ctx.env.RTEMS_PATH = ctx.options.rtems_path_py
124
125        cmd_configure(ctx)
126
127
128CONF_FRAG = """
129sys.path.append(os.path.abspath('../../common/'))
130sys.path.append('%s')
131templates_path = ['_templates']
132html_static_path = ['_static']
133"""
134
135
136# XXX: fix this ugly hack.  No time to waste on it.
137def cmd_build_path(ctx):
138        def run(task):
139
140                with open("conf.py") as fp:
141                        conf = "import sys, os\nsys.path.append(os.path.abspath('../../common/'))\n"
142                        conf += fp.read()
143
144                task.inputs[0].abspath()
145                task.outputs[0].write(conf + (CONF_FRAG % ctx.env.RTEMS_PATH))
146
147        ctx(
148                rule   = run,
149                source = [ctx.path.parent.find_node("common/conf.py"), ctx.path.find_node("./conf.py")],
150                target = ctx.path.get_bld().make_node('conf.py')
151    )
152
153        cmd_build(ctx, conf_dir="build", source_dir="build")
154
155
Note: See TracBrowser for help on using the repository browser.