[5daabd2] | 1 | import sys, os |
---|
[f916fca] | 2 | from waflib.Build import BuildContext |
---|
[5daabd2] | 3 | |
---|
[14bbcb1] | 4 | sphinx_min_version = (1,3) |
---|
| 5 | |
---|
[a316b1f] | 6 | |
---|
[f916fca] | 7 | def 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 | |
---|
[0858375] | 28 | print("running:", cmd) |
---|
[f916fca] | 29 | call(cmd) |
---|
| 30 | |
---|
| 31 | |
---|
[ed3794e] | 32 | def 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 | |
---|
[f916fca] | 41 | class spell(BuildContext): |
---|
| 42 | __doc__ = "Check spelling. Supply a list of files or a glob (*.rst)" |
---|
| 43 | cmd = 'spell' |
---|
| 44 | fun = 'cmd_spell' |
---|
[3a71759] | 45 | |
---|
| 46 | |
---|
[ed3794e] | 47 | class linkcheck(BuildContext): |
---|
| 48 | __doc__ = "Check all external URL references." |
---|
| 49 | cmd = 'linkcheck' |
---|
| 50 | fun = 'cmd_linkcheck' |
---|
| 51 | |
---|
| 52 | |
---|
[14bbcb1] | 53 | def check_sphinx_version(ctx, minver): |
---|
[0f5ccd4] | 54 | version = ctx.cmd_and_log(ctx.env.BIN_SPHINX_BUILD + ['--version']).split(" ")[-1:][0].strip() |
---|
| 55 | try: |
---|
| 56 | ver = tuple(map(int, version.split("."))) |
---|
| 57 | except: |
---|
| 58 | ctx.fatal("Sphinx version cannot be checked: %s" % version) |
---|
[14bbcb1] | 59 | if ver < minver: |
---|
| 60 | ctx.fatal("Sphinx version is too old: %s" % ".".join(map(str, ver))) |
---|
| 61 | |
---|
| 62 | return ver |
---|
| 63 | |
---|
[a316b1f] | 64 | |
---|
[5daabd2] | 65 | def cmd_configure(ctx): |
---|
[9b5801a] | 66 | ctx.load('tex') |
---|
| 67 | |
---|
[2bcd424] | 68 | ctx.env.append_value('PDFLATEXFLAGS', '-shell-escape') |
---|
| 69 | |
---|
[9b5801a] | 70 | ctx.find_program("sphinx-build", var="BIN_SPHINX_BUILD", mandatory=True) |
---|
[f916fca] | 71 | ctx.find_program("aspell", var="BIN_ASPELL", mandatory=False) |
---|
[a316b1f] | 72 | ctx.find_program("inliner", var="BIN_INLINER", mandatory=False) |
---|
[9b5801a] | 73 | |
---|
[14bbcb1] | 74 | ctx.start_msg("Checking if Sphinx is at least %s.%s" % sphinx_min_version) |
---|
| 75 | ver = check_sphinx_version(ctx, sphinx_min_version) |
---|
| 76 | |
---|
| 77 | ctx.end_msg("yes (%s)" % ".".join(map(str, ver))) |
---|
| 78 | |
---|
| 79 | |
---|
[a316b1f] | 80 | def doc_pdf(ctx, source_dir, conf_dir): |
---|
[7c1f215] | 81 | if not ctx.env.PDFLATEX or not ctx.env.MAKEINDEX: |
---|
| 82 | ctx.fatal('The programs pdflatex and makeindex are required') |
---|
| 83 | |
---|
[a316b1f] | 84 | ctx( |
---|
| 85 | rule = "${BIN_SPHINX_BUILD} -b latex -c %s -j %d -d build/doctrees %s build/latex" % (conf_dir, ctx.options.jobs, source_dir), |
---|
| 86 | cwd = ctx.path.abspath(), |
---|
| 87 | source = ctx.path.ant_glob('**/*.rst'), |
---|
| 88 | target = "latex/%s.tex" % ctx.path.name |
---|
| 89 | ) |
---|
[14bbcb1] | 90 | |
---|
[a316b1f] | 91 | ctx.add_group() |
---|
[5daabd2] | 92 | |
---|
[a316b1f] | 93 | ctx( |
---|
| 94 | features = 'tex', |
---|
| 95 | cwd = "%s/latex/" % ctx.path.get_bld().abspath(), |
---|
| 96 | type = 'pdflatex', |
---|
| 97 | source = ctx.bldnode.find_or_declare("latex/%s.tex" % ctx.path.name), |
---|
| 98 | prompt = 0 |
---|
| 99 | ) |
---|
[5daabd2] | 100 | |
---|
[a316b1f] | 101 | def doc_singlehtml(ctx, source_dir, conf_dir): |
---|
| 102 | if not ctx.env.BIN_INLINER: |
---|
| 103 | ctx.fatal("Node inliner is required install with 'npm install -g inliner' (https://github.com/remy/inliner)") |
---|
| 104 | |
---|
| 105 | ctx( |
---|
| 106 | rule = "${BIN_SPHINX_BUILD} -b singlehtml -c %s -j %d -d build/doctrees %s build/singlehtml" % (conf_dir, ctx.options.jobs, source_dir), |
---|
| 107 | cwd = ctx.path.abspath(), |
---|
| 108 | source = ctx.path.ant_glob('**/*.rst'), |
---|
| 109 | target = "singlehtml/index.html" |
---|
| 110 | ) |
---|
| 111 | |
---|
| 112 | ctx.add_group() |
---|
| 113 | |
---|
| 114 | ctx( |
---|
| 115 | rule = "${BIN_INLINER} ${SRC} > ${TGT}", |
---|
| 116 | source = "singlehtml/index.html", |
---|
| 117 | target = "singlehtml/%s.html" % ctx.path.name |
---|
| 118 | ) |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | def html_resources(ctx): |
---|
[170418a] | 122 | for dir_name in ["_static", "_templates"]: |
---|
| 123 | files = ctx.path.parent.find_node("common").ant_glob("%s/*" % dir_name) |
---|
| 124 | ctx.path.get_bld().make_node(dir_name).mkdir() # dirs |
---|
[9b5801a] | 125 | |
---|
| 126 | ctx( |
---|
[a316b1f] | 127 | features = "subst", |
---|
| 128 | is_copy = True, |
---|
| 129 | source = files, |
---|
[170418a] | 130 | target = [ctx.bldnode.find_node(dir_name).get_bld().make_node(x.name) for x in files] |
---|
[9b5801a] | 131 | ) |
---|
| 132 | |
---|
[170418a] | 133 | # copy images |
---|
| 134 | # ctx.path.get_bld().make_node("images").mkdir() |
---|
| 135 | # files = ctx.path.parent.ant_glob("images/**") |
---|
| 136 | # ctx( |
---|
| 137 | # features = "subst", |
---|
| 138 | # is_copy = True, |
---|
| 139 | # source = files, |
---|
| 140 | # target = [x.srcpath().replace("../", "") for x in files] |
---|
| 141 | # ) |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | |
---|
[9b5801a] | 145 | |
---|
[a316b1f] | 146 | def cmd_build(ctx, conf_dir=".", source_dir="."): |
---|
| 147 | srcnode = ctx.srcnode.abspath() |
---|
| 148 | |
---|
| 149 | if ctx.options.pdf: |
---|
| 150 | doc_pdf(ctx, source_dir, conf_dir) |
---|
| 151 | elif ctx.options.singlehtml: |
---|
| 152 | html_resources(ctx) |
---|
| 153 | doc_singlehtml(ctx, source_dir, conf_dir) |
---|
| 154 | else: |
---|
| 155 | html_resources(ctx) |
---|
[9b5801a] | 156 | ctx( |
---|
| 157 | rule = "${BIN_SPHINX_BUILD} -b html -c %s -j %d -d build/doctrees %s build/html" % (conf_dir, ctx.options.jobs, source_dir), |
---|
| 158 | cwd = ctx.path.abspath(), |
---|
| 159 | source = ctx.path.ant_glob('**/*.rst'),# + ctx.path.ant_glob('conf.py'), |
---|
| 160 | target = ctx.path.find_or_declare('html/index.html') |
---|
| 161 | ) |
---|
| 162 | |
---|
| 163 | def cmd_options(ctx): |
---|
| 164 | ctx.add_option('--pdf', action='store_true', default=False, help="Build PDF.") |
---|
[a316b1f] | 165 | ctx.add_option('--singlehtml', action='store_true', default=False, help="Build Single HTML file, requires Node Inliner") |
---|
| 166 | |
---|
[5daabd2] | 167 | |
---|
[3a71759] | 168 | def cmd_options_path(ctx): |
---|
[9b5801a] | 169 | cmd_options(ctx) |
---|
| 170 | ctx.add_option('--rtems-path-py', type='string', help="Full path to py/ in RTEMS source repository.") |
---|
[3a71759] | 171 | |
---|
| 172 | |
---|
| 173 | def cmd_configure_path(ctx): |
---|
| 174 | if not ctx.options.rtems_path_py: |
---|
| 175 | ctx.fatal("--rtems-path-py is required") |
---|
| 176 | |
---|
| 177 | ctx.env.RTEMS_PATH = ctx.options.rtems_path_py |
---|
| 178 | |
---|
| 179 | cmd_configure(ctx) |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | CONF_FRAG = """ |
---|
| 183 | sys.path.append(os.path.abspath('../../common/')) |
---|
| 184 | sys.path.append('%s') |
---|
| 185 | templates_path = ['_templates'] |
---|
| 186 | html_static_path = ['_static'] |
---|
| 187 | """ |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | # XXX: fix this ugly hack. No time to waste on it. |
---|
| 191 | def cmd_build_path(ctx): |
---|
| 192 | def run(task): |
---|
| 193 | |
---|
| 194 | with open("conf.py") as fp: |
---|
| 195 | conf = "import sys, os\nsys.path.append(os.path.abspath('../../common/'))\n" |
---|
| 196 | conf += fp.read() |
---|
| 197 | |
---|
| 198 | task.inputs[0].abspath() |
---|
| 199 | task.outputs[0].write(conf + (CONF_FRAG % ctx.env.RTEMS_PATH)) |
---|
| 200 | |
---|
| 201 | ctx( |
---|
| 202 | rule = run, |
---|
| 203 | source = [ctx.path.parent.find_node("common/conf.py"), ctx.path.find_node("./conf.py")], |
---|
| 204 | target = ctx.path.get_bld().make_node('conf.py') |
---|
| 205 | ) |
---|
| 206 | |
---|
| 207 | cmd_build(ctx, conf_dir="build", source_dir="build") |
---|