[PATCH 135/147] meson: sphinx-build

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

diff --git a/Makefile b/Makefile
index 2297712..b0207a9 100644
--- a/Makefile
+++ b/Makefile
@@ -119,36 +119,9 @@ $(call set-vpath, $(SRC_PATH))
 
 LIBS+=-lz $(LIBS_TOOLS)
 
-# Sphinx does not allow building manuals into the same directory as
-# the source files, so if we're doing an in-tree QEMU build we must
-# build the manuals into a subdirectory (and then install them from
-# there for 'make install'). For an out-of-tree build we can just
-# use the docs/ subdirectory in the build tree as normal.
-ifeq ($(realpath $(SRC_PATH)),$(realpath .))
-MANUAL_BUILDDIR := docs/built
-else
-MANUAL_BUILDDIR := docs
-endif
-
 ifdef BUILD_DOCS
-DOCS+=$(MANUAL_BUILDDIR)/system/qemu.1
-DOCS+=$(MANUAL_BUILDDIR)/tools/qemu-img.1
-DOCS+=$(MANUAL_BUILDDIR)/tools/qemu-nbd.8
-DOCS+=$(MANUAL_BUILDDIR)/interop/qemu-ga.8
-ifeq ($(CONFIG_LINUX)$(CONFIG_SECCOMP)$(CONFIG_LIBCAP_NG),yyy)
-DOCS+=$(MANUAL_BUILDDIR)/tools/virtiofsd.1
-endif
-DOCS+=$(MANUAL_BUILDDIR)/system/qemu-block-drivers.7
 DOCS+=docs/interop/qemu-qmp-ref.html docs/interop/qemu-qmp-ref.txt docs/interop/qemu-qmp-ref.7
 DOCS+=docs/interop/qemu-ga-ref.html docs/interop/qemu-ga-ref.txt docs/interop/qemu-ga-ref.7
-DOCS+=$(MANUAL_BUILDDIR)/system/qemu-cpu-models.7
-DOCS+=$(MANUAL_BUILDDIR)/index.html
-ifdef CONFIG_VIRTFS
-DOCS+=$(MANUAL_BUILDDIR)/tools/virtfs-proxy-helper.1
-endif
-ifdef CONFIG_TRACE_SYSTEMTAP
-DOCS+=$(MANUAL_BUILDDIR)/tools/qemu-trace-stap.1
-endif
 else
 DOCS=
 endif
@@ -231,11 +204,6 @@ dist: qemu-$(VERSION).tar.bz2
 qemu-%.tar.bz2:
 	$(SRC_PATH)/scripts/make-release "$(SRC_PATH)" "$(patsubst qemu-%.tar.bz2,%,$@)"
 
-define clean-manual =
-rm -rf $(MANUAL_BUILDDIR)/$1/_static
-rm -f $(MANUAL_BUILDDIR)/$1/objects.inv $(MANUAL_BUILDDIR)/$1/searchindex.js $(MANUAL_BUILDDIR)/$1/*.html
-endef
-
 distclean: clean
 	rm -f config-host.mak config-host.h* $(DOCS)
 	rm -f tests/tcg/config-*.mak
@@ -251,13 +219,6 @@ distclean: clean
 	rm -f docs/interop/qemu-qmp-ref.txt docs/interop/qemu-ga-ref.txt
 	rm -f docs/interop/qemu-qmp-ref.pdf docs/interop/qemu-ga-ref.pdf
 	rm -f docs/interop/qemu-qmp-ref.html docs/interop/qemu-ga-ref.html
-	rm -rf .doctrees
-	$(call clean-manual,devel)
-	$(call clean-manual,interop)
-	$(call clean-manual,specs)
-	$(call clean-manual,system)
-	$(call clean-manual,tools)
-	$(call clean-manual,user)
 	rm -Rf .sdk
 
 KEYMAPS=da     en-gb  et  fr     fr-ch  is  lt  no  pt-br  sv \
@@ -291,28 +252,8 @@ else
 BLOBS=
 endif
 
-# Note that we manually filter-out the non-Sphinx documentation which
-# is currently built into the docs/interop directory in the build tree,
-# and also any sphinx-built manpages.
-define install-manual =
-for d in $$(cd $(MANUAL_BUILDDIR) && find $1 -type d); do $(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)/$$d"; done
-for f in $$(cd $(MANUAL_BUILDDIR) && find $1 -type f -a '!' '(' -name '*.[0-9]' -o -name 'qemu-*-qapi.*' -o -name 'qemu-*-ref.*' ')' ); do $(INSTALL_DATA) "$(MANUAL_BUILDDIR)/$$f" "$(DESTDIR)$(qemu_docdir)/$$f"; done
-endef
-
-# Note that we deliberately do not install the "devel" manual: it is
-# for QEMU developers, and not interesting to our users.
-.PHONY: install-sphinxdocs
-install-sphinxdocs: sphinxdocs
-	$(call install-manual,interop)
-	$(call install-manual,specs)
-	$(call install-manual,system)
-	$(call install-manual,tools)
-	$(call install-manual,user)
-
-install-doc: $(DOCS) install-sphinxdocs
+install-doc: $(DOCS)
 	$(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)"
-	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/index.html "$(DESTDIR)$(qemu_docdir)"
-	$(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)/interop"
 	$(INSTALL_DATA) docs/interop/qemu-qmp-ref.html "$(DESTDIR)$(qemu_docdir)/interop"
 	$(INSTALL_DATA) docs/interop/qemu-qmp-ref.txt "$(DESTDIR)$(qemu_docdir)/interop"
 ifdef CONFIG_POSIX
@@ -320,19 +261,7 @@ ifdef CONFIG_POSIX
 	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/system/qemu.1 "$(DESTDIR)$(mandir)/man1"
 	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man7"
 	$(INSTALL_DATA) docs/interop/qemu-qmp-ref.7 "$(DESTDIR)$(mandir)/man7"
-	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/system/qemu-block-drivers.7 "$(DESTDIR)$(mandir)/man7"
-	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/system/qemu-cpu-models.7 "$(DESTDIR)$(mandir)/man7"
-ifeq ($(CONFIG_TOOLS),y)
-	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/tools/qemu-img.1 "$(DESTDIR)$(mandir)/man1"
-	$(INSTALL_DIR) "$(DESTDIR)$(mandir)/man8"
-	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/tools/qemu-nbd.8 "$(DESTDIR)$(mandir)/man8"
-endif
-ifdef CONFIG_TRACE_SYSTEMTAP
-	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/tools/qemu-trace-stap.1 "$(DESTDIR)$(mandir)/man1"
-endif
 ifeq ($(CONFIG_GUEST_AGENT),y)
-	$(INSTALL_DATA) $(MANUAL_BUILDDIR)/interop/qemu-ga.8 "$(DESTDIR)$(mandir)/man8"
-	$(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)/interop"
 	$(INSTALL_DATA) docs/interop/qemu-ga-ref.html "$(DESTDIR)$(qemu_docdir)/interop"
 	$(INSTALL_DATA) docs/interop/qemu-ga-ref.txt "$(DESTDIR)$(qemu_docdir)/interop"
 	$(INSTALL_DATA) docs/interop/qemu-ga-ref.7 "$(DESTDIR)$(mandir)/man7"
@@ -419,69 +348,6 @@ docs/version.texi: $(SRC_PATH)/VERSION config-host.mak
 %.pdf: %.texi docs/version.texi
 	$(call quiet-command,texi2pdf $(TEXI2PDFFLAGS) $< -o $@,"GEN","$@")
 
-# Sphinx builds all its documentation at once in one invocation
-# and handles "don't rebuild things unless necessary" itself.
-# The '.doctrees' files are cached information to speed this up.
-.PHONY: sphinxdocs
-sphinxdocs: $(MANUAL_BUILDDIR)/devel/index.html \
-            $(MANUAL_BUILDDIR)/interop/index.html \
-            $(MANUAL_BUILDDIR)/specs/index.html \
-            $(MANUAL_BUILDDIR)/system/index.html \
-            $(MANUAL_BUILDDIR)/tools/index.html \
-            $(MANUAL_BUILDDIR)/user/index.html
-
-# Canned command to build a single manual
-# Arguments: $1 = manual name, $2 = Sphinx builder ('html' or 'man')
-# Note the use of different doctree for each (manual, builder) tuple;
-# this works around Sphinx not handling parallel invocation on
-# a single doctree: https://github.com/sphinx-doc/sphinx/issues/2946
-build-manual = $(call quiet-command,CONFDIR="$(qemu_confdir)" $(SPHINX_BUILD) $(if $(V),,-q) $(SPHINX_WERROR) -b $2 -D version=$(VERSION) -D release="$(FULL_VERSION)" -d .doctrees/$1-$2 $(SRC_PATH)/docs/$1 $(MANUAL_BUILDDIR)/$1 ,"SPHINX","$(MANUAL_BUILDDIR)/$1")
-# We assume all RST files in the manual's directory are used in it
-manual-deps = $(wildcard $(SRC_PATH)/docs/$1/*.rst $(SRC_PATH)/docs/$1/*/*.rst) \
-              $(SRC_PATH)/docs/defs.rst.inc \
-              $(SRC_PATH)/docs/$1/conf.py $(SRC_PATH)/docs/conf.py \
-              $(SRC_PATH)/docs/sphinx/*.py
-# Macro to write out the rule and dependencies for building manpages
-# Usage: $(call define-manpage-rule,manualname,manpage1 manpage2...[,extradeps])
-# 'extradeps' is optional, and specifies extra files (eg .hx files) that
-# the manual page depends on.
-define define-manpage-rule
-$(call atomic,$(foreach manpage,$2,$(MANUAL_BUILDDIR)/$1/$(manpage)),$(call manual-deps,$1) $3)
-	$(call build-manual,$1,man)
-endef
-
-$(MANUAL_BUILDDIR)/devel/index.html: $(call manual-deps,devel)
-	$(call build-manual,devel,html)
-
-$(MANUAL_BUILDDIR)/interop/index.html: $(call manual-deps,interop)
-	$(call build-manual,interop,html)
-
-$(MANUAL_BUILDDIR)/specs/index.html: $(call manual-deps,specs)
-	$(call build-manual,specs,html)
-
-$(MANUAL_BUILDDIR)/system/index.html: $(call manual-deps,system) $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/qemu-options.hx
-	$(call build-manual,system,html)
-
-$(MANUAL_BUILDDIR)/tools/index.html: $(call manual-deps,tools) $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/docs/qemu-option-trace.rst.inc
-	$(call build-manual,tools,html)
-
-$(MANUAL_BUILDDIR)/user/index.html: $(call manual-deps,user)
-	$(call build-manual,user,html)
-
-$(call define-manpage-rule,interop,qemu-ga.8)
-
-$(call define-manpage-rule,system,qemu.1 qemu-block-drivers.7 qemu-cpu-models.7)
-
-$(call define-manpage-rule,tools,\
-       qemu-img.1 qemu-nbd.8 qemu-trace-stap.1\
-       virtiofsd.1 virtfs-proxy-helper.1,\
-       $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/docs/qemu-option-trace.rst.inc)
-
-$(MANUAL_BUILDDIR)/index.html: $(SRC_PATH)/docs/index.html.in qemu-version.h
-	@mkdir -p "$(MANUAL_BUILDDIR)"
-	$(call quiet-command, sed "s|@@VERSION@@|${VERSION}|g" $< >$@, \
-             "GEN","$@")
-
 docs/interop/qemu-qmp-qapi.texi: qapi/qapi-doc.texi
 	@cp -p $< $@
 
@@ -504,6 +370,12 @@ docs/interop/qemu-qmp-ref.dvi docs/interop/qemu-qmp-ref.html \
 	docs/interop/qemu-qmp-ref.texi docs/interop/qemu-qmp-qapi.texi
 
 $(filter %.1 %.7 %.8,$(DOCS)): scripts/texi2pod.pl
+	$(call quiet-command, \
+	  perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $(TEXI2PODFLAGS) $< $@.pod && \
+	  $(POD2MAN) --section=$(subst .,,$(suffix $@)) --center=" " --release=" " $@.pod > $@, \
+	  "GEN","$@")
+
+man: $(filter %.1 %.7 %.8,$(DOCS))
 
 ifdef CONFIG_WIN32
 
diff --git a/configure b/configure
index 21b9ed2..7e7b4d8 100755
--- a/configure
+++ b/configure
@@ -7768,7 +7768,6 @@ echo "INSTALL_PROG=$install -c -m 0755" >> $config_host_mak
 echo "INSTALL_LIB=$install -c -m 0644" >> $config_host_mak
 echo "PYTHON=$python" >> $config_host_mak
 echo "SPHINX_BUILD=$sphinx_build" >> $config_host_mak
-echo "SPHINX_WERROR=$sphinx_werror" >> $config_host_mak
 echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
 echo "MESON=$meson" >> $config_host_mak
 echo "CC=$cc" >> $config_host_mak
diff --git a/docs/index.html.in b/docs/index.html.in
index 6736fa4..ca28047 100644
--- a/docs/index.html.in
+++ b/docs/index.html.in
@@ -2,10 +2,10 @@
 <html lang="en">
     <head>
         <meta charset="UTF-8">
-        <title>QEMU @@VERSION@@ Documentation</title>
+        <title>QEMU @VERSION@ Documentation</title>
     </head>
     <body>
-        <h1>QEMU @@VERSION@@ Documentation</h1>
+        <h1>QEMU @VERSION@ Documentation</h1>
         <ul>
             <li><a href="system/index.html">System Emulation User's Guide</a></li>
             <li><a href="user/index.html">User Mode Emulation User's Guide</a></li>
diff --git a/docs/meson.build b/docs/meson.build
new file mode 100644
index 0000000..20fc92e
--- /dev/null
+++ b/docs/meson.build
@@ -0,0 +1,68 @@
+SPHINX_ARGS = [config_host['SPHINX_BUILD'],
+               '-Dversion=' + meson.project_version(),
+               '-Drelease=' + config_host['PKGVERSION']]
+
+if get_option('werror')
+  SPHINX_ARGS += [ '-W' ]
+endif
+
+if build_docs
+  configure_file(output: 'index.html',
+                 input: files('index.html.in'),
+                 configuration: {'VERSION': meson.project_version()},
+                 install_dir: config_host['qemu_docdir'])
+  manuals = [ 'devel', 'interop', 'tools', 'specs', 'system', 'user' ]
+  man_pages = {
+    'interop' : {
+        'qemu-ga.8': (have_tools ? 'man8' : ''),
+    },
+    'tools': {
+        'qemu-img.1': (have_tools ? 'man1' : ''),
+        'qemu-nbd.8': (have_tools ? 'man8' : ''),
+        'qemu-trace-stap.1': (config_host.has_key('CONFIG_TRACE_SYSTEMTAP') ? 'man1' : ''),
+        'virtfs-proxy-helper.1': (have_virtfs_proxy_helper ? 'man1' : ''),
+        'virtiofsd.1': (have_virtiofsd ? 'man1' : ''),
+    },
+    'system': {
+        'qemu.1': 'man1',
+        'qemu-block-drivers.7': 'man7',
+        'qemu-cpu-models.7': 'man7'
+    },
+  }
+
+  sphinxdocs = []
+  sphinxmans = []
+  foreach manual : manuals
+    private_dir = meson.current_build_dir() / (manual + '.p')
+    input_dir = meson.current_source_dir() / manual
+    sphinxdocs += custom_target(manual + ' manual',
+                build_always_stale: true,
+                build_by_default: build_docs,
+                output: manual,
+                command: [SPHINX_ARGS, '-b', 'html', '-d', private_dir,
+                          input_dir, meson.current_build_dir() / manual])
+    if build_docs and manual != 'devel'
+      install_subdir(meson.current_build_dir() / manual,
+                     install_dir: config_host['qemu_docdir'])
+    endif
+
+    these_man_pages = []
+    install_dirs = []
+    foreach page, section : man_pages.get(manual, {})
+      these_man_pages += page
+      install_dirs += section == '' ? false : get_option('mandir') / section
+    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,
+                         install: build_docs,
+                         install_dir: install_dirs,
+                         command: [SPHINX_ARGS, '-b', 'man', '-d', private_dir,
+                                   input_dir, meson.current_build_dir()])
+    endif
+  endforeach
+  alias_target('sphinxdocs', sphinxdocs)
+  alias_target('man', sphinxmans)
+endif
diff --git a/meson.build b/meson.build
index c3ef9b6..903b860 100644
--- a/meson.build
+++ b/meson.build
@@ -11,6 +11,7 @@ cc = meson.get_compiler('c')
 config_host = keyval.load(meson.current_build_dir() / 'config-host.mak')
 config_all_disas = keyval.load(meson.current_build_dir() / 'config-all-disas.mak')
 enable_modules = 'CONFIG_MODULES' in config_host
+build_docs = 'BUILD_DOCS' in config_host
 
 add_project_arguments(config_host['QEMU_CFLAGS'].split(),
                       language: ['c', 'objc'])
@@ -1039,6 +1040,7 @@ endif
 subdir('tools')
 subdir('pc-bios')
 subdir('tests')
+subdir('docs')
 
 summary_info = {}
 summary_info += {'Install prefix':    config_host['prefix']}
diff --git a/rules.mak b/rules.mak
index 6d89001..6cab0b9 100644
--- a/rules.mak
+++ b/rules.mak
@@ -375,53 +375,5 @@ define unnest-vars
         $(eval $v := $(filter-out %/,$($v))))
 endef
 
-TEXI2MAN = $(call quiet-command, \
-	perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $(TEXI2PODFLAGS) $< $@.pod && \
-	$(POD2MAN) --section=$(subst .,,$(suffix $@)) --center=" " --release=" " $@.pod > $@, \
-	"GEN","$@")
-
-%.1:
-	$(call TEXI2MAN)
-%.7:
-	$(call TEXI2MAN)
-%.8:
-	$(call TEXI2MAN)
-
-# Support for building multiple output files by atomically executing
-# a single rule which depends on several input files (so the rule
-# will be executed exactly once, not once per output file, and
-# not multiple times in parallel.) For more explanation see:
-# https://www.cmcrossroads.com/article/atomic-rules-gnu-make
-
-# Given a space-separated list of filenames, create the name of
-# a 'sentinel' file to use to indicate that they have been built.
-# We use fixed text on the end to avoid accidentally triggering
-# automatic pattern rules, and . on the start to make the file
-# not show up in ls output.
-sentinel = .$(subst $(SPACE),_,$(subst /,_,$1)).sentinel.
-
-# Define an atomic rule that builds multiple outputs from multiple inputs.
-# To use:
-#    $(call atomic,out1 out2 ...,in1 in2 ...)
-#    <TAB>rule to do the operation
-#
-# Make 4.3 will have native support for this, and you would be able
-# to instead write:
-#    out1 out2 ... &: in1 in2 ...
-#    <TAB>rule to do the operation
-#
-# The way this works is that it creates a make rule
-# "out1 out2 ... : sentinel-file ; @:" which says that the sentinel
-# depends on the dependencies, and the rule to do that is "do nothing".
-# Then we have a rule
-# "sentinel-file : in1 in2 ..."
-# whose commands start with "touch sentinel-file" and then continue
-# with the rule text provided by the user of this 'atomic' function.
-# The foreach... is there to delete the sentinel file if any of the
-# output files don't exist, so that we correctly rebuild in that situation.
-atomic = $(eval $1: $(call sentinel,$1) ; @:) \
-         $(call sentinel,$1) : $2 ; @touch $$@ \
-         $(foreach t,$1,$(if $(wildcard $t),,$(shell rm -f $(call sentinel,$1))))
-
 print-%:
 	@echo '$*=$($*)'
-- 
1.8.3.1



Re: [PATCH 135/147] meson: sphinx-build
Posted by Peter Maydell 5 years, 4 months ago
On Mon, 10 Aug 2020 at 19:16, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

> diff --git a/configure b/configure
> index 21b9ed2..7e7b4d8 100755
> --- a/configure
> +++ b/configure
> @@ -7768,7 +7768,6 @@ echo "INSTALL_PROG=$install -c -m 0755" >> $config_host_mak
>  echo "INSTALL_LIB=$install -c -m 0644" >> $config_host_mak
>  echo "PYTHON=$python" >> $config_host_mak
>  echo "SPHINX_BUILD=$sphinx_build" >> $config_host_mak
> -echo "SPHINX_WERROR=$sphinx_werror" >> $config_host_mak

Shouldn't we also be deleting the code in configure that
sets $sphinx_werror if we're no longer using it ?

> +    these_man_pages = []
> +    install_dirs = []
> +    foreach page, section : man_pages.get(manual, {})
> +      these_man_pages += page
> +      install_dirs += section == '' ? false : get_option('mandir') / section
> +    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,
> +                         install: build_docs,
> +                         install_dir: install_dirs,
> +                         command: [SPHINX_ARGS, '-b', 'man', '-d', private_dir,
> +                                   input_dir, meson.current_build_dir()])
> +    endif
> +  endforeach
> +  alias_target('sphinxdocs', sphinxdocs)
> +  alias_target('man', sphinxmans)

Does "build_always_stale: true" do what I guess it does from the
name? Does this mean we're discarding the makefile's approach of
only running sphinx if it's necessary in favour of always running
half a dozen sphinx invocations every build ?

thanks
-- PMM

Re: [PATCH 135/147] meson: sphinx-build
Posted by Paolo Bonzini 5 years, 4 months ago
On 10/08/20 20:33, Peter Maydell wrote:
> On Mon, 10 Aug 2020 at 19:16, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> 
>> diff --git a/configure b/configure
>> index 21b9ed2..7e7b4d8 100755
>> --- a/configure
>> +++ b/configure
>> @@ -7768,7 +7768,6 @@ echo "INSTALL_PROG=$install -c -m 0755" >> $config_host_mak
>>  echo "INSTALL_LIB=$install -c -m 0644" >> $config_host_mak
>>  echo "PYTHON=$python" >> $config_host_mak
>>  echo "SPHINX_BUILD=$sphinx_build" >> $config_host_mak
>> -echo "SPHINX_WERROR=$sphinx_werror" >> $config_host_mak
> 
> Shouldn't we also be deleting the code in configure that
> sets $sphinx_werror if we're no longer using it ?

Yes.

>> +    these_man_pages = []
>> +    install_dirs = []
>> +    foreach page, section : man_pages.get(manual, {})
>> +      these_man_pages += page
>> +      install_dirs += section == '' ? false : get_option('mandir') / section
>> +    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,
>> +                         install: build_docs,
>> +                         install_dir: install_dirs,
>> +                         command: [SPHINX_ARGS, '-b', 'man', '-d', private_dir,
>> +                                   input_dir, meson.current_build_dir()])
>> +    endif
>> +  endforeach
>> +  alias_target('sphinxdocs', sphinxdocs)
>> +  alias_target('man', sphinxmans)
> 
> Does "build_always_stale: true" do what I guess it does from the
> name? Does this mean we're discarding the makefile's approach of
> only running sphinx if it's necessary in favour of always running
> half a dozen sphinx invocations every build ?

Yes, because the Makefile's approach is not maintainable in my opinion;
*.rst.inc files were already not included in the Makefile.  I'll look
into using a Sphinx extension to produce a dependency file.

Paolo


Paolo


Re: [PATCH 135/147] meson: sphinx-build
Posted by Peter Maydell 5 years, 4 months ago
On Mon, 10 Aug 2020 at 20:06, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 10/08/20 20:33, Peter Maydell wrote:
> > Does "build_always_stale: true" do what I guess it does from the
> > name? Does this mean we're discarding the makefile's approach of
> > only running sphinx if it's necessary in favour of always running
> > half a dozen sphinx invocations every build ?
>
> Yes, because the Makefile's approach is not maintainable in my opinion;
> *.rst.inc files were already not included in the Makefile.  I'll look
> into using a Sphinx extension to produce a dependency file.

Yeah, agreed that the makefile approach isn't great. (It lists
some .rst.inc files but we added more without updating the
dependencies, I think.)

If Sphinx can be persuaded to output a dependency file that
would certainly be the nicest approach; I hadn't thought
of trying that.

It would be nice to note in the commit messages where the
conversion has made this kind of "we're going to do it a
different way" design decision rather than just being
a translation of the makefile logic into Meson.

thanks
-- PMM

Re: [PATCH 135/147] meson: sphinx-build
Posted by Paolo Bonzini 5 years, 4 months ago
On 10/08/20 21:21, Peter Maydell wrote:
>> Yes, because the Makefile's approach is not maintainable in my opinion;
>> *.rst.inc files were already not included in the Makefile.  I'll look
>> into using a Sphinx extension to produce a dependency file.
>
> Yeah, agreed that the makefile approach isn't great. (It lists
> some .rst.inc files but we added more without updating the
> dependencies, I think.)
> 
> If Sphinx can be persuaded to output a dependency file that
> would certainly be the nicest approach; I hadn't thought
> of trying that.

It should be possible and probably not too hard once I figure out how
Sphinx events work.  It's a fair request since build_always_stale is
inferior and Meson requires no particular magic to include the depfile.
 Maybe that will win you over. :)

I can also leave out sphinx from the initial conversion.

> It would be nice to note in the commit messages where the
> conversion has made this kind of "we're going to do it a
> different way" design decision rather than just being
> a translation of the makefile logic into Meson.

Yes, I'll do that for the final version (to be posted Friday or next
Monday).

Thanks for running these initial test, it looks encouraging.

Paolo


Re: [PATCH 135/147] meson: sphinx-build
Posted by Peter Maydell 5 years, 4 months ago
On Mon, 10 Aug 2020 at 20:31, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 10/08/20 21:21, Peter Maydell wrote:
> >> Yes, because the Makefile's approach is not maintainable in my opinion;
> >> *.rst.inc files were already not included in the Makefile.  I'll look
> >> into using a Sphinx extension to produce a dependency file.
> >
> > Yeah, agreed that the makefile approach isn't great. (It lists
> > some .rst.inc files but we added more without updating the
> > dependencies, I think.)
> >
> > If Sphinx can be persuaded to output a dependency file that
> > would certainly be the nicest approach; I hadn't thought
> > of trying that.
>
> It should be possible and probably not too hard once I figure out how
> Sphinx events work.  It's a fair request since build_always_stale is
> inferior and Meson requires no particular magic to include the depfile.
>  Maybe that will win you over. :)
>
> I can also leave out sphinx from the initial conversion.

If we have a working-but-build-always conversion for Sphinx
I'd be happy to take that and then upgrade it to processing
the dependencies properly later.

(The thing I'm not really looking forward to is updating
the qapi-doc-to-rst patchset to Meson...)

thanks
-- PMM

Re: [PATCH 135/147] meson: sphinx-build
Posted by Paolo Bonzini 5 years, 4 months ago
On 10/08/20 21:36, Peter Maydell wrote:
>> It should be possible and probably not too hard once I figure out how
>> Sphinx events work.  It's a fair request since build_always_stale is
>> inferior and Meson requires no particular magic to include the depfile.
>>  Maybe that will win you over. :)
>>
>> I can also leave out sphinx from the initial conversion.
> If we have a working-but-build-always conversion for Sphinx
> I'd be happy to take that and then upgrade it to processing
> the dependencies properly later.
> 
> (The thing I'm not really looking forward to is updating
> the qapi-doc-to-rst patchset to Meson...)

Since it's all handled internally by sphinx, I think you only need to 
add the man pages to the dictionary, and get rid of the corresponding 
Texinfo outputs in qapi/meson.build and qga/meson.build?

In other words, it should be just this:

diff --git a/qapi/meson.build b/qapi/meson.build
index de5b16f..315252f 100644
--- a/qapi/meson.build
+++ b/qapi/meson.build
@@ -96,7 +96,7 @@ foreach module : qapi_all_modules
 endforeach
 
 qapi_files = custom_target('shared QAPI source files',
-  output: qapi_util_outputs + qapi_specific_outputs + qapi_nonmodule_outputs + ['qapi-doc.texi'],
+  output: qapi_util_outputs + qapi_specific_outputs + qapi_nonmodule_outputs,
   input: [ files('qapi-schema.json') ],
   command: [ qapi_gen, '-o', 'qapi', '-b', '@INPUT0@' ],
   depend_files: [ qapi_inputs, qapi_gen_depends ])
@@ -120,5 +120,3 @@ foreach output : qapi_specific_outputs + qapi_nonmodule_outputs
   specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: qapi_files[i])
   i = i + 1
 endforeach
-
-qapi_doc_texi = qapi_files[i]
diff --git a/qga/meson.build b/qga/meson.build
index 6fdddd6..741b683 100644
--- a/qga/meson.build
+++ b/qga/meson.build
@@ -16,7 +16,7 @@ qga_qapi_outputs = [
 ]
 
 qga_qapi_files = custom_target('QGA QAPI files',
-                               output: qga_qapi_outputs + ['qga-qapi-doc.texi'],
+                               output: qga_qapi_outputs,
                                input: 'qapi-schema.json',
                                command: [ qapi_gen, '-o', 'qga', '-p', 'qga-', '@INPUT0@' ],
                                depend_files: qapi_gen_depends)
@@ -27,7 +27,6 @@ foreach output: qga_qapi_outputs
   qga_ss.add(qga_qapi_files[i])
   i = i + 1
 endforeach
-qga_qapi_doc_texi = qga_qapi_files[i]
 
 qga_ss.add(files(
   'commands.c',


Paolo


Re: [PATCH 135/147] meson: sphinx-build
Posted by Peter Maydell 5 years, 4 months ago
On Mon, 10 Aug 2020 at 20:46, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 10/08/20 21:36, Peter Maydell wrote:
> >> It should be possible and probably not too hard once I figure out how
> >> Sphinx events work.  It's a fair request since build_always_stale is
> >> inferior and Meson requires no particular magic to include the depfile.
> >>  Maybe that will win you over. :)
> >>
> >> I can also leave out sphinx from the initial conversion.
> > If we have a working-but-build-always conversion for Sphinx
> > I'd be happy to take that and then upgrade it to processing
> > the dependencies properly later.
> >
> > (The thing I'm not really looking forward to is updating
> > the qapi-doc-to-rst patchset to Meson...)
>
> Since it's all handled internally by sphinx, I think you only need to
> add the man pages to the dictionary, and get rid of the corresponding
> Texinfo outputs in qapi/meson.build and qga/meson.build?

The patchset has a fair amount of change to the makefiles:
 Makefile                                   |  86 +---
 rules.mak                                  |  14 +-


> In other words, it should be just this:

...so if it's that simple that would be nice.

-- PMM

Re: [PATCH 135/147] meson: sphinx-build
Posted by Paolo Bonzini 5 years, 4 months ago
Il lun 10 ago 2020, 21:57 Peter Maydell <peter.maydell@linaro.org> ha
scritto:

> > Since it's all handled internally by sphinx, I think you only need to
> > add the man pages to the dictionary, and get rid of the corresponding
> > Texinfo outputs in qapi/meson.build and qga/meson.build?
>
> The patchset has a fair amount of change to the makefiles:
>  Makefile                                   |  86 +---
>  rules.mak                                  |  14 +-
>
>
> > In other words, it should be just this:
>
> ...so if it's that simple that would be nice.
>

Hopefully. Of course you would also have to delete the Texinfo rules in
meson.build but that's certainly more self explanatory then the qapi-gen.py
bit.

Paolo


> -- PMM
>
>
Re: [PATCH 135/147] meson: sphinx-build
Posted by Paolo Bonzini 5 years, 4 months ago
On 10/08/20 21:06, Paolo Bonzini wrote:
>>> diff --git a/configure b/configure
>>> index 21b9ed2..7e7b4d8 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -7768,7 +7768,6 @@ echo "INSTALL_PROG=$install -c -m 0755" >> $config_host_mak
>>>  echo "INSTALL_LIB=$install -c -m 0644" >> $config_host_mak
>>>  echo "PYTHON=$python" >> $config_host_mak
>>>  echo "SPHINX_BUILD=$sphinx_build" >> $config_host_mak
>>> -echo "SPHINX_WERROR=$sphinx_werror" >> $config_host_mak
>> Shouldn't we also be deleting the code in configure that
>> sets $sphinx_werror if we're no longer using it ?
> Yes.
> 

... It's still used by has_sphinx_build, actually.

Paolo