From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 572BC1384B4 for ; Mon, 30 Nov 2015 15:02:29 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BCFFD21C08A; Mon, 30 Nov 2015 15:01:32 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 1E3AA21C01B for ; Mon, 30 Nov 2015 15:01:31 +0000 (UTC) Received: from localhost.localdomain (d202-251.icpnet.pl [109.173.202.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id 79736340554; Mon, 30 Nov 2015 15:01:29 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH 1/8] systemd.eclass: Introduce a common getter for systemd directories Date: Mon, 30 Nov 2015 16:01:15 +0100 Message-Id: <1448895682-19312-2-git-send-email-mgorny@gentoo.org> X-Mailer: git-send-email 2.6.3 In-Reply-To: <1448895682-19312-1-git-send-email-mgorny@gentoo.org> References: <1448636008-13184-1-git-send-email-mgorny@gentoo.org> <1448895682-19312-1-git-send-email-mgorny@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Archives-Salt: 9f2ce1a7-86dd-4f9b-af9c-7b4e9569c44c X-Archives-Hash: 7ae61307e666c1deaf180d70fc9df001 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: # @INTERNAL # @DESCRIPTION: -# Get unprefixed unitdir. -_systemd_get_unitdir() { +# Try to obtain the variable from systemd.pc. +# If pkg-config or systemd is not installed, return +# instead. +_systemd_get_dir() { + [[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} " + 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