[libvirt] [PATCH 15/41] remote: reduce duplication in systemd unit file make rules into one

Daniel P. Berrangé posted 41 patches 6 years, 6 months ago
There is a newer version of this series
[libvirt] [PATCH 15/41] remote: reduce duplication in systemd unit file make rules into one
Posted by Daniel P. Berrangé 6 years, 6 months ago
The make rules for the systemd socket unit files are all essentially
identical and can be collapsed into a single generic rule. The service
unit file rule can be simplified too.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 src/Makefile.am            |  6 +++++
 src/remote/Makefile.inc.am | 47 ++++++--------------------------------
 2 files changed, 13 insertions(+), 40 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index dbbb94e7f1..d254069e4b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -89,6 +89,12 @@ man8_MANS =
 DRIVER_SOURCES =
 man7_MANS =
 
+COMMON_UNIT_VARS = \
+	-e 's|[@]localstatedir[@]|$(localstatedir)|g' \
+	-e 's|[@]sbindir[@]|$(sbindir)|g' \
+	-e 's|[@]sysconfdir[@]|$(sysconfdir)|g' \
+	$(NULL)
+
 include util/Makefile.inc.am
 include conf/Makefile.inc.am
 include cpu/Makefile.inc.am
diff --git a/src/remote/Makefile.inc.am b/src/remote/Makefile.inc.am
index 7fd50a15df..6b09fc9294 100644
--- a/src/remote/Makefile.inc.am
+++ b/src/remote/Makefile.inc.am
@@ -290,48 +290,15 @@ INSTALL_DATA_LOCAL += install-sasl
 UNINSTALL_LOCAL += uninstall-sasl
 endif WITH_SASL
 
-libvirtd.service: remote/libvirtd.service.in $(top_builddir)/config.status
-	$(AM_V_GEN)sed \
-	    -e 's|[@]localstatedir[@]|$(localstatedir)|g' \
-	    -e 's|[@]sbindir[@]|$(sbindir)|g' \
-	    -e 's|[@]sysconfdir[@]|$(sysconfdir)|g' \
-	    < $< > $@-t && \
-	    mv $@-t $@
-
-libvirtd.socket: remote/libvirtd.socket.in $(top_builddir)/config.status
-	$(AM_V_GEN)sed \
-	    -e 's|[@]localstatedir[@]|$(localstatedir)|g' \
-	    -e 's|[@]sysconfdir[@]|$(sysconfdir)|g' \
-	    < $< > $@-t && \
-	    mv $@-t $@
-
-libvirtd-ro.socket: remote/libvirtd-ro.socket.in $(top_builddir)/config.status
-	$(AM_V_GEN)sed \
-	    -e 's|[@]localstatedir[@]|$(localstatedir)|g' \
-	    -e 's|[@]sysconfdir[@]|$(sysconfdir)|g' \
-	    < $< > $@-t && \
-	    mv $@-t $@
-
-libvirtd-admin.socket: remote/libvirtd-admin.socket.in $(top_builddir)/config.status
-	$(AM_V_GEN)sed \
-	    -e 's|[@]localstatedir[@]|$(localstatedir)|g' \
-	    -e 's|[@]sysconfdir[@]|$(sysconfdir)|g' \
-	    < $< > $@-t && \
-	    mv $@-t $@
+LIBVIRTD_UNIT_VARS = \
+	$(COMMON_UNIT_VARS) \
+	$(NULL)
 
-libvirtd-tcp.socket: remote/libvirtd-tcp.socket.in $(top_builddir)/config.status
-	$(AM_V_GEN)sed \
-	    -e 's|[@]localstatedir[@]|$(localstatedir)|g' \
-	    -e 's|[@]sysconfdir[@]|$(sysconfdir)|g' \
-	    < $< > $@-t && \
-	    mv $@-t $@
+libvirtd.service: remote/libvirtd.service.in $(top_builddir)/config.status
+	$(AM_V_GEN)sed $(LIBVIRTD_UNIT_VARS) < $< > $@-t && mv $@-t $@
 
-libvirtd-tls.socket: remote/libvirtd-tls.socket.in $(top_builddir)/config.status
-	$(AM_V_GEN)sed \
-	    -e 's|[@]localstatedir[@]|$(localstatedir)|g' \
-	    -e 's|[@]sysconfdir[@]|$(sysconfdir)|g' \
-	    < $< > $@-t && \
-	    mv $@-t $@
+libvirt%.socket: remote/libvirt%.socket.in $(top_builddir)/config.status
+	$(AM_V_GEN)sed $(LIBVIRTD_UNIT_VARS) < $< > $@-t && mv $@-t $@
 
 virt-guest-shutdown.target: remote/virt-guest-shutdown.target.in \
 			$(top_builddir)/config.status
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 15/41] remote: reduce duplication in systemd unit file make rules into one
Posted by Andrea Bolognani 6 years, 6 months ago
On Tue, 2019-07-23 at 17:02 +0100, Daniel P. Berrangé wrote:
[...]
> +COMMON_UNIT_VARS = \
> +	-e 's|[@]localstatedir[@]|$(localstatedir)|g' \
> +	-e 's|[@]sbindir[@]|$(sbindir)|g' \
> +	-e 's|[@]sysconfdir[@]|$(sysconfdir)|g' \
> +	$(NULL)
>  
> +LIBVIRTD_UNIT_VARS = \
> +	$(COMMON_UNIT_VARS) \
> +	$(NULL)
>  
> +libvirtd.service: remote/libvirtd.service.in $(top_builddir)/config.status
> +	$(AM_V_GEN)sed $(LIBVIRTD_UNIT_VARS) < $< > $@-t && mv $@-t $@
>  
> +libvirt%.socket: remote/libvirt%.socket.in $(top_builddir)/config.status
> +	$(AM_V_GEN)sed $(LIBVIRTD_UNIT_VARS) < $< > $@-t && mv $@-t $@

This is a fantastic refactoring that I've been thinking about
spending time on for a long time, so thanks a lot for doing it!

It's a bummer that we don't go further in our DRY crusade and extend
it to .service files (even after the entire series has been applied),
but we can always do that as a follow-up series :)

  Reviewed-by: Andrea Bolognani <abologna@redhat.com>

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list