pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/mk/pkgtasks Create ${PKG_SYSCONFDIR} automatically in ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/78d3f219dfd6
branches:  trunk
changeset: 363152:78d3f219dfd6
user:      jlam <jlam%pkgsrc.org@localhost>
date:      Fri Jun 02 16:12:25 2017 +0000

description:
Create ${PKG_SYSCONFDIR} automatically in "pkgtasks" framework.

Add missing feature from "pkginstall" framework where the config
directory ${PKG_SYSCONFDIR} was automatically created if one of
the following conditions were true:

* PKG_SYSCONFSUBDIR was defined and non-empty.
* Any configuration files were copied into ${PKG_SYSCONFDIR}.

diffstat:

 mk/pkgtasks/files.mk            |  19 ++++++++-
 mk/pkgtasks/tests/files_test    |  92 ++++++++++++++++++++++++++++++++++++++++-
 mk/pkgtasks/tests/pkgtasks_test |   9 ++-
 mk/pkgtasks/tests/test.mk       |  10 +++-
 4 files changed, 122 insertions(+), 8 deletions(-)

diffs (216 lines):

diff -r 3fd7a0c3e4a9 -r 78d3f219dfd6 mk/pkgtasks/files.mk
--- a/mk/pkgtasks/files.mk      Fri Jun 02 16:11:47 2017 +0000
+++ b/mk/pkgtasks/files.mk      Fri Jun 02 16:12:25 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.mk,v 1.2 2017/06/02 16:11:47 jlam Exp $
+# $NetBSD: files.mk,v 1.3 2017/06/02 16:12:25 jlam Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -139,6 +139,23 @@
 .  endif
 .endfor
 
+# Hook into directories.mk to create ${PKG_SYSCONFDIR} in the package
+# tasks.
+#
+# The following variables used are set within bsd.pkg.mk:
+#
+#      PKG_SYSCONFDIR
+#      PKG_SYSCONFDIR_PERMS
+#      PKG_SYSCONFSUBDIR
+#
+.if defined(PKG_SYSCONFSUBDIR) && !empty(PKG_SYSCONFSUBDIR)
+# Always create ${PKG_SYSCONFDIR} if ${PKG_SYSCONFSUBDIR} is non-empty.
+MAKE_DIRS_PERMS+=      ${PKG_SYSCONFDIR} ${PKG_SYSCONFDIR_PERMS}
+.elif !empty(_ALL_FILES.files:M${PKG_SYSCONFDIR}/*)
+# Create ${PKG_SYSCONFDIR} if any target files are in that directory.
+MAKE_DIRS+=            ${PKG_SYSCONFDIR}
+.endif
+
 _PKGTASKS_DATA.files=  ${_PKGTASKS_DIR}/files
 _PKGTASKS_DATAFILES+=  ${_PKGTASKS_DATA.files}
 
diff -r 3fd7a0c3e4a9 -r 78d3f219dfd6 mk/pkgtasks/tests/files_test
--- a/mk/pkgtasks/tests/files_test      Fri Jun 02 16:11:47 2017 +0000
+++ b/mk/pkgtasks/tests/files_test      Fri Jun 02 16:12:25 2017 +0000
@@ -1,6 +1,6 @@
 #!/usr/bin/env atf-sh
 #
-# $NetBSD: files_test,v 1.1 2017/06/01 02:06:05 jlam Exp $
+# $NetBSD: files_test,v 1.2 2017/06/02 16:12:26 jlam Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -161,8 +161,98 @@
        atf_pass
 }
 
+###
+### test3
+###
+
+atf_test_case test3
+
+test3_head()
+{
+       atf_set "descr" "PKG_SYSCONFSUBDIR triggers MAKE_DIRS_PERMS"
+}
+
+test3_body()
+{
+       : ${MAKE:=make}
+       : ${PKGSRCDIR:=/usr/pkgsrc}
+
+       # Setup
+       setup
+
+       cat > mk.conf << 'EOF'
+PKG_SYSCONFSUBDIR=     pkgname
+PKG_SYSCONFDIR_PERMS=  root wheel 0755
+EOF
+       echo "/etc/pkgname root wheel 0755" > expected
+       ${MAKE} show-var VARNAME=MAKE_DIRS_PERMS \
+               PKGSRCDIR="${PKGSRCDIR}" > value
+       cmp expected value ||
+               atf_fail "PKG_SYSCONFSUBDIR not in MAKE_DIRS_PERMS"
+       atf_pass
+}
+
+###
+### test4
+###
+
+atf_test_case test4
+
+test4_head()
+{
+       atf_set "descr" "CONF_FILES into PKG_SYSCONFDIR triggers MAKE_DIRS"
+}
+
+test4_body()
+{
+       : ${MAKE:=make}
+       : ${PKGSRCDIR:=/usr/pkgsrc}
+
+       # Setup
+       setup
+
+       cat > mk.conf << 'EOF'
+CONF_FILES+=   source ${PKG_SYSCONFDIR}/target
+EOF
+       echo "/etc" > expected
+       ${MAKE} show-var VARNAME=MAKE_DIRS PKGSRCDIR="${PKGSRCDIR}" > value
+       cmp expected value || atf_fail "PKG_SYSCONFDIR not in MAKE_DIRS"
+       atf_pass
+}
+
+###
+### test5
+###
+
+atf_test_case test5
+
+test5_head()
+{
+       atf_set "descr" "CONF_FILES outside of PKG_SYSCONFDIR"
+}
+
+test5_body()
+{
+       : ${MAKE:=make}
+       : ${PKGSRCDIR:=/usr/pkgsrc}
+
+       # Setup
+       setup
+
+       cat > mk.conf << 'EOF'
+CONF_FILES+=   source target
+EOF
+       echo > expected
+       ${MAKE} show-var VARNAME=MAKE_DIRS PKGSRCDIR="${PKGSRCDIR}" > value
+       cmp expected value || atf_fail "MAKE_DIRS not empty"
+       atf_pass
+}
+
 atf_init_test_cases()
 {
        atf_add_test_case test1
        atf_add_test_case test2
+       atf_add_test_case test3
+       atf_add_test_case test4
+       atf_add_test_case test5
 }
diff -r 3fd7a0c3e4a9 -r 78d3f219dfd6 mk/pkgtasks/tests/pkgtasks_test
--- a/mk/pkgtasks/tests/pkgtasks_test   Fri Jun 02 16:11:47 2017 +0000
+++ b/mk/pkgtasks/tests/pkgtasks_test   Fri Jun 02 16:12:25 2017 +0000
@@ -1,6 +1,6 @@
 #!/usr/bin/env atf-sh
 #
-# $NetBSD: pkgtasks_test,v 1.1 2017/06/01 02:06:05 jlam Exp $
+# $NetBSD: pkgtasks_test,v 1.2 2017/06/02 16:12:26 jlam Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -77,14 +77,15 @@
 
        cat > mk.conf << 'EOF'
 MAKE_DIRS+=    dir
-CONF_FILES+=   source target
+CONF_FILES+=   source ${PKG_SYSCONFDIR}/target
 PKG_GROUPS+=   g1
 PKG_USERS+=    u1:g1
 EOF
        # Expected output.
        cat > expected << 'EOF'
 # DIR: dir m
-# FILE: target c source 0644
+# DIR: /etc m
+# FILE: /etc/target c source 0644
 # GROUP: g1
 # USER: u1:g1:::/nonexistent:/sbin/nologin
 EOF
@@ -120,7 +121,7 @@
 
        cat > mk.conf << 'EOF'
 MAKE_DIRS+=    dir
-CONF_FILES+=   source target
+CONF_FILES+=   source ${PKG_SYSCONFDIR}/target
 PKG_GROUPS+=   g1
 PKG_USERS+=    u1:g1
 EOF
diff -r 3fd7a0c3e4a9 -r 78d3f219dfd6 mk/pkgtasks/tests/test.mk
--- a/mk/pkgtasks/tests/test.mk Fri Jun 02 16:11:47 2017 +0000
+++ b/mk/pkgtasks/tests/test.mk Fri Jun 02 16:12:25 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: test.mk,v 1.2 2017/06/02 16:11:24 jlam Exp $
+# $NetBSD: test.mk,v 1.3 2017/06/02 16:12:26 jlam Exp $
 #
 # Copyright (c) 2017 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -39,7 +39,7 @@
 MKDIR?=                        mkdir -p
 MV?=                   mv
 NOLOGIN?=              /sbin/nologin
-PKG_SYSCONFDIR?=       /etc
+PKG_SYSCONFBASE?=      /etc
 PREFIX?=               ${LOCALBASE}
 RM?=                   rm
 RUN?=                  @
@@ -48,6 +48,8 @@
 TEST?=                 test
 VARBASE?=              /var
 
+PKG_SYSCONFDIR=                ${PKG_SYSCONFSUBDIR:D${PKG_SYSCONFBASE}/${PKG_SYSCONFSUBDIR}:U${PKG_SYSCONFBASE}}
+
 # Override any other default definitions so that generated files go into
 # the current directory.
 #
@@ -59,3 +61,7 @@
 .PHONY: _all
 _all:
        ${RUN}: "do nothing"
+
+# Target to write the value of a variable to standard output.
+show-var: .PHONY
+       @echo ${${VARNAME}:Q}



Home | Main Index | Thread Index | Old Index