-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.py
More file actions
125 lines (97 loc) · 3.85 KB
/
Copy pathdocs.py
File metadata and controls
125 lines (97 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""
File:
docs.py
Authors:
MarioS271
Copyright:
SPDX-License-Identifier: GPL-3.0-only
Description:
Build docs for Ferrite
Docs creation runs inside Docker
Usage:
python docs.py [build | open | all | clean]
"""
import shutil
import sys
import webbrowser
import lib
from lib import BUILD, CONTAINER_NAME, ROOT, banner, remove, run, run_in_container
# ─── config ───────────────────────────────────────────────────────────────────
TARGET = "x86_64-unknown-none"
# Crate whose docs we care about (must match the [package] name in Cargo.toml)
CRATE = "kernel"
# Manifest path *inside the container*
MANIFEST_CONTAINER = "src/kernel/Cargo.toml"
# Generated docs *inside the container* (target/ lives in a docker volume,
# so it is NOT visible on the host — the output has to be copied out)
DOCS_DIR_CONTAINER = f"/ferrite_os/target/{TARGET}/doc"
# Generated docs on the host
DOCS_DIR = ROOT / "docs"
DOCS_INDEX = DOCS_DIR / CRATE / "index.html"
# Staging dir for docker cp — it nests into an existing destination, so the
# copy lands here first and replaces docs/ only once it succeeded.
DOCS_TMP = BUILD / ".docs_tmp"
# ─── docs steps ───────────────────────────────────────────────────────────────
def do_docs():
banner("Building Docs (in container)")
lib.ensure_container_running()
run_in_container(
"cd /ferrite_os && "
"cargo doc "
f"--target {TARGET} "
f"--manifest-path {MANIFEST_CONTAINER} "
"--no-deps "
"--document-private-items"
)
# target/ is a docker volume — copy the generated docs onto the host
remove(DOCS_TMP)
BUILD.mkdir(parents=True, exist_ok=True)
run(["docker", "cp", f"{CONTAINER_NAME}:{DOCS_DIR_CONTAINER}", str(DOCS_TMP)])
# docs/ is entirely rustdoc output, so swap it wholesale
remove(DOCS_DIR)
shutil.move(str(DOCS_TMP), str(DOCS_DIR))
if not DOCS_INDEX.exists():
print(f" ✗ {DOCS_INDEX} not found after build — something went wrong")
print(f" (is the crate actually named '{CRATE}'?)")
sys.exit(1)
print(f" ✓ Docs: {DOCS_INDEX}")
def open_docs():
banner("Opening Docs")
if not DOCS_INDEX.exists():
print(" ✗ No docs found. Run build first.")
sys.exit(1)
url = DOCS_INDEX.resolve().as_uri()
print(f" >> {url}")
try:
opened = webbrowser.open(url)
except webbrowser.Error:
opened = False
if not opened:
print(" ! No browser available — open the URL above manually")
def clean():
banner("Cleaning Docs")
if not DOCS_DIR.exists():
print(" Nothing to clean")
return
remove(DOCS_DIR)
print(f" ✓ Deleted {DOCS_DIR}")
# ─── commands ─────────────────────────────────────────────────────────────────
def check_deps():
lib.check_dependencies(["docker"])
COMMANDS = {
"build": ("generate rustdoc for the kernel crate in Docker", [check_deps, do_docs]),
"open": ("open the generated docs in the browser", [open_docs]),
"all": ("build + open", [check_deps, do_docs, open_docs]),
"clean": ("delete generated docs", [clean]),
}
def main():
sys.stdout.reconfigure(encoding="utf-8")
lib.patch_path()
lib.list_config_vars({
"ROOT": ROOT,
"DOCS_DIR": DOCS_DIR,
"DOCS_INDEX": DOCS_INDEX,
})
lib.dispatch("docs.py", COMMANDS, default="all")
if __name__ == "__main__":
main()