[master] 99400dfea Make vmodtool leave output files alone if unchanged. This prevents unecessary docs builds. However, we do need to touch the *if.c mtime, otherwise a doc-only change will cause vmodtool to run on every make afterwards.

Poul-Henning Kamp phk at FreeBSD.org
Wed Mar 29 08:59:08 UTC 2023


commit 99400dfeaccb5d6a39f548102febcefeb9c29ce7
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Mar 29 08:14:28 2023 +0000

    Make vmodtool leave output files alone if unchanged.
    This prevents unecessary docs builds.
    However, we do need to touch the *if.c mtime, otherwise a
    doc-only change will cause vmodtool to run on every make afterwards.
    
    Relevant to: #3901

diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py
index da7157766..8f102d2cd 100755
--- a/lib/libvcc/vmodtool.py
+++ b/lib/libvcc/vmodtool.py
@@ -76,8 +76,11 @@ $(libvmod_XXX_la_OBJECTS): PFX.h
 
 PFX.h vmod_XXX.rst vmod_XXX.man.rst: PFX.c
 
+# A doc-change will not update mtime on the .h and .c files, so a
+# touch(1) is necessary to signal that vmodtool was in fact run.
 PFX.c: $(vmodtool) $(srcdir)/VCC
 \t at PYTHON@ $(vmodtool) $(vmodtoolargs_XXX) $(srcdir)/VCC
+\ttouch PFX.c
 
 clean-local: clean-vmod-XXX
 
@@ -924,7 +927,15 @@ class vcc():
 
     def commit(self):
         for i in self.commit_files:
-            os.rename(i + ".tmp", i)
+            try:
+                before = open(i, "rb").read()
+            except:
+                before = None
+            after = open(i + ".tmp", "rb").read()
+            if before != after:
+                os.rename(i + ".tmp", i)
+            else:
+                os.remove(i + ".tmp")
 
     def parse(self):
         global inputline
diff --git a/vmod/automake_boilerplate_blob.am b/vmod/automake_boilerplate_blob.am
index c1934c9b6..c49d42a6f 100644
--- a/vmod/automake_boilerplate_blob.am
+++ b/vmod/automake_boilerplate_blob.am
@@ -32,8 +32,11 @@ $(libvmod_blob_la_OBJECTS): vcc_blob_if.h
 
 vcc_blob_if.h vmod_blob.rst vmod_blob.man.rst: vcc_blob_if.c
 
+# A doc-change will not update mtime on the .h and .c files, so a
+# touch(1) is necessary to signal that vmodtool was in fact run.
 vcc_blob_if.c: $(vmodtool) $(srcdir)/vmod_blob.vcc
 	@PYTHON@ $(vmodtool) $(vmodtoolargs_blob) $(srcdir)/vmod_blob.vcc
+	touch vcc_blob_if.c
 
 clean-local: clean-vmod-blob
 
diff --git a/vmod/automake_boilerplate_cookie.am b/vmod/automake_boilerplate_cookie.am
index 2ab718f63..fa3ccfb7f 100644
--- a/vmod/automake_boilerplate_cookie.am
+++ b/vmod/automake_boilerplate_cookie.am
@@ -25,8 +25,11 @@ $(libvmod_cookie_la_OBJECTS): vcc_cookie_if.h
 
 vcc_cookie_if.h vmod_cookie.rst vmod_cookie.man.rst: vcc_cookie_if.c
 
+# A doc-change will not update mtime on the .h and .c files, so a
+# touch(1) is necessary to signal that vmodtool was in fact run.
 vcc_cookie_if.c: $(vmodtool) $(srcdir)/vmod_cookie.vcc
 	@PYTHON@ $(vmodtool) $(vmodtoolargs_cookie) $(srcdir)/vmod_cookie.vcc
+	touch vcc_cookie_if.c
 
 clean-local: clean-vmod-cookie
 
diff --git a/vmod/automake_boilerplate_debug.am b/vmod/automake_boilerplate_debug.am
index d546d4587..e97ac77da 100644
--- a/vmod/automake_boilerplate_debug.am
+++ b/vmod/automake_boilerplate_debug.am
@@ -28,8 +28,11 @@ $(libvmod_debug_la_OBJECTS): vcc_debug_if.h
 
 vcc_debug_if.h vmod_debug.rst vmod_debug.man.rst: vcc_debug_if.c
 
+# A doc-change will not update mtime on the .h and .c files, so a
+# touch(1) is necessary to signal that vmodtool was in fact run.
 vcc_debug_if.c: $(vmodtool) $(srcdir)/vmod_debug.vcc
 	@PYTHON@ $(vmodtool) $(vmodtoolargs_debug) $(srcdir)/vmod_debug.vcc
+	touch vcc_debug_if.c
 
 clean-local: clean-vmod-debug
 
diff --git a/vmod/automake_boilerplate_directors.am b/vmod/automake_boilerplate_directors.am
index 157d06138..6cec72ead 100644
--- a/vmod/automake_boilerplate_directors.am
+++ b/vmod/automake_boilerplate_directors.am
@@ -35,8 +35,11 @@ $(libvmod_directors_la_OBJECTS): vcc_directors_if.h
 
 vcc_directors_if.h vmod_directors.rst vmod_directors.man.rst: vcc_directors_if.c
 
+# A doc-change will not update mtime on the .h and .c files, so a
+# touch(1) is necessary to signal that vmodtool was in fact run.
 vcc_directors_if.c: $(vmodtool) $(srcdir)/vmod_directors.vcc
 	@PYTHON@ $(vmodtool) $(vmodtoolargs_directors) $(srcdir)/vmod_directors.vcc
+	touch vcc_directors_if.c
 
 clean-local: clean-vmod-directors
 
diff --git a/vmod/automake_boilerplate_proxy.am b/vmod/automake_boilerplate_proxy.am
index 2fa58068d..24be960ea 100644
--- a/vmod/automake_boilerplate_proxy.am
+++ b/vmod/automake_boilerplate_proxy.am
@@ -25,8 +25,11 @@ $(libvmod_proxy_la_OBJECTS): vcc_proxy_if.h
 
 vcc_proxy_if.h vmod_proxy.rst vmod_proxy.man.rst: vcc_proxy_if.c
 
+# A doc-change will not update mtime on the .h and .c files, so a
+# touch(1) is necessary to signal that vmodtool was in fact run.
 vcc_proxy_if.c: $(vmodtool) $(srcdir)/vmod_proxy.vcc
 	@PYTHON@ $(vmodtool) $(vmodtoolargs_proxy) $(srcdir)/vmod_proxy.vcc
+	touch vcc_proxy_if.c
 
 clean-local: clean-vmod-proxy
 
diff --git a/vmod/automake_boilerplate_purge.am b/vmod/automake_boilerplate_purge.am
index 35b893abb..7d2186d11 100644
--- a/vmod/automake_boilerplate_purge.am
+++ b/vmod/automake_boilerplate_purge.am
@@ -25,8 +25,11 @@ $(libvmod_purge_la_OBJECTS): vcc_purge_if.h
 
 vcc_purge_if.h vmod_purge.rst vmod_purge.man.rst: vcc_purge_if.c
 
+# A doc-change will not update mtime on the .h and .c files, so a
+# touch(1) is necessary to signal that vmodtool was in fact run.
 vcc_purge_if.c: $(vmodtool) $(srcdir)/vmod_purge.vcc
 	@PYTHON@ $(vmodtool) $(vmodtoolargs_purge) $(srcdir)/vmod_purge.vcc
+	touch vcc_purge_if.c
 
 clean-local: clean-vmod-purge
 
diff --git a/vmod/automake_boilerplate_std.am b/vmod/automake_boilerplate_std.am
index 57d87f773..4900e4471 100644
--- a/vmod/automake_boilerplate_std.am
+++ b/vmod/automake_boilerplate_std.am
@@ -28,8 +28,11 @@ $(libvmod_std_la_OBJECTS): vcc_std_if.h
 
 vcc_std_if.h vmod_std.rst vmod_std.man.rst: vcc_std_if.c
 
+# A doc-change will not update mtime on the .h and .c files, so a
+# touch(1) is necessary to signal that vmodtool was in fact run.
 vcc_std_if.c: $(vmodtool) $(srcdir)/vmod_std.vcc
 	@PYTHON@ $(vmodtool) $(vmodtoolargs_std) $(srcdir)/vmod_std.vcc
+	touch vcc_std_if.c
 
 clean-local: clean-vmod-std
 
diff --git a/vmod/automake_boilerplate_unix.am b/vmod/automake_boilerplate_unix.am
index be3afe8cf..ab9ca4bca 100644
--- a/vmod/automake_boilerplate_unix.am
+++ b/vmod/automake_boilerplate_unix.am
@@ -26,8 +26,11 @@ $(libvmod_unix_la_OBJECTS): vcc_unix_if.h
 
 vcc_unix_if.h vmod_unix.rst vmod_unix.man.rst: vcc_unix_if.c
 
+# A doc-change will not update mtime on the .h and .c files, so a
+# touch(1) is necessary to signal that vmodtool was in fact run.
 vcc_unix_if.c: $(vmodtool) $(srcdir)/vmod_unix.vcc
 	@PYTHON@ $(vmodtool) $(vmodtoolargs_unix) $(srcdir)/vmod_unix.vcc
+	touch vcc_unix_if.c
 
 clean-local: clean-vmod-unix
 
diff --git a/vmod/automake_boilerplate_vtc.am b/vmod/automake_boilerplate_vtc.am
index 2d8d9a666..cae60718d 100644
--- a/vmod/automake_boilerplate_vtc.am
+++ b/vmod/automake_boilerplate_vtc.am
@@ -25,8 +25,11 @@ $(libvmod_vtc_la_OBJECTS): vcc_vtc_if.h
 
 vcc_vtc_if.h vmod_vtc.rst vmod_vtc.man.rst: vcc_vtc_if.c
 
+# A doc-change will not update mtime on the .h and .c files, so a
+# touch(1) is necessary to signal that vmodtool was in fact run.
 vcc_vtc_if.c: $(vmodtool) $(srcdir)/vmod_vtc.vcc
 	@PYTHON@ $(vmodtool) $(vmodtoolargs_vtc) $(srcdir)/vmod_vtc.vcc
+	touch vcc_vtc_if.c
 
 clean-local: clean-vmod-vtc
 


More information about the varnish-commit mailing list