1 | import sys, os |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | def cmd_configure(ctx): |
---|
6 | ctx.find_program("sphinx-build", var="SPHINX_BUILD") |
---|
7 | |
---|
8 | def cmd_build(ctx, conf_dir=".", source_dir="."): |
---|
9 | srcnode = ctx.srcnode.abspath() |
---|
10 | |
---|
11 | # Copy resources. |
---|
12 | for dir in ["_static", "_templates"]: |
---|
13 | files = ctx.path.parent.find_node("common").ant_glob("%s/*" % dir) |
---|
14 | ctx.path.get_bld().make_node(dir).mkdir() # dirs |
---|
15 | |
---|
16 | ctx( |
---|
17 | features = "subst", |
---|
18 | is_copy = True, |
---|
19 | source = files, |
---|
20 | target = [ctx.bldnode.find_node(dir).get_bld().make_node(x.name) for x in files] |
---|
21 | ) |
---|
22 | |
---|
23 | ctx( |
---|
24 | rule = "${SPHINX_BUILD} -b html -c %s -j %d -d build/doctrees %s build/html" % (conf_dir, ctx.options.jobs, source_dir), |
---|
25 | cwd = ctx.path.abspath(), |
---|
26 | source = ctx.path.ant_glob('**/*.rst'),# + ctx.path.ant_glob('conf.py'), |
---|
27 | target = ctx.path.find_or_declare('html/index.html') |
---|
28 | ) |
---|
29 | |
---|
30 | def cmd_options_path(ctx): |
---|
31 | ctx.add_option('--rtems-path-py', type='string', help="Path to py/ in RTEMS.") |
---|
32 | |
---|
33 | |
---|
34 | def cmd_configure_path(ctx): |
---|
35 | if not ctx.options.rtems_path_py: |
---|
36 | ctx.fatal("--rtems-path-py is required") |
---|
37 | |
---|
38 | ctx.env.RTEMS_PATH = ctx.options.rtems_path_py |
---|
39 | |
---|
40 | cmd_configure(ctx) |
---|
41 | |
---|
42 | |
---|
43 | CONF_FRAG = """ |
---|
44 | sys.path.append(os.path.abspath('../../common/')) |
---|
45 | sys.path.append('%s') |
---|
46 | templates_path = ['_templates'] |
---|
47 | html_static_path = ['_static'] |
---|
48 | """ |
---|
49 | |
---|
50 | |
---|
51 | # XXX: fix this ugly hack. No time to waste on it. |
---|
52 | def cmd_build_path(ctx): |
---|
53 | def run(task): |
---|
54 | |
---|
55 | with open("conf.py") as fp: |
---|
56 | conf = "import sys, os\nsys.path.append(os.path.abspath('../../common/'))\n" |
---|
57 | conf += fp.read() |
---|
58 | |
---|
59 | task.inputs[0].abspath() |
---|
60 | task.outputs[0].write(conf + (CONF_FRAG % ctx.env.RTEMS_PATH)) |
---|
61 | |
---|
62 | ctx( |
---|
63 | rule = run, |
---|
64 | source = [ctx.path.parent.find_node("common/conf.py"), ctx.path.find_node("./conf.py")], |
---|
65 | target = ctx.path.get_bld().make_node('conf.py') |
---|
66 | ) |
---|
67 | |
---|
68 | cmd_build(ctx, conf_dir="build", source_dir="build") |
---|