docs: meson.build: Prepare for use of identical code for XSLT processing of htmls

Meson unfortunately doesn't give us any means to share the code using
xsltproc to output HTMLs processed by our template. This means we will
have to resort to copy&paste engineering.

To make things simpler, let's use the same block of code in
docs/meson.build but also any of the subdirs which generate htmls.

This will be achieved by making it configurable and wrapping it in a
comment that instructs anybody editing it to keep it identical.

We need to be able to configure the template file used and installation
directory. The rest of the processing is same as we do in
docs/meson.build.

This code will then be copied to subdirs to refactor the current
approach used there.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Peter Krempa 2020-10-13 17:14:53 +02:00
parent fa84e3c46a
commit 4ced77a309

View File

@ -193,35 +193,37 @@ docs_rst2html_gen = generator(
) )
# docs_html_in_gen: # html_xslt_gen config
html_xslt_gen_xslt = site_xsl
html_xslt_gen_install_dir = docs_html_dir
html_xslt_gen = []
# html_xslt_gen:
# each entry is a dictionary with following items: # each entry is a dictionary with following items:
# name - base file name (required) # name - base file name (required), output file will become 'name.html'
# file - generated file (required) # file - input file (optional, 'name.html.in' assumed if missing)
# source - source filename relative to repository root (optional, if there is no source) # source - source filename relative to repository root (optional, if there is no source)
# depends - explicit dependency on other input (optional) # depends - explicit dependency on other input (optional)
docs_html_in_gen = []
foreach name : docs_html_in_files foreach name : docs_html_in_files
html_in_file = '@0@.html.in'.format(name) html_xslt_gen += {
docs_html_in_gen += {
'name': name, 'name': name,
'file': html_in_file, 'source': 'docs' / name + '.html.in',
'source': 'docs' / html_in_file,
} }
endforeach endforeach
foreach name : docs_rst_files foreach name : docs_rst_files
rst_file = '@0@.rst'.format(name) rst_file = '@0@.rst'.format(name)
docs_html_in_gen += { html_xslt_gen += {
'name': name, 'name': name,
'file': docs_rst2html_gen.process(rst_file), 'file': docs_rst2html_gen.process(rst_file),
'source': 'docs' / rst_file, 'source': 'docs' / rst_file,
} }
endforeach endforeach
docs_html_in_gen += { html_xslt_gen += {
'name': 'acl.html', 'name': 'acl',
'file': 'acl.html.in',
'source': 'docs' / 'acl.html.in', 'source': 'docs' / 'acl.html.in',
'depends': aclperms_gen, 'depends': aclperms_gen,
} }
@ -247,45 +249,55 @@ hvsupport_html_in = custom_target(
docs_api_generated, docs_api_generated,
], ],
) )
docs_html_in_gen += { html_xslt_gen += {
'name': 'hvsupport', 'name': 'hvsupport',
'file': hvsupport_html_in, 'file': hvsupport_html_in,
} }
news_html_in = docs_rst2html_gen.process(meson.source_root() / 'NEWS.rst') news_html_in = docs_rst2html_gen.process(meson.source_root() / 'NEWS.rst')
docs_html_in_gen += { html_xslt_gen += {
'name': 'news', 'name': 'news',
'file': news_html_in, 'file': news_html_in,
'source': 'NEWS.rst', 'source': 'NEWS.rst',
} }
foreach data : docs_html_in_gen # The following code between the markers must be kept identical with the other
html_file = '@0@.html'.format(data['name']) # copies of the code in various subdirs, since meson doesn't support any kind
# of functions.
out_file = custom_target( # --- begin of XSLT processing ---
html_file,
input: data['file'], foreach data : html_xslt_gen
output: html_file, html_filename = data['name'] + '.html'
html_file = custom_target(
html_filename,
input: data.get('file', data['name'] + '.html.in'),
output: html_filename,
command: [ command: [
xsltproc_prog, xsltproc_prog,
'--stringparam', 'pagesrc', data.get('source', ''), '--stringparam', 'pagesrc', data.get('source', ''),
'--stringparam', 'builddir', meson.build_root(), '--stringparam', 'builddir', meson.build_root(),
'--stringparam', 'timestamp', docs_timestamp, '--stringparam', 'timestamp', docs_timestamp,
'--nonet', '--nonet',
site_xsl, html_xslt_gen_xslt,
'@INPUT@', '@INPUT@',
], ],
depends: data.get('depends', []), depends: data.get('depends', []),
depend_files: [ page_xsl ], depend_files: [ page_xsl ],
capture: true, capture: true,
install: true, install: true,
install_dir: docs_html_dir, install_dir: html_xslt_gen_install_dir,
) )
install_web_deps += out_file install_web_deps += html_file
install_web_files += '@0@:@1@'.format(out_file.full_path(), docs_html_dir) install_web_files += html_file.full_path() + ':' + html_xslt_gen_install_dir
endforeach endforeach
html_xslt_gen = []
# --- end of XSLT processing ---
subdir('fonts') subdir('fonts')
subdir('html') subdir('html')
subdir('internals') subdir('internals')