3 # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 # Licensed under the Apache License, Version 2.0 (the "License").
6 # You may not use this file except in compliance with the License.
7 # A copy of the License is located at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # or in the "license" file accompanying this file. This file is distributed
12 # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 # express or implied. See the License for the specific language governing
14 # permissions and limitations under the License.
23 DOC_DIR = pathlib.Path(sys.path[0]).resolve()
24 sys.path.insert(1, str(DOC_DIR.parent))
26 # pylint: disable=wrong-import-position,import-error
27 import lib.ninja_syntax
30 OUT_DIR = DOC_DIR / "out"
32 BIN_DIR = DOC_DIR / "bin"
34 SRC_DIR = DOC_DIR / "src"
36 TEMPLATE_DIR = DOC_DIR / "templates"
37 TMP_DIR = DOC_DIR / "tmp"
39 ROFF_DIR = OUT_DIR / "man"
41 HTML_MAN_SRC_DIR = TMP_DIR / "roff_to_html"
42 HTML_UNIQUE_DIR = TMP_DIR / "html_unique"
47 "description": "converting ${man-name} to roff",
48 "command": "scdoc < ${in} > ${out}"
50 "name": "voluptuous_to_roff",
51 "description": "converting ${man-name} to roff",
52 "command": f"{BIN_DIR / 'schema-to-scdoc'}"
53 f" --project-root { DOC_DIR.parent }"
54 " --page-name ${man-name}"
55 " --data-path ${data-path}"
57 f" { TEMPLATE_DIR / 'voluptuous-man.jinja.scdoc' }"
60 "name": "roff_to_html",
61 "description": "converting ${man-name}.roff HTML",
62 "command": "mandoc -O fragment -Thtml < ${in} > ${out}"
64 "name": "uniquify_header_ids",
65 "description": "Giving unique header IDs to ${man-name}.html",
66 "command": f"sed -f {BIN_DIR}/uniquify-header-ids"
67 " -e 's/@MAN_NAME@/${man-name}/g'"
69 # Get rid of header and footer
76 "name": "build_html_doc",
77 "description": "Building final HTML page",
78 "command": f"{BIN_DIR}/build-html-doc"
79 " --html-manuals ${html-mans}"
80 f" --template-dir {TEMPLATE_DIR}"
82 " --roff-html-dir ${roff-html-dir}"
86 def make_html_unique(man, html_man, html_mans, builds):
87 html_unique = HTML_UNIQUE_DIR / f"{man.stem}.html"
89 "inputs": [html_man, BIN_DIR / "uniquify-header-ids"],
90 "outputs": [html_unique],
91 "rule": "uniquify_header_ids",
97 html_mans.append(html_unique)
100 def roff_to_html(man, roff_out, builds):
101 html_man = HTML_MAN_SRC_DIR / f"{man.stem}.html"
103 "inputs": [roff_out],
104 "outputs": [html_man],
105 "rule": "roff_to_html",
107 "man-name": man.stem,
114 def convert_man_dir_to_roff(src_dir, dst_dir, rule, html_mans, builds):
115 for man in (src_dir).iterdir():
116 roff_out = dst_dir / f"{man.stem}.roff"
119 "outputs": [roff_out],
122 "man-name": man.stem,
123 "data-path": man.resolve(),
126 html_man = roff_to_html(man, roff_out, builds)
127 make_html_unique(man, html_man, html_mans, builds)
134 convert_man_dir_to_roff(
135 SRC_DIR / "man", ROFF_DIR, "sc_to_roff", html_mans, builds)
136 convert_man_dir_to_roff(
137 SRC_DIR / "voluptuous-man", ROFF_DIR, "voluptuous_to_roff", html_mans,
141 "inputs": html_mans + [
142 BIN_DIR / "build-html-doc",
143 TEMPLATE_DIR / "index.jinja.html",
145 "outputs": [DOC_DIR / "out" / "html"/ "index.html"],
146 "rule": "build_html_doc",
148 "html-mans": " ".join([str(h) for h in html_mans]),
149 "roff-html-dir": HTML_MAN_SRC_DIR,
154 for k, v in build.items():
155 if isinstance(v, list):
156 build[k] = [str(s) for s in v]
158 build["implicit"].append(str(DOC_DIR / "configure"))
160 build["implicit"] = [str(DOC_DIR / "configure")]
162 with open("build.ninja", "w") as handle:
163 ninja = lib.ninja_syntax.Writer(handle)
170 if __name__ == "__main__":