[PATCH 2/2] docs: meson.build: Generate HTML files directly by meson

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Our HTML file generation has two steps:

1) XSL transformation

  This applies headers/footers and various other bits.

2) xmllint reformat

  To fix indentation and to look like a proper XML/XHTML.

Historically these were done in a pipeline. The meson conversion
attempted to do the same by adding 'scripts/meson-html-gen.py' which
tried to pipeline them.

Unfortunately this hid errors from 'xsltproc' as return value was not
checked and the stderr was piped into xmllints stdin. The result was
that any invalid input file would result into an empty output file.

Since the script's only purpose was to prevent additional temporary
files being created at the cost of compexity and obscurity (by hiding
the commands used to process the XMLs and their arguments being weirdly
passed through positional arguments) we can remove it if we accept extra
temporary files in the directory.

Moving the generation directly into the meson definition makes it more
obvious what's happening and saves readers from having to parse what's
going on. A free bonus is that errors are now properly caught and
reported.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 docs/meson.build          | 39 +++++++++++++++++++++++++--------------
 scripts/meson-html-gen.py | 37 -------------------------------------
 2 files changed, 25 insertions(+), 51 deletions(-)
 delete mode 100755 scripts/meson-html-gen.py

diff --git a/docs/meson.build b/docs/meson.build
index 400c1ca955..d1943161b8 100644
--- a/docs/meson.build
+++ b/docs/meson.build
@@ -253,33 +253,44 @@ docs_html_in_gen += {
 }

 foreach data : docs_html_in_gen
-  html_file = '@0@.html'.format(data['name'])
+  xslout_filename = '@0@xxxxxxxxxxxx'.format(data['name'])
+  html_filename = '@0@.html'.format(data['name'])

-  out_file = custom_target(
-    html_file,
+  xslout_file = custom_target(
+    xslout_filename,
     input: data['file'],
-    output: html_file,
+    output: xslout_filename,
     command: [
-      meson_python_prog,
-      python3_prog.path(),
-      meson_html_gen_prog.path(),
       xsltproc_prog.path(),
-      xmllint_prog.path(),
-      meson.build_root(),
-      docs_timestamp,
+      '--stringparam', 'pagesrc', data.get('source', ''),
+      '--stringparam', 'builddir', meson.build_root(),
+      '--stringparam', 'timestamp', docs_timestamp,
+      '--nonet',
       site_xsl,
       '@INPUT@',
-      '@OUTPUT@',
-      data.get('source', []),
     ],
     depends: [ aclperms_gen ],
     depend_files: [ page_xsl ],
+    capture: true,
+  )
+
+  html_file = custom_target(
+    html_filename,
+    input: xslout_file,
+    output: html_filename,
+    command: [
+      xmllint_prog.path(),
+      '--nonet',
+      '--format',
+      '@INPUT@',
+    ],
     install: true,
     install_dir: docs_html_dir,
+    capture: true
   )

-  install_web_deps += out_file
-  install_web_files += '@0@:@1@'.format(out_file.full_path(), docs_html_dir)
+  install_web_deps += html_file
+  install_web_files += '@0@:@1@'.format(html_file.full_path(), docs_html_dir)
 endforeach

 subdir('fonts')
diff --git a/scripts/meson-html-gen.py b/scripts/meson-html-gen.py
deleted file mode 100755
index 2731d734a7..0000000000
--- a/scripts/meson-html-gen.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python3
-
-import argparse
-import subprocess
-
-parser = argparse.ArgumentParser()
-parser.add_argument("xsltproc", type=str, help="path to xsltproc bin")
-parser.add_argument("xmllint", type=str, help="path to xmllint bin")
-parser.add_argument("builddir", type=str, help="build root dir path")
-parser.add_argument("timestamp", type=str, help="docs timestamp")
-parser.add_argument("style", type=str, help="XSL stile file")
-parser.add_argument("infile", type=str, help="path to source HTML file")
-parser.add_argument("htmlfile", type=str, help="path to generated HTML file")
-parser.add_argument("pagesrc", type=str, default="", nargs='?', help="(optional) path to source file used for edit this page")
-args = parser.parse_args()
-
-html_tmp = subprocess.run(
-    [
-        args.xsltproc,
-        '--stringparam', 'pagesrc', args.pagesrc,
-        '--stringparam', 'builddir', args.builddir,
-        '--stringparam', 'timestamp', args.timestamp,
-        '--nonet', args.style, args.infile,
-    ],
-    stdout=subprocess.PIPE,
-    stderr=subprocess.PIPE,
-)
-
-html = subprocess.run(
-    [args.xmllint, '--nonet', '--format', '-'],
-    input=html_tmp.stdout,
-    stdout=subprocess.PIPE,
-    stderr=subprocess.PIPE,
-)
-
-with open(args.htmlfile, 'wb') as outfile:
-    outfile.write(html.stdout)
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux