]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Fix dependencies for docs, using a Sphinx extension to generate a dep file, as sugges...
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 18 Feb 2025 13:20:16 +0000 (14:20 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 18 Feb 2025 14:35:48 +0000 (15:35 +0100)
Actually, the depfile (sphinx.d) is removed by ninja after generating
it as shown by a trace.  I do not know why, but touching an .rst
file has the correct behaviour. So I suspect it is an optimization.

docs/conf.py
docs/depfile.py [new file with mode: 0644]
meson.build
pdns/dnsdistdist/docs/conf.py
pdns/dnsdistdist/docs/depfile.py [new symlink]
pdns/dnsdistdist/meson.build
pdns/recursordist/docs/conf.py
pdns/recursordist/docs/depfile.py [new symlink]
pdns/recursordist/meson.build

index 2457532b83240de613793dadca9289065697966e..b8cbbc8bbbc22ad1bfa5142cab181a5454996592 100644 (file)
@@ -19,8 +19,8 @@
 #
 # import os
 import glob
-import sys
-# sys.path.insert(0, os.path.abspath('.'))
+import sys
+from pathlib import Path
 import guzzle_sphinx_theme
 import datetime
 
@@ -30,13 +30,15 @@ import datetime
 #
 # needs_sphinx = '1.0'
 
+sys.path.append(str(Path('.').resolve()))
+
 # Add any Sphinx extension module names here, as strings. They can be
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
 # ones.
 #extensions = []
 #extensions = ['redjack.sphinx.lua', 'sphinxcontrib.httpdomain', 'sphinxjsondomain']
 extensions = ['sphinxcontrib.openapi',
-              'sphinxcontrib.fulltoc', 'changelog']
+              'sphinxcontrib.fulltoc', 'changelog', 'depfile']
 
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ['_templates']
@@ -237,3 +239,6 @@ epub_copyright = copyright
 
 # A list of files that should not be packed into the epub file.
 epub_exclude_files = ['search.html']
+
+depfile = 'sphinx.d'
+depfile_stamp = 'sphinx.stamp'
diff --git a/docs/depfile.py b/docs/depfile.py
new file mode 100644 (file)
index 0000000..fda8ba8
--- /dev/null
@@ -0,0 +1,69 @@
+# 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
+import sys
+from pathlib import Path
+
+__version__ = '1.0'
+
+def get_infiles(env):
+    for x in env.found_docs:
+        yield str(env.doc2path(x))
+        yield from ((os.path.join(env.srcdir, dep)
+                    for dep in env.dependencies[x]))
+    for mod in sys.modules.values():
+        if hasattr(mod, '__file__'):
+            if mod.__file__:
+                yield mod.__file__
+    # this is perhaps going to include unused files:
+    for static_path in env.config.html_static_path + env.config.templates_path:
+        for path in Path(static_path).rglob('*'):
+            yield str(path)
+
+    # also include kdoc script
+    #yield str(env.config.kerneldoc_bin[1])
+
+
+def write_depfile(app, exception):
+    if exception:
+        return
+
+    env = 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:
+            print('depfile.py: Writing ' + env.config.depfile_stamp)
+
+    with open(env.config.depfile, 'w') as f:
+        print('depfile.py: Writing ' + env.config.depfile)
+        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('build-finished', write_depfile)
+
+    return dict(
+        version = __version__,
+        parallel_read_safe = True,
+        parallel_write_safe = True
+    )
index e4d946e8db357f988a79ec35ef190173ed6f75df..89560ba9613fcf44cebc6cc52d2412509e519bd2 100644 (file)
@@ -1125,9 +1125,6 @@ if get_option('unit-tests-backends')
 endif
 
 if python.found()
-  find_rst_files = run_command(['find', docs_dir, '-name', '*.rst'])
-  rst_files = find_rst_files.stdout().strip().split('\n')
-
   html_docs = custom_target(
     'html-docs',
     command: [
@@ -1140,9 +1137,9 @@ if python.found()
         '--source-directory', docs_dir,
         '--target-directory', '@BUILD_ROOT@' / 'html-docs',
     ],
-    output: 'html-docs',
+    output: 'sphinx.stamp',
     console: true,
-    depend_files: rst_files,
+    depfile: 'sphinx.d',
   )
 
   docs_tarball = custom_target(
@@ -1165,7 +1162,7 @@ if python.found()
     ],
     output: 'PowerDNS-Authoritative.pdf',
     console: true,
-    depend_files: rst_files,
+    depfile: 'sphinx.d',
   )
 
   run_target(
index 9708c85cd3bc55972050e8f4a9e5421249906f61..a137e14707d463ff5bc847a0da642de6367347cb 100644 (file)
@@ -20,6 +20,8 @@
 # import os
 # import sys
 # sys.path.insert(0, os.path.abspath('.'))
+import sys
+from pathlib import Path
 import datetime
 
 # -- General configuration ------------------------------------------------
@@ -28,11 +30,13 @@ import datetime
 #
 # needs_sphinx = '1.0'
 
+sys.path.append(str(Path('.').resolve()))
+
 # Add any Sphinx extension module names here, as strings. They can be
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
 # ones.
 extensions = ['redjack.sphinx.lua', 'sphinxcontrib.httpdomain', 'sphinxjsondomain',
-              'sphinxcontrib.fulltoc', 'changelog']
+              'sphinxcontrib.fulltoc', 'changelog', 'depfile']
 primary_domain = 'lua'
 
 # Add any paths that contain templates here, relative to this directory.
@@ -200,4 +204,5 @@ epub_copyright = copyright
 # A list of files that should not be packed into the epub file.
 epub_exclude_files = ['search.html']
 
-
+depfile = 'sphinx.d'
+depfile_stamp = 'sphinx.stamp'
diff --git a/pdns/dnsdistdist/docs/depfile.py b/pdns/dnsdistdist/docs/depfile.py
new file mode 120000 (symlink)
index 0000000..0decaf3
--- /dev/null
@@ -0,0 +1 @@
+../../../docs/depfile.py
\ No newline at end of file
index c13ef069d051d88d944f2b6a789500a0695335ac..e06cfc02a8cf6fbd76bf0c4ef68e763af009577b 100644 (file)
@@ -691,8 +691,6 @@ install_data(
 )
 
 if python.found()
-  find_rst_files = run_command(['find', docs_dir, '-name', '*.rst'])
-  rst_files = find_rst_files.stdout().strip().split('\n')
 
   html_docs = custom_target(
     'html-docs',
@@ -706,9 +704,9 @@ if python.found()
         '--source-directory', docs_dir,
         '--target-directory', '@BUILD_ROOT@' / 'html-docs',
     ],
-    output: 'html-docs',
+    output: 'sphinx.stamp',
     console: true,
-    depend_files: rst_files,
+    depfile: 'sphinx.d',
   )
 
   docs_tarball = custom_target(
@@ -731,7 +729,7 @@ if python.found()
     ],
     output: 'dnsdist.pdf',
     console: true,
-    depend_files: rst_files,
+    depfile: 'sphinx.d',
   )
 
   run_target(
index f07504db325383e74432af44235c5b3294f2fcb5..d0188e72f0d485979fec8a1aa79ee2b22437f173 100644 (file)
@@ -18,8 +18,8 @@
 # documentation root, use os.path.abspath to make it absolute, like shown here.
 #
 # import os
-import sys
-# sys.path.insert(0, os.path.abspath('.'))
+import sys
+from pathlib import Path
 import guzzle_sphinx_theme
 import datetime
 
@@ -29,13 +29,15 @@ import datetime
 #
 # needs_sphinx = '1.0'
 
+sys.path.append(str(Path('.').resolve()))
+
 # Add any Sphinx extension module names here, as strings. They can be
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
 # ones.
 #extensions = []
 #extensions = ['redjack.sphinx.lua', 'sphinxcontrib.httpdomain', 'sphinxjsondomain']
 extensions = ['redjack.sphinx.lua', 'sphinxcontrib.httpdomain', 'sphinxjsondomain',
-              'sphinxcontrib.fulltoc', 'changelog']
+              'sphinxcontrib.fulltoc', 'changelog', 'depfile']
 primary_domain = 'lua'
 
 # Add any paths that contain templates here, relative to this directory.
@@ -208,3 +210,6 @@ epub_copyright = copyright
 
 # A list of files that should not be packed into the epub file.
 epub_exclude_files = ['search.html']
+
+depfile = 'sphinx.d'
+depfile_stamp = 'sphinx.stamp'
diff --git a/pdns/recursordist/docs/depfile.py b/pdns/recursordist/docs/depfile.py
new file mode 120000 (symlink)
index 0000000..0decaf3
--- /dev/null
@@ -0,0 +1 @@
+../../../docs/depfile.py
\ No newline at end of file
index c6c4e7a6b5cfa26a1d4916aa4132126f17baa107..5d8a970d7b96f784fc93a5828cf3e277b7750f2d 100644 (file)
@@ -735,8 +735,6 @@ dep_conf_distfile = custom_target(
 )
 
 if python.found()
-  find_rst_files = run_command(['find', docs_dir, '-name', '*.rst'])
-  rst_files = find_rst_files.stdout().strip().split('\n')
 
   html_docs = custom_target(
     'html-docs',
@@ -750,9 +748,10 @@ if python.found()
         '--source-directory', docs_dir,
         '--target-directory', '@BUILD_ROOT@' / 'html-docs',
     ],
-    output: 'html-docs',
+    output: 'sphinx.stamp',
     console: true,
-    depend_files: rst_files,
+    depfile: 'sphinx.d',
+    depends: [ metricfiles, recrust ], # for generated .rst files
   )
 
   docs_tarball = custom_target(
@@ -775,7 +774,8 @@ if python.found()
     ],
     output: 'PowerDNS-Recursor.pdf',
     console: true,
-    depend_files: rst_files,
+    depfile: 'sphinx.d',
+    depends: [ metricfiles, recrust ], # for generated .rst files
   )
 
   run_target(