From ef413e3eac947507ae1dc62dc365d225c30f4bbf Mon Sep 17 00:00:00 2001 From: pennae Date: Sun, 12 Feb 2023 09:04:07 +0100 Subject: [PATCH] nixos/manual: split manpages-combined from manual-combined once we generate the entire manual-combined.xml with a single nixos-render-docs invocation we will no longer need any options xml files. likewise we do not need the test options xml in the manpage build. splitting manpages-combined from manual-combined also allows these two to run in parallel, slightly improving build times. --- nixos/doc/manual/default.nix | 94 +++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 39 deletions(-) diff --git a/nixos/doc/manual/default.nix b/nixos/doc/manual/default.nix index e0bcec1ea6b5..30f1f51b3878 100644 --- a/nixos/doc/manual/default.nix +++ b/nixos/doc/manual/default.nix @@ -148,6 +148,43 @@ let "--stringparam chunk.toc ${toc}" ]; + linterFunctions = '' + # outputs the context of an xmllint error output + # LEN lines around the failing line are printed + function context { + # length of context + local LEN=6 + # lines to print before error line + local BEFORE=4 + + # xmllint output lines are: + # file.xml:1234: there was an error on line 1234 + while IFS=':' read -r file line rest; do + echo + if [[ -n "$rest" ]]; then + echo "$file:$line:$rest" + local FROM=$(($line>$BEFORE ? $line - $BEFORE : 1)) + # number lines & filter context + nl --body-numbering=a "$file" | sed -n "$FROM,+$LEN p" + else + if [[ -n "$line" ]]; then + echo "$file:$line" + else + echo "$file" + fi + fi + done + } + + function lintrng { + xmllint --debug --noout --nonet \ + --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \ + "$1" \ + 2>&1 | context 1>&2 + # ^ redirect assumes xmllint doesn’t print to stdout + } + ''; + manual-combined = runCommand "nixos-manual-combined" { inherit sources; nativeBuildInputs = [ buildPackages.libxml2.bin buildPackages.libxslt.bin ]; @@ -157,50 +194,29 @@ let ${copySources} xmllint --xinclude --output ./manual-combined.xml ./manual.xml - xmllint --xinclude --noxincludenode \ - --output ./man-pages-combined.xml ./man-pages.xml - # outputs the context of an xmllint error output - # LEN lines around the failing line are printed - function context { - # length of context - local LEN=6 - # lines to print before error line - local BEFORE=4 - - # xmllint output lines are: - # file.xml:1234: there was an error on line 1234 - while IFS=':' read -r file line rest; do - echo - if [[ -n "$rest" ]]; then - echo "$file:$line:$rest" - local FROM=$(($line>$BEFORE ? $line - $BEFORE : 1)) - # number lines & filter context - nl --body-numbering=a "$file" | sed -n "$FROM,+$LEN p" - else - if [[ -n "$line" ]]; then - echo "$file:$line" - else - echo "$file" - fi - fi - done - } - - function lintrng { - xmllint --debug --noout --nonet \ - --relaxng ${docbook5}/xml/rng/docbook/docbook.rng \ - "$1" \ - 2>&1 | context 1>&2 - # ^ redirect assumes xmllint doesn’t print to stdout - } + ${linterFunctions} mkdir $out cp manual-combined.xml $out/ - cp man-pages-combined.xml $out/ lintrng $out/manual-combined.xml - lintrng $out/man-pages-combined.xml + ''; + + manpages-combined = runCommand "nixos-manpages-combined.xml" + { nativeBuildInputs = [ buildPackages.libxml2.bin buildPackages.libxslt.bin ]; + meta.description = "The NixOS manpages as plain docbook XML"; + } + '' + mkdir generated + cp -prd ${./man-pages.xml} man-pages.xml + ln -s ${optionsDoc.optionsDocBook} generated/options-db.xml + + xmllint --xinclude --noxincludenode --output $out ./man-pages.xml + + ${linterFunctions} + + lintrng $out ''; in rec { @@ -300,7 +316,7 @@ in rec { --param man.endnotes.are.numbered 0 \ --param man.break.after.slash 1 \ ${docbook_xsl_ns}/xml/xsl/docbook/manpages/docbook.xsl \ - ${manual-combined}/man-pages-combined.xml + ${manpages-combined} '' else '' mkdir -p $out/share/man/man5