Subject: Add html-serve target to autotools and meson

From: "Tristan Partin" <[email-masked]>
Date: Thu, 07 Nov 2024 04:37:22 +0000

When working on documentation, I find it useful to spawn an HTTP server 
to serve docs for me to consume in a web browser. I went ahead and used 
Python's builtin http.server module, but it could also be a run target 
which just spawned `xdg-open builddir/doc/src/sgml/html/index.html`, 
though I would doubt Windows has xdg-open(1).

The one controversial part of this patch might be using "port" 0, which 
asks the kernel to assign an unused port. I'm not sure if that exists on 
Windows, or is even desireable. Should we have a build option for the 
port? What would a good default be?

-- 
Tristan Partin
Neon (https://neon.tech)
diff --git a/doc/src/sgml/Makefile b/doc/src/sgml/Makefile
index a04c532b53..6f629e02a7 100644
--- a/doc/src/sgml/Makefile
+++ b/doc/src/sgml/Makefile
@@ -130,6 +130,9 @@ html-stamp: stylesheet.xsl postgres-full.xml $(ALL_IMAGES)
 	$(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) $(XSLTPROC_HTML_FLAGS) $(wordlist 1,2,$^)
 	touch $@
 
+html-serve: html
+	python3 -m http.server --directory '$(top_builddir)/$(subdir)/html' 0
+
 # single-page HTML
 postgres.html: stylesheet-html-nochunk.xsl postgres-full.xml $(ALL_IMAGES)
 	$(XSLTPROC) $(XMLINCLUDE) $(XSLTPROCFLAGS) $(XSLTPROC_HTML_FLAGS) -o $@ $(wordlist 1,2,$^)
diff --git a/doc/src/sgml/meson.build b/doc/src/sgml/meson.build
index e418de83a7..fa598d8ab1 100644
--- a/doc/src/sgml/meson.build
+++ b/doc/src/sgml/meson.build
@@ -154,6 +154,19 @@ if docs_dep.found()
   alias_target('html', html)
   alias_target('install-html', install_doc_html)
 
+  run_target(
+    'html-serve',
+    command: [
+      python,
+      '-m',
+      'http.server',
+      '--directory',
+      meson.current_build_dir() / 'html',
+      '0',
+    ],
+    depends: html,
+  )
+
   # build and install multi-page html docs as part of docs target
   docs += html
   installdocs += install_doc_html