From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH 1/7] systemd.eclass: Introduce a common getter for systemd directories
Date: Fri, 27 Nov 2015 15:53:22 +0100 [thread overview]
Message-ID: <1448636008-13184-2-git-send-email-mgorny@gentoo.org> (raw)
In-Reply-To: <1448636008-13184-1-git-send-email-mgorny@gentoo.org>
Add a _systemd_get_dir function that serves as a common getter for
all directories returned by the eclass. Add proper error handling for
the variable getter.
---
eclass/systemd.eclass | 38 +++++++++++++++++++++++---------------
1 file changed, 23 insertions(+), 15 deletions(-)
diff --git a/eclass/systemd.eclass b/eclass/systemd.eclass
index 278d319..245e803 100644
--- a/eclass/systemd.eclass
+++ b/eclass/systemd.eclass
@@ -34,16 +34,32 @@ esac
DEPEND="virtual/pkgconfig"
-# @FUNCTION: _systemd_get_unitdir
+# @FUNCTION: _systemd_get_dir
+# @USAGE: <variable-name> <fallback-directory>
# @INTERNAL
# @DESCRIPTION:
-# Get unprefixed unitdir.
-_systemd_get_unitdir() {
+# Try to obtain the <variable-name> variable from systemd.pc.
+# If pkg-config or systemd is not installed, return <fallback-directory>
+# instead.
+_systemd_get_dir() {
+ [[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <variable-name> <fallback-directory>"
+ local variable=${1} fallback=${2} d
+
if $(tc-getPKG_CONFIG) --exists systemd; then
- echo "$($(tc-getPKG_CONFIG) --variable=systemdsystemunitdir systemd)"
+ d=$($(tc-getPKG_CONFIG) --variable="${variable}" systemd) || die
else
- echo /usr/lib/systemd/system
+ d=${fallback}
fi
+
+ echo "${d}"
+}
+
+# @FUNCTION: _systemd_get_unitdir
+# @INTERNAL
+# @DESCRIPTION:
+# Get unprefixed unitdir.
+_systemd_get_unitdir() {
+ _systemd_get_dir systemdsystemunitdir /usr/lib/systemd/system
}
# @FUNCTION: systemd_get_unitdir
@@ -62,11 +78,7 @@ systemd_get_unitdir() {
# @DESCRIPTION:
# Get unprefixed userunitdir.
_systemd_get_userunitdir() {
- if $(tc-getPKG_CONFIG) --exists systemd; then
- echo "$($(tc-getPKG_CONFIG) --variable=systemduserunitdir systemd)"
- else
- echo /usr/lib/systemd/user
- fi
+ _systemd_get_dir systemduserunitdir /usr/lib/systemd/user
}
# @FUNCTION: systemd_get_userunitdir
@@ -86,11 +98,7 @@ systemd_get_userunitdir() {
# @DESCRIPTION:
# Get unprefixed utildir.
_systemd_get_utildir() {
- if $(tc-getPKG_CONFIG) --exists systemd; then
- echo "$($(tc-getPKG_CONFIG) --variable=systemdutildir systemd)"
- else
- echo /usr/lib/systemd
- fi
+ _systemd_get_dir systemdutildir /usr/lib/systemd
}
# @FUNCTION: systemd_get_utildir
--
2.6.3
next prev parent reply other threads:[~2015-11-27 14:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-27 14:53 [gentoo-dev] [PATCHES] systemd.eclass: Clean up & EAPI 6 support Michał Górny
2015-11-27 14:53 ` Michał Górny [this message]
2015-11-27 14:53 ` [gentoo-dev] [PATCH 2/7] systemd.eclass: Update the example for best practices Michał Górny
2015-11-27 14:53 ` [gentoo-dev] [PATCH 3/7] systemd.eclass: Remove long-deprecated systemd_to_myeconfargs Michał Górny
2015-11-27 14:53 ` [gentoo-dev] [PATCH 4/7] systemd.eclass: Add missing ||die on ntp file writes Michał Górny
2015-11-27 14:53 ` [gentoo-dev] [PATCH 5/7] systemd.eclass: Ban systemd_with_* in EAPI 6 Michał Górny
2015-11-27 14:53 ` [gentoo-dev] [PATCH 6/7] systemd.eclass: Allow systemd_update_catalog only during pkg_post* Michał Górny
2015-11-27 14:53 ` [gentoo-dev] [PATCH 7/7] systemd.eclass: Enable EAPI=6 Michał Górny
2015-11-30 15:01 ` [gentoo-dev] [v2] systemd.eclass cleanup & EAPI 6 support Michał Górny
2015-11-30 15:01 ` [gentoo-dev] [PATCH 1/8] systemd.eclass: Introduce a common getter for systemd directories Michał Górny
2015-11-30 15:01 ` [gentoo-dev] [PATCH 2/8] systemd.eclass: systemd_get_unitdir -> *systemunitdir for consistency Michał Górny
2015-11-30 15:01 ` [gentoo-dev] [PATCH 3/8] systemd.eclass: Update the example for best practices Michał Górny
2015-11-30 15:01 ` [gentoo-dev] [PATCH 4/8] systemd.eclass: Remove long-deprecated systemd_to_myeconfargs Michał Górny
2015-11-30 15:01 ` [gentoo-dev] [PATCH 5/8] systemd.eclass: Add missing ||die on ntp file writes Michał Górny
2015-11-30 15:01 ` [gentoo-dev] [PATCH 6/8] systemd.eclass: Ban systemd_with_* in EAPI 6 Michał Górny
2015-11-30 15:01 ` [gentoo-dev] [PATCH 7/8] systemd.eclass: Allow systemd_update_catalog only during pkg_post* Michał Górny
2015-11-30 15:01 ` [gentoo-dev] [PATCH 8/8] systemd.eclass: Enable EAPI=6 Michał Górny
2015-12-01 22:08 ` [gentoo-dev] [v2] systemd.eclass cleanup & EAPI 6 support Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1448636008-13184-2-git-send-email-mgorny@gentoo.org \
--to=mgorny@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox