173.3. kdos-doc-1.0.0
The KDOS book as HTML, kdos(7), kdos-doc and a manual page per kdos-* command
| Version | 1.0.0, release 2 |
| Source tree | src/system/kdos-doc/ |
| Phase | 41_system (System), 962 of 1047 in build order |
| Licence | MIT |
| Homepage | https://github.com/kunaldawn/kdos |
| Build time | 0.1 SBU |
| Installed size | 7.2 MiB in 109 files |
| Recipe | src/system/kdos-doc/kpkgbuild |
About
kdos-doc puts the KDOS book on the machine, so it can be read with no network: as HTML in the browser or the Help Center, as man pages, and through the kdos-doc command.
Its build.sh renders the book with one call to mkbook.py, which
- renders every page of
docs/kdosto HTML under/usr/share/doc/kdoswith lowdown, withkdos.cssfrom the port directory in a<style>element of every page; - writes
kdos(7), which says where the book is and lists its chapters; - writes a manual page for every
kdos-*command in the book’s command index, and for each command of ours named without the prefix thatOURSinmkbook.pylists (kpkgand its four other names,ksvc,service,kinstall,xdg-terminal-exec). Each page’s DESCRIPTION is the section of the book that command’s row links to, soman kdos-appboxand the book say the same thing, in the same words.
How a reader finds them is in Manual pages and the book. The rest of build.sh compiles kdos-doc and installs the entries described below.
kdos-doc. /usr/bin/kdos-doc, built from kdos-doc.c beside the recipe, opens the book at a page, for example kdos-doc 04-programs/kdos-command#kdos-theme:
- in a graphical session it hands KHelpCenter that page’s file URL, or the desktop’s browser through
xdg-openwhere there is no Help Center; - on a text console it opens the page in lynx, or
w3mwhere lynx is absent, at the anchor’s heading; - when its output is not a terminal or no text browser is installed, it prints the file’s path, so a pipe or a script gets the path.
The page name is checked against letters, digits and ._-/, with no .., before it is used, so it can only name a page under /usr/share/doc/kdos, and it reaches the viewer as one argument through exec.
The Help Center and help:/. The book is read in the browser, and in the Help Center where khelpcenter is installed; the installation medium does not carry the Help Center, since it pulls in Qt WebEngine. The package installs KHelpCenter’s entry, /usr/share/khelpcenter/plugins/kdos.desktop, whose X-DOC-Weight of -100 puts the KDOS book first in the Help Center’s tree, above KDE’s own handbooks, which stay under help:/; kdos-kfs installs the second entry, kfs.desktop, at -99.
The book is under help:/ as well. The package links /usr/share/doc/HTML/en/kdos to ../../kdos, and KIO’s help: worker, which looks a path up among the handbooks under /usr/share/doc/HTML/<language>, serves help:/kdos/<page>.html from the book’s own files. That is the address a KDOS settings page’s Help button opens, from its X-DocPath (see Help): in the Help Center where it is installed, and otherwise in the default browser at the page’s file: address under the same link, which kguiaddons’ help: handler finds there. kpkg’s manual prune names the link as one it keeps.
The Library entry. The package also installs the menu’s Library launcher, kdos-library-kdos-book.desktop, which opens the book in the browser through xdg-open and names it as an item of library:/ (see kio-library). kdos-kfs installs the second, kdos-library-kfs-book.desktop, beside its own book, so the menu offers KDOS from Scratch only where it is installed.
mkbook.py takes three arguments: the directory that holds kdos/ and screenshots/ (the port directory itself), the package root, and the repository’s src/, which it searches for manual pages that programs ship themselves. Nothing is fetched, and lowdown is run with an argument vector.
Why it is in KDOS
The comment above it in script/phases/41_system/packages.d/src-system.txt:
The book under /usr/share/doc/kdos, kdos(7), and a manual page per kdos-* command, rendered from docs/kdos by lowdown.
Sources
None: the port builds from its own directory, /kdos/src/system/kdos-doc.
Dependencies
Required by: no port names it.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install kdos-doc'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /kdos/src/system/kdos-doc.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/kdos-doc
SRC=$SRC_ROOT/kdos-doc-1.0.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
python3 "$PORT_SRC/mkbook.py" "$PORT_SRC" "$PKG" "$PORT_SRC/../.."
gcc $CFLAGS -O2 -std=gnu11 -Wall -Wextra -o kdos-doc "$PORT_SRC/kdos-doc.c" $LDFLAGS
install -Dm755 kdos-doc "$PKG/usr/bin/kdos-doc"
install -Dm644 -t "$PKG/usr/share/khelpcenter/plugins" "$PORT_SRC"/khelpcenter/kdos.desktop
install -Dm644 -t "$PKG/usr/share/applications" "$PORT_SRC"/applications/kdos-library-kdos-book.desktop
install -d "$PKG/usr/share/doc/HTML/en"
ln -s ../../kdos "$PKG/usr/share/doc/HTML/en/kdos"
The switches, and why each is set:
-std=gnu11,-O2,-Wall,-Wextra— The tree’s C dialect and optimisation level, named again forkdos-doc.c, with the compiler’s common and extra warnings.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/kdos-doc, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf kdos-doc-1.0.0-2.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/kdos-doc, and runs the triggers its paths call for.
Other files in the port directory, read by build.sh: applications/, kdos/, kdos-doc.c, kdos.css, khelpcenter/, mkbook.py, screenshots/.
Contents
Installed programs: kdos-doc.
Installed directories: /usr/share/doc/kdos.
Short descriptions
kdos-doc |
Open the KDOS book at a page, in the Help Center, the browser, or lynx on a console: kdos-doc [CHAPTER/PAGE[#ANCHOR]] |
Notes
The stylesheet is in every page rather than linked: KHelpCenter answers every request a help: page makes, its stylesheet included, as text/html, and its browser engine refuses a linked stylesheet of that type, so a linked kdos.css would style the book under file: and leave it bare under help:.
KHelpCenter adds KDE’s handbook stylesheet to every page it shows, as a <style id="default"> appended to the page’s head, after kdos.css, so its element rules would replace the book’s colours with white paper and black text. kdos.css carries a second set of rules under html:has(> head > style#default), which match only a page carrying that element and outrank the handbook’s: in the Help Center the book keeps its own colours, and takes the desktop’s proportional face for its text and the Help Center’s margins.
The book reaches the port through two symbolic links in its directory, kdos to docs/kdos and screenshots to docs/screenshots. The recipe hash follows them, so an edit anywhere in the book or its pictures rebuilds this port on the next 41_system run, and an edit elsewhere under docs/ does not; a link to the whole of docs/ would rebuild it for the other book too. The chroot sees docs/ read-only at /kdos/docs. The image carries docs/kdos and docs/screenshots under /ports/docs so that the links resolve on an installed machine as well: a dangling link drops out of the recipe hash, and the machine would then take the installed book for stale. See Rebuilding one thing.
The build fails when a row of the command index links a section the book does not have, so a renamed heading is caught here rather than shipped as a manual page with no body.
A page’s NAME line is that row’s description cell, held to ASCII. mandoc’s makewhatis keeps the first 150 bytes of a NAME description’s roff, an escape such as \(dq for " counted at its written length, and apropos prints what it kept, so mkbook.py ends a longer description before the last clause separator (a comma, semicolon or colon, an opening parenthesis, a --) that fits, or at the last space when none does, and never leaves a bracket open. The cells are written short enough that no shipped page is cut; testing/selftest.sh checks both. See The manual index.
A command whose own port ships a kdos-*.1 page, as kdos-bb does, is left to that port. Two packages that wrote the same path would be a conflict kpkg refuses, which is also why a name without the prefix is listed by hand in OURS rather than taken from every row: the command index names upstream programs too (ping, getent, init), whose own ports install their pages. ksvc and service, installed in /usr/sbin, are section 8.
Headings are given the ids GitHub gives them, by the same rule as script/book/kfsgen.py and testing/anchorcheck.py, so a link that works on GitHub works in the installed book; a change to the rule in one of the three has to be made in all of them.