[PATCH 138/150] docs: automatically track manual dependencies

Paolo Bonzini posted 150 patches 5 years, 5 months ago
Maintainers: Cornelia Huck <cohuck@redhat.com>, Christian Schoenebeck <qemu_oss@crudebyte.com>, Anthony Perard <anthony.perard@citrix.com>, Bastian Koppelmann <kbastian@mail.uni-paderborn.de>, Ben Warren <ben@skyportsystems.com>, Sagar Karandikar <sagark@eecs.berkeley.edu>, Michael Roth <mdroth@linux.vnet.ibm.com>, "Michael S. Tsirkin" <mst@redhat.com>, John Snow <jsnow@redhat.com>, Greg Kurz <groug@kaod.org>, Aurelien Jarno <aurelien@aurel32.net>, Stefano Stabellini <sstabellini@kernel.org>, Jiaxun Yang <jiaxun.yang@flygoat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Joel Stanley <joel@jms.id.au>, Keith Busch <kbusch@kernel.org>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Thomas Huth <thuth@redhat.com>, Laurent Vivier <laurent@vivier.eu>, Su Hang <suhang16@mails.ucas.ac.cn>, Hannes Reinecke <hare@suse.com>, David Gibson <david@gibson.dropbear.id.au>, Fam Zheng <fam@euphon.net>, Christian Borntraeger <borntraeger@de.ibm.com>, "Alex Bennée" <alex.bennee@linaro.org>, Wainer dos Santos Moschetta <wainersm@redhat.com>, Alex Williamson <alex.williamson@redhat.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>, Helge Deller <deller@gmx.de>, Stefan Berger <stefanb@linux.ibm.com>, Igor Mammedov <imammedo@redhat.com>, Laszlo Ersek <lersek@redhat.com>, Amit Shah <amit@kernel.org>, Yoshinori Sato <ysato@users.sourceforge.jp>, Riku Voipio <riku.voipio@iki.fi>, Max Filippov <jcmvbkbc@gmail.com>, Cleber Rosa <crosa@redhat.com>, Stafford Horne <shorne@gmail.com>, Richard Henderson <rth@twiddle.net>, Markus Armbruster <armbru@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Alexander Bulekov <alxndr@bu.edu>, Artyom Tarasenko <atar4qemu@gmail.com>, Gerd Hoffmann <kraxel@redhat.com>, Juan Quintela <quintela@redhat.com>, David Hildenbrand <david@redhat.com>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, "Cédric Le Goater" <clg@kaod.org>, Bandan Das <bsd@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Palmer Dabbelt <palmer@dabbelt.com>, Jason Wang <jasowang@redhat.com>, Michael Rolnik <mrolnik@gmail.com>, Sarah Harris <S.E.Harris@kent.ac.uk>, Alistair Francis <Alistair.Francis@wdc.com>, Paolo Bonzini <pbonzini@redhat.com>, Max Reitz <mreitz@redhat.com>, Stefan Weil <sw@weilnetz.de>, Laurent Vivier <lvivier@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, "Philippe Mathieu-Daudé" <philmd@redhat.com>, Andrzej Zaborowski <balrogg@gmail.com>, Paul Durrant <paul@xen.org>, Kevin Wolf <kwolf@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Raphael Norwitz <raphael.norwitz@nutanix.com>, Dmitry Fleytman <dmitry.fleytman@gmail.com>, Peter Maydell <peter.maydell@linaro.org>, Yuval Shaia <yuval.shaia.ml@gmail.com>, Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>, Huacai Chen <chenhc@lemote.com>, Stefan Hajnoczi <stefanha@redhat.com>, Eric Blake <eblake@redhat.com>, Eduardo Habkost <ehabkost@redhat.com>
[PATCH 138/150] docs: automatically track manual dependencies
Posted by Paolo Bonzini 5 years, 5 months ago
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 docs/conf.py           |  2 +-
 docs/meson.build       | 21 ++++++++++-------
 docs/sphinx/depfile.py | 51 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 9 deletions(-)
 create mode 100644 docs/sphinx/depfile.py

diff --git a/docs/conf.py b/docs/conf.py
index d6e173ef77..0dbd90dc11 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -67,7 +67,7 @@ needs_sphinx = '1.6'
 # Add any Sphinx extension module names here, as strings. They can be
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
 # ones.
-extensions = ['kerneldoc', 'qmp_lexer', 'hxtool']
+extensions = ['kerneldoc', 'qmp_lexer', 'hxtool', 'depfile']
 
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ['_templates']
diff --git a/docs/meson.build b/docs/meson.build
index 20fc92e2fe..08c9139fbe 100644
--- a/docs/meson.build
+++ b/docs/meson.build
@@ -34,16 +34,21 @@ if build_docs
   sphinxmans = []
   foreach manual : manuals
     private_dir = meson.current_build_dir() / (manual + '.p')
+    output_dir = meson.current_build_dir() / manual
     input_dir = meson.current_source_dir() / manual
-    sphinxdocs += custom_target(manual + ' manual',
-                build_always_stale: true,
+
+    this_manual = custom_target(manual + ' manual',
                 build_by_default: build_docs,
-                output: manual,
-                command: [SPHINX_ARGS, '-b', 'html', '-d', private_dir,
-                          input_dir, meson.current_build_dir() / manual])
+                output: [manual + '.stamp', manual],
+                input: [files('conf.py'), files(manual / 'conf.py')],
+                depfile: manual + '.d',
+                command: [SPHINX_ARGS, '-Ddepfile=@DEPFILE@',
+                          '-Ddepfile_stamp=@OUTPUT0@',
+                          '-b', 'html', '-d', private_dir,
+                          input_dir, output_dir])
+    sphinxdocs += this_manual
     if build_docs and manual != 'devel'
-      install_subdir(meson.current_build_dir() / manual,
-                     install_dir: config_host['qemu_docdir'])
+      install_subdir(output_dir, install_dir: config_host['qemu_docdir'])
     endif
 
     these_man_pages = []
@@ -54,9 +59,9 @@ if build_docs
     endforeach
     if these_man_pages.length() > 0
       sphinxmans += custom_target(manual + ' man pages',
-                         build_always_stale: true,
                          build_by_default: build_docs,
                          output: these_man_pages,
+                         input: this_manual,
                          install: build_docs,
                          install_dir: install_dirs,
                          command: [SPHINX_ARGS, '-b', 'man', '-d', private_dir,
diff --git a/docs/sphinx/depfile.py b/docs/sphinx/depfile.py
new file mode 100644
index 0000000000..277fdf0f56
--- /dev/null
+++ b/docs/sphinx/depfile.py
@@ -0,0 +1,51 @@
+# coding=utf-8
+#
+# QEMU depfile generation extension
+#
+# Copyright (c) 2020 Red Hat, Inc.
+#
+# This work is licensed under the terms of the GNU GPLv2 or later.
+# See the COPYING file in the top-level directory.
+
+"""depfile is a Sphinx extension that writes a dependency file for
+   an external build system"""
+
+import os
+import sphinx
+
+__version__ = '1.0'
+
+def get_infiles(env):
+    for x in env.found_docs:
+        yield env.doc2path(x)
+        yield from ((os.path.join(env.srcdir, dep)
+                    for dep in env.dependencies[x]))
+
+def write_depfile(app, env):
+    if not env.config.depfile:
+        return
+
+    # Using a directory as the output file does not work great because
+    # its timestamp does not necessarily change when the contents change.
+    # So create a timestamp file.
+    if env.config.depfile_stamp:
+        with open(env.config.depfile_stamp, 'w') as f:
+            pass
+
+    with open(env.config.depfile, 'w') as f:
+        print((env.config.depfile_stamp or app.outdir) + ": \\", file=f)
+        print(*get_infiles(env), file=f)
+        for x in get_infiles(env):
+            print(x + ":", file=f)
+
+
+def setup(app):
+    app.add_config_value('depfile', None, 'env')
+    app.add_config_value('depfile_stamp', None, 'env')
+    app.connect('env-updated', write_depfile)
+
+    return dict(
+        version = __version__,
+        parallel_read_safe = True,
+        parallel_write_safe = True
+    )
-- 
2.26.2