[5daabd2] | 1 | import sys, os |
---|
[f916fca] | 2 | from waflib.Build import BuildContext |
---|
[5daabd2] | 3 | |
---|
[f916fca] | 4 | def cmd_spell(ctx): |
---|
| 5 | from waflib import Options |
---|
| 6 | from sys import argv |
---|
| 7 | from subprocess import call |
---|
| 8 | |
---|
| 9 | Options.commands = None # stop warnings about knowing commands. |
---|
| 10 | |
---|
| 11 | if not ctx.env.BIN_ASPELL: |
---|
| 12 | ctx.fatal("'aspell' is required please add binary to your path and re-run configure.") |
---|
| 13 | |
---|
| 14 | if len(argv) < 3: |
---|
| 15 | ctx.fatal("Please supply at least one file name") |
---|
| 16 | |
---|
| 17 | files = argv[2:] |
---|
| 18 | |
---|
| 19 | path = ctx.path.parent.abspath() |
---|
| 20 | |
---|
| 21 | # XXX: add error checking eg check if file exists. |
---|
| 22 | for file in files: |
---|
| 23 | 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] |
---|
| 24 | |
---|
| 25 | print "running:", cmd |
---|
| 26 | call(cmd) |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | class spell(BuildContext): |
---|
| 30 | __doc__ = "Check spelling. Supply a list of files or a glob (*.rst)" |
---|
| 31 | cmd = 'spell' |
---|
| 32 | fun = 'cmd_spell' |
---|
[3a71759] | 33 | |
---|
| 34 | |
---|
[5daabd2] | 35 | def cmd_configure(ctx): |
---|
[9b5801a] | 36 | ctx.load('tex') |
---|
| 37 | |
---|
| 38 | if not ctx.env.PDFLATEX: |
---|
| 39 | conf.fatal('The program LaTex is required') |
---|
| 40 | |
---|
| 41 | ctx.find_program("sphinx-build", var="BIN_SPHINX_BUILD", mandatory=True) |
---|
| 42 | # ctx.find_program("pdflatex", var="BIN_PDFLATEX", mandatory=True) |
---|
[f916fca] | 43 | ctx.find_program("aspell", var="BIN_ASPELL", mandatory=False) |
---|
[5daabd2] | 44 | |
---|
[9b5801a] | 45 | |
---|
[3a71759] | 46 | def cmd_build(ctx, conf_dir=".", source_dir="."): |
---|
[5daabd2] | 47 | srcnode = ctx.srcnode.abspath() |
---|
| 48 | |
---|
[9b5801a] | 49 | if ctx.options.pdf: |
---|
[5daabd2] | 50 | |
---|
| 51 | ctx( |
---|
[9b5801a] | 52 | rule = "${BIN_SPHINX_BUILD} -b latex -c %s -j %d -d build/doctrees %s build/latex" % (conf_dir, ctx.options.jobs, source_dir), |
---|
| 53 | cwd = ctx.path.abspath(), |
---|
| 54 | source = ctx.path.ant_glob('**/*.rst'), |
---|
| 55 | target = "latex/%s.tex" % ctx.path.name |
---|
[5daabd2] | 56 | ) |
---|
| 57 | |
---|
[9b5801a] | 58 | ctx.add_group() |
---|
| 59 | |
---|
| 60 | ctx( |
---|
| 61 | features = 'tex', |
---|
| 62 | cwd = "%s/latex/" % ctx.path.get_bld().abspath(), |
---|
| 63 | type = 'pdflatex', |
---|
| 64 | source = ctx.bldnode.find_or_declare("latex/%s.tex" % ctx.path.name), |
---|
| 65 | prompt = 0 |
---|
| 66 | ) |
---|
| 67 | |
---|
| 68 | else: |
---|
| 69 | # Copy HTML resources. |
---|
| 70 | for dir in ["_static", "_templates"]: |
---|
| 71 | files = ctx.path.parent.find_node("common").ant_glob("%s/*" % dir) |
---|
| 72 | ctx.path.get_bld().make_node(dir).mkdir() # dirs |
---|
| 73 | |
---|
| 74 | ctx( |
---|
| 75 | features = "subst", |
---|
| 76 | is_copy = True, |
---|
| 77 | source = files, |
---|
| 78 | target = [ctx.bldnode.find_node(dir).get_bld().make_node(x.name) for x in files] |
---|
| 79 | ) |
---|
| 80 | |
---|
| 81 | ctx( |
---|
| 82 | rule = "${BIN_SPHINX_BUILD} -b html -c %s -j %d -d build/doctrees %s build/html" % (conf_dir, ctx.options.jobs, source_dir), |
---|
| 83 | cwd = ctx.path.abspath(), |
---|
| 84 | source = ctx.path.ant_glob('**/*.rst'),# + ctx.path.ant_glob('conf.py'), |
---|
| 85 | target = ctx.path.find_or_declare('html/index.html') |
---|
| 86 | ) |
---|
| 87 | |
---|
| 88 | def cmd_options(ctx): |
---|
| 89 | ctx.add_option('--pdf', action='store_true', default=False, help="Build PDF.") |
---|
[5daabd2] | 90 | |
---|
[3a71759] | 91 | def cmd_options_path(ctx): |
---|
[9b5801a] | 92 | cmd_options(ctx) |
---|
| 93 | ctx.add_option('--rtems-path-py', type='string', help="Full path to py/ in RTEMS source repository.") |
---|
[3a71759] | 94 | |
---|
| 95 | |
---|
| 96 | def cmd_configure_path(ctx): |
---|
| 97 | if not ctx.options.rtems_path_py: |
---|
| 98 | ctx.fatal("--rtems-path-py is required") |
---|
| 99 | |
---|
| 100 | ctx.env.RTEMS_PATH = ctx.options.rtems_path_py |
---|
| 101 | |
---|
| 102 | cmd_configure(ctx) |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | CONF_FRAG = """ |
---|
| 106 | sys.path.append(os.path.abspath('../../common/')) |
---|
| 107 | sys.path.append('%s') |
---|
| 108 | templates_path = ['_templates'] |
---|
| 109 | html_static_path = ['_static'] |
---|
| 110 | """ |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | # XXX: fix this ugly hack. No time to waste on it. |
---|
| 114 | def cmd_build_path(ctx): |
---|
| 115 | def run(task): |
---|
| 116 | |
---|
| 117 | with open("conf.py") as fp: |
---|
| 118 | conf = "import sys, os\nsys.path.append(os.path.abspath('../../common/'))\n" |
---|
| 119 | conf += fp.read() |
---|
| 120 | |
---|
| 121 | task.inputs[0].abspath() |
---|
| 122 | task.outputs[0].write(conf + (CONF_FRAG % ctx.env.RTEMS_PATH)) |
---|
| 123 | |
---|
| 124 | ctx( |
---|
| 125 | rule = run, |
---|
| 126 | source = [ctx.path.parent.find_node("common/conf.py"), ctx.path.find_node("./conf.py")], |
---|
| 127 | target = ctx.path.get_bld().make_node('conf.py') |
---|
| 128 | ) |
---|
| 129 | |
---|
| 130 | cmd_build(ctx, conf_dir="build", source_dir="build") |
---|
[f916fca] | 131 | |
---|
| 132 | |
---|