[gtkmm-documentation] docs/tutorial, Meson config: Check if xmllint can be used



commit b2cdae27133b5739452ca7d0f6757446890c5730
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Mon Sep 27 09:56:55 2021 +0200

    docs/tutorial, Meson config: Check if xmllint can be used

 Makefile.am                            |  1 +
 docs/tutorial/can_use_xmllint.xml      | 15 +++++++++++++++
 docs/tutorial/meson.build              | 22 ++++++++++++++++++++--
 meson.build                            |  2 +-
 tools/meson_aux/tutorial-custom-cmd.py | 12 +++++++++++-
 5 files changed, 48 insertions(+), 4 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index d879252..83ac230 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,6 +12,7 @@ dist_noinst_SCRIPTS = autogen.sh
 EXTRA_DIST = \
   meson.build \
   meson_options.txt \
+  docs/tutorial/can_use_xmllint.xml \
   docs/tutorial/insert_example_code.py \
   docs/tutorial/meson.build \
   docs/tutorial/LINGUAS \
diff --git a/docs/tutorial/can_use_xmllint.xml b/docs/tutorial/can_use_xmllint.xml
new file mode 100644
index 0000000..8ff1b0d
--- /dev/null
+++ b/docs/tutorial/can_use_xmllint.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<book xmlns="http://docbook.org/ns/docbook";
+      version="5.0" xml:id="index" xml:lang="en">
+
+<title>xmllint test</title>
+
+<chapter xml:id="chapter-introduction">
+<title>Introduction</title>
+  <para>
+  This is a short DocBook V5.0 document. It can be used for testing if the installed
+  version of xmllint or a similar program can validate a DocBook V5.0 document.
+  </para>
+</chapter>
+
+</book>
diff --git a/docs/tutorial/meson.build b/docs/tutorial/meson.build
index 28c2ff9..5bf61b9 100644
--- a/docs/tutorial/meson.build
+++ b/docs/tutorial/meson.build
@@ -7,14 +7,32 @@
 
 # xsltproc is required by tutorial_custom_cmd html.
 xsltproc = find_program('xsltproc', required: true)
-xmllint = find_program('xmllint', required: false)
 
+xmllint = find_program('xmllint', required: false)
 can_parse_and_validate = xmllint.found()
+validate = get_option('validation') ? 'true' : 'false'
+
+# Check if xmllint can be used.
+if xmllint.found()
+  can_parse_and_validate = run_command(
+    python3, tutorial_custom_cmd, 'xmllint',
+    validate,
+    meson.current_source_dir() / 'can_use_xmllint.xml',
+    meson.current_build_dir() / 'can_use_xmllint.stamp',
+  ).returncode() == 0
+  if not can_parse_and_validate
+    # The DocBook V5.0 package is called docbook5-xml in Ubuntu,
+    # docbook5-schemas in Fedora. It may have other names in other distros.
+    warning('Can\'t validate XML file.\n' +
+      'xmllint does not support Relax NG schemas and DocBook V5.0.\n' +
+      'DocBook V5.0 support may require docbook5-xml, docbook5-schemas or a similar package.'
+    )
+  endif
+endif
 
 can_build_translations = find_program('msgfmt', required: false).found() and \
                          find_program('itstool', required: false).found()
 build_translations_by_default = get_option('build-translations')
-validate = get_option('validation') ? 'true' : 'false'
 
 dblatex = find_program('dblatex', required: false)
 can_build_pdf = dblatex.found() or (xsltproc.found() and \
diff --git a/meson.build b/meson.build
index ec9c35b..3e3a7d8 100644
--- a/meson.build
+++ b/meson.build
@@ -109,7 +109,7 @@ endif
 validate = get_option('validation') and can_parse_and_validate
 explain_val = ''
 if get_option('validation') and not validate
-  explain_val = ' (requires xmllint)'
+  explain_val = ' (requires xmllint with Relax NG and DocBook V5.0 support)'
 endif
 
 build_translations = build_translations_by_default and can_build_translations
diff --git a/tools/meson_aux/tutorial-custom-cmd.py b/tools/meson_aux/tutorial-custom-cmd.py
index 4346293..0cc6e73 100755
--- a/tools/meson_aux/tutorial-custom-cmd.py
+++ b/tools/meson_aux/tutorial-custom-cmd.py
@@ -91,6 +91,13 @@ def xmllint():
   stamp_file_path = sys.argv[4]
 
   relax_ng_schema = 'http://docbook.org/xml/5.0/rng/docbook.rng'
+  # schematron_schema = 'http://docbook.org/xml/5.0/sch/docbook.sch'
+
+  # Validation against the Schematron schema does not work on Ubuntu 21.04:
+  # file:///usr/share/xml/docbook/schema/schematron/5.0/docbook.sch:6: element rule:
+  #   Schemas parser error : Failed to compile context expression db:firstterm[@linkend]
+  # .....
+  # Schematron schema http://docbook.org/xml/5.0/sch/docbook.sch failed to compile
 
   cmd = [
     'xmllint',
@@ -99,7 +106,10 @@ def xmllint():
     '--xinclude',
   ]
   if validate == 'true':
-    cmd += ['--relaxng', relax_ng_schema]
+    cmd += [
+      '--relaxng', relax_ng_schema,
+      #'--schematron', schematron_schema,
+    ]
   cmd += [input_xml_file]
   result = subprocess.run(cmd)
   if result.returncode:


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