public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 0/3] systemd.eclass improvements
@ 2022-10-10 15:33 Mike Gilbert
  2022-10-10 15:33 ` [gentoo-dev] [PATCH 1/3] systemd.eclass: rework EPREFIX handling Mike Gilbert
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mike Gilbert @ 2022-10-10 15:33 UTC (permalink / raw
  To: gentoo-dev; +Cc: Mike Gilbert

A few improvements to systemd.eclass.

Mike Gilbert (3):
  systemd.eclass: rework EPREFIX handling
  systemd.eclass: add systemd_get_sleepdir
  eclass/tests: add systemd tests

 eclass/systemd.eclass   | 77 +++++++++++++++--------------------------
 eclass/tests/systemd.sh | 50 ++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 50 deletions(-)
 create mode 100755 eclass/tests/systemd.sh

-- 
2.37.3



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [gentoo-dev] [PATCH 1/3] systemd.eclass: rework EPREFIX handling
  2022-10-10 15:33 [gentoo-dev] [PATCH 0/3] systemd.eclass improvements Mike Gilbert
@ 2022-10-10 15:33 ` Mike Gilbert
  2022-10-10 15:33 ` [gentoo-dev] [PATCH 2/3] systemd.eclass: add systemd_get_sleepdir Mike Gilbert
  2022-10-10 15:33 ` [gentoo-dev] [PATCH 3/3] eclass/tests: add systemd tests Mike Gilbert
  2 siblings, 0 replies; 4+ messages in thread
From: Mike Gilbert @ 2022-10-10 15:33 UTC (permalink / raw
  To: gentoo-dev; +Cc: Mike Gilbert

Instead of adding a private function to get the unprefixed version of
every path, use a new "_systemd_unprefix" helper function.

Signed-off-by: Mike Gilbert <floppym@gentoo.org>
---
 eclass/systemd.eclass | 69 ++++++++++++-------------------------------
 1 file changed, 19 insertions(+), 50 deletions(-)

diff --git a/eclass/systemd.eclass b/eclass/systemd.eclass
index 7731bede094..9e9a9b0cf20 100644
--- a/eclass/systemd.eclass
+++ b/eclass/systemd.eclass
@@ -1,4 +1,4 @@
-# Copyright 2011-2021 Gentoo Authors
+# Copyright 2011-2022 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: systemd.eclass
@@ -53,20 +53,21 @@ _systemd_get_dir() {
 
 	if $(tc-getPKG_CONFIG) --exists systemd; then
 		d=$($(tc-getPKG_CONFIG) --variable="${variable}" systemd) || die
-		d=${d#${EPREFIX}}
 	else
-		d=${fallback}
+		d="${EPREFIX}${fallback}"
 	fi
 
 	echo "${d}"
 }
 
-# @FUNCTION: _systemd_get_systemunitdir
+# @FUNCTION: _systemd_unprefix
+# @USAGE: <function-name>
 # @INTERNAL
 # @DESCRIPTION:
-# Get unprefixed unitdir.
-_systemd_get_systemunitdir() {
-	_systemd_get_dir systemdsystemunitdir /lib/systemd/system
+# Calls the specified function and removes ${EPREFIX} from the result.
+_systemd_unprefix() {
+	local d=$("${@}")
+	echo "${d#"${EPREFIX}"}"
 }
 
 # @FUNCTION: systemd_get_systemunitdir
@@ -77,7 +78,7 @@ _systemd_get_systemunitdir() {
 systemd_get_systemunitdir() {
 	debug-print-function ${FUNCNAME} "${@}"
 
-	echo "${EPREFIX}$(_systemd_get_systemunitdir)"
+	_systemd_get_dir systemdsystemunitdir /lib/systemd/system
 }
 
 # @FUNCTION: systemd_get_unitdir
@@ -89,14 +90,6 @@ systemd_get_unitdir() {
 	systemd_get_systemunitdir
 }
 
-# @FUNCTION: _systemd_get_userunitdir
-# @INTERNAL
-# @DESCRIPTION:
-# Get unprefixed userunitdir.
-_systemd_get_userunitdir() {
-	_systemd_get_dir systemduserunitdir /usr/lib/systemd/user
-}
-
 # @FUNCTION: systemd_get_userunitdir
 # @DESCRIPTION:
 # Output the path for the systemd user unit directory (not including
@@ -105,15 +98,7 @@ _systemd_get_userunitdir() {
 systemd_get_userunitdir() {
 	debug-print-function ${FUNCNAME} "${@}"
 
-	echo "${EPREFIX}$(_systemd_get_userunitdir)"
-}
-
-# @FUNCTION: _systemd_get_utildir
-# @INTERNAL
-# @DESCRIPTION:
-# Get unprefixed utildir.
-_systemd_get_utildir() {
-	_systemd_get_dir systemdutildir /lib/systemd
+	_systemd_get_dir systemduserunitdir /usr/lib/systemd/user
 }
 
 # @FUNCTION: systemd_get_utildir
@@ -124,15 +109,7 @@ _systemd_get_utildir() {
 systemd_get_utildir() {
 	debug-print-function ${FUNCNAME} "${@}"
 
-	echo "${EPREFIX}$(_systemd_get_utildir)"
-}
-
-# @FUNCTION: _systemd_get_systemgeneratordir
-# @INTERNAL
-# @DESCRIPTION:
-# Get unprefixed systemgeneratordir.
-_systemd_get_systemgeneratordir() {
-	_systemd_get_dir systemdsystemgeneratordir /lib/systemd/system-generators
+	_systemd_get_dir systemdutildir /lib/systemd
 }
 
 # @FUNCTION: systemd_get_systemgeneratordir
@@ -142,15 +119,7 @@ _systemd_get_systemgeneratordir() {
 systemd_get_systemgeneratordir() {
 	debug-print-function ${FUNCNAME} "${@}"
 
-	echo "${EPREFIX}$(_systemd_get_systemgeneratordir)"
-}
-
-# @FUNCTION: _systemd_get_systempresetdir
-# @INTERNAL
-# @DESCRIPTION:
-# Get unprefixed systempresetdir.
-_systemd_get_systempresetdir() {
-	_systemd_get_dir systemdsystempresetdir /lib/systemd/system-preset
+	_systemd_get_dir systemdsystemgeneratordir /lib/systemd/system-generators
 }
 
 # @FUNCTION: systemd_get_systempresetdir
@@ -160,7 +129,7 @@ _systemd_get_systempresetdir() {
 systemd_get_systempresetdir() {
 	debug-print-function ${FUNCNAME} "${@}"
 
-	echo "${EPREFIX}$(_systemd_get_systempresetdir)"
+	_systemd_get_dir systemdsystempresetdir /lib/systemd/system-preset
 }
 
 # @FUNCTION: systemd_dounit
@@ -172,7 +141,7 @@ systemd_dounit() {
 
 	(
 		insopts -m 0644
-		insinto "$(_systemd_get_systemunitdir)"
+		insinto "$(_systemd_unprefix systemd_get_systemunitdir)"
 		doins "${@}"
 	)
 }
@@ -186,7 +155,7 @@ systemd_newunit() {
 
 	(
 		insopts -m 0644
-		insinto "$(_systemd_get_systemunitdir)"
+		insinto "$(_systemd_unprefix systemd_get_systemunitdir)"
 		newins "${@}"
 	)
 }
@@ -200,7 +169,7 @@ systemd_douserunit() {
 
 	(
 		insopts -m 0644
-		insinto "$(_systemd_get_userunitdir)"
+		insinto "$(_systemd_unprefix systemd_get_userunitdir)"
 		doins "${@}"
 	)
 }
@@ -215,7 +184,7 @@ systemd_newuserunit() {
 
 	(
 		insopts -m 0644
-		insinto "$(_systemd_get_userunitdir)"
+		insinto "$(_systemd_unprefix systemd_get_userunitdir)"
 		newins "${@}"
 	)
 }
@@ -262,7 +231,7 @@ systemd_enable_service() {
 
 	local target=${1}
 	local service=${2}
-	local ud=$(_systemd_get_systemunitdir)
+	local ud=$(_systemd_unprefix systemd_get_systemunitdir)
 	local destname=${service##*/}
 
 	dodir "${ud}"/"${target}".wants && \
@@ -306,7 +275,7 @@ systemd_enable_ntpunit() {
 
 	(
 		insopts -m 0644
-		insinto "$(_systemd_get_utildir)"/ntp-units.d
+		insinto "$(_systemd_unprefix systemd_get_utildir)"/ntp-units.d
 		doins "${T}"/${ntpunit_name}.list
 	)
 	local ret=${?}
-- 
2.37.3



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-dev] [PATCH 2/3] systemd.eclass: add systemd_get_sleepdir
  2022-10-10 15:33 [gentoo-dev] [PATCH 0/3] systemd.eclass improvements Mike Gilbert
  2022-10-10 15:33 ` [gentoo-dev] [PATCH 1/3] systemd.eclass: rework EPREFIX handling Mike Gilbert
@ 2022-10-10 15:33 ` Mike Gilbert
  2022-10-10 15:33 ` [gentoo-dev] [PATCH 3/3] eclass/tests: add systemd tests Mike Gilbert
  2 siblings, 0 replies; 4+ messages in thread
From: Mike Gilbert @ 2022-10-10 15:33 UTC (permalink / raw
  To: gentoo-dev; +Cc: Mike Gilbert

Closes: https://bugs.gentoo.org/873172
Signed-off-by: Mike Gilbert <floppym@gentoo.org>
---
 eclass/systemd.eclass | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/eclass/systemd.eclass b/eclass/systemd.eclass
index 9e9a9b0cf20..fbed387e0ca 100644
--- a/eclass/systemd.eclass
+++ b/eclass/systemd.eclass
@@ -132,6 +132,14 @@ systemd_get_systempresetdir() {
 	_systemd_get_dir systemdsystempresetdir /lib/systemd/system-preset
 }
 
+# @FUNCTION: systemd_get_sleepdir
+# @DESCRIPTION:
+# Output the path for the system sleep directory.
+systemd_get_sleepdir() {
+	debug-print-function ${FUNCNAME} "${@}"
+	_systemd_get_dir systemdsleepdir /lib/systemd/system-sleep
+}
+
 # @FUNCTION: systemd_dounit
 # @USAGE: <unit>...
 # @DESCRIPTION:
-- 
2.37.3



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-dev] [PATCH 3/3] eclass/tests: add systemd tests
  2022-10-10 15:33 [gentoo-dev] [PATCH 0/3] systemd.eclass improvements Mike Gilbert
  2022-10-10 15:33 ` [gentoo-dev] [PATCH 1/3] systemd.eclass: rework EPREFIX handling Mike Gilbert
  2022-10-10 15:33 ` [gentoo-dev] [PATCH 2/3] systemd.eclass: add systemd_get_sleepdir Mike Gilbert
@ 2022-10-10 15:33 ` Mike Gilbert
  2 siblings, 0 replies; 4+ messages in thread
From: Mike Gilbert @ 2022-10-10 15:33 UTC (permalink / raw
  To: gentoo-dev; +Cc: Mike Gilbert

Signed-off-by: Mike Gilbert <floppym@gentoo.org>
---
 eclass/tests/systemd.sh | 50 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100755 eclass/tests/systemd.sh

diff --git a/eclass/tests/systemd.sh b/eclass/tests/systemd.sh
new file mode 100755
index 00000000000..f870df4b7a1
--- /dev/null
+++ b/eclass/tests/systemd.sh
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+source tests-common.sh || exit
+
+inherit systemd
+
+test_system_dir() {
+	local exp1="${EPREFIX}$1"
+	local exp2="${EPREFIX}/usr$1"
+	shift
+	tbegin "$@"
+	local act=$("$@")
+	[[ ${act} == ${exp1} || ${act} == ${exp2} ]]
+	tend $?
+}
+
+test_user_dir() {
+	local exp="${EPREFIX}$1"
+	shift
+	tbegin "$@"
+	local act=$("$@")
+	[[ ${act} == ${exp} ]]
+	tend $?
+}
+
+test_systemd_unprefix() {
+	local exp=$1
+	local EPREFIX=$2
+	shift 2
+	tbegin "EPREFIX=${EPREFIX} _systemd_unprefix $@"
+	[[ "$(_systemd_unprefix "$@")" == "${exp}" ]]
+	tend $?
+}
+
+test_system_dir /lib/systemd/system systemd_get_systemunitdir
+test_system_dir /lib/systemd systemd_get_utildir
+test_system_dir /lib/systemd/system-generators systemd_get_systemgeneratordir
+test_system_dir /lib/systemd/system-preset systemd_get_systempresetdir
+test_system_dir /lib/systemd/system-sleep systemd_get_sleepdir
+
+test_user_dir /usr/lib/systemd/user systemd_get_userunitdir
+
+test_systemd_unprefix /lib/systemd /prefix echo /prefix/lib/systemd
+test_systemd_unprefix /lib/systemd '' echo /lib/systemd
+test_systemd_unprefix /lib/systemd '/*' echo '/*/lib/systemd'
+
+texit
-- 
2.37.3



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-10 15:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-10 15:33 [gentoo-dev] [PATCH 0/3] systemd.eclass improvements Mike Gilbert
2022-10-10 15:33 ` [gentoo-dev] [PATCH 1/3] systemd.eclass: rework EPREFIX handling Mike Gilbert
2022-10-10 15:33 ` [gentoo-dev] [PATCH 2/3] systemd.eclass: add systemd_get_sleepdir Mike Gilbert
2022-10-10 15:33 ` [gentoo-dev] [PATCH 3/3] eclass/tests: add systemd tests Mike Gilbert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox