pkgsrc-Changes archive

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

CVS commit: pkgsrc/mk/pkgformat/pkg



Module Name:    pkgsrc
Committed By:   jlam
Date:           Thu Jun  1 02:09:43 UTC 2017

Added Files:
        pkgsrc/mk/pkgformat/pkg: scripts.mk
        pkgsrc/mk/pkgformat/pkg/templates: deinstall footer header install
        pkgsrc/mk/pkgformat/pkg/tests: Kyuafile scripts_test

Log Message:
Make creation of +DEINSTALL/+INSTALL scripts pkgformat-specific.

Move the files needed to generate +DEINSTALL and +INSTALL scripts
for the "pkg" format into pkgsrc/mk/pkgformat/pkg.

Create new script templates that make use of "pkgtasks" to perform
the actual tasks.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 pkgsrc/mk/pkgformat/pkg/scripts.mk
cvs rdiff -u -r0 -r1.1 pkgsrc/mk/pkgformat/pkg/templates/deinstall \
    pkgsrc/mk/pkgformat/pkg/templates/footer \
    pkgsrc/mk/pkgformat/pkg/templates/header \
    pkgsrc/mk/pkgformat/pkg/templates/install
cvs rdiff -u -r0 -r1.1 pkgsrc/mk/pkgformat/pkg/tests/Kyuafile \
    pkgsrc/mk/pkgformat/pkg/tests/scripts_test

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: pkgsrc/mk/pkgformat/pkg/scripts.mk
diff -u /dev/null pkgsrc/mk/pkgformat/pkg/scripts.mk:1.1
--- /dev/null   Thu Jun  1 02:09:43 2017
+++ pkgsrc/mk/pkgformat/pkg/scripts.mk  Thu Jun  1 02:09:43 2017
@@ -0,0 +1,182 @@
+# $NetBSD: scripts.mk,v 1.1 2017/06/01 02:09:43 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# This Makefile fragment provides the targets to make the +DEINSTALL
+# and +INSTALL scripts and hooks into metadata.mk to automatically
+# generate them as needed.
+
+# HEADER_TEMPLATES
+#      List of package-provided template files to be concatenated
+#      into a header for the install and deinstall scripts.  The
+#      concatenated files are placed after the main header template
+#      file.
+#
+# DEINSTALL_TEMPLATES
+#      List of package-provided template files to be concatenated
+#      to form the body of the deinstall script.  The concatenated
+#      files are placed before the main deinstall template file.
+#      The script templates should exit with a code >0 if an error
+#      occurs.
+#
+# INSTALL_TEMPLATES
+#      List of package-provided template files to be concatenated
+#      to form the body of the install script.  The concatenated
+#      files are placed after the main install template file.  The
+#      script templates should exit with a code >0 if an error
+#      occurs.
+#
+_HEADER_TMPL=          ${PKGSRCDIR}/mk/pkgformat/pkg/templates/header
+HEADER_TEMPLATES?=     # empty
+.for _file_ in ${PKGDIR}/HEADER
+.  if exists(${_file_}) && empty(HEADER_TEMPLATES:M${_file_})
+HEADER_TEMPLATES+=     ${_file_}
+.  endif
+.endfor
+_DEINSTALL_TMPL=       ${PKGSRCDIR}/mk/pkgformat/pkg/templates/deinstall
+DEINSTALL_TEMPLATES?=  # empty
+.for _file_ in ${PKGDIR}/DEINSTALL
+.  if exists(${_file_}) && empty(DEINSTALL_TEMPLATES:M${_file_})
+DEINSTALL_TEMPLATES+=  ${_file_}
+.  endif
+.endfor
+_INSTALL_TMPL=         ${PKGSRCDIR}/mk/pkgformat/pkg/templates/install
+INSTALL_TEMPLATES?=    # empty
+.for _file_ in ${PKGDIR}/INSTALL
+.  if exists(${_file_}) && empty(INSTALL_TEMPLATES:M${_file_})
+INSTALL_TEMPLATES+=    ${_file_}
+.  endif
+.endfor
+_FOOTER_TMPL?=         ${PKGSRCDIR}/mk/pkgformat/pkg/templates/footer
+
+# DEINSTALL_SRC
+# INSTALL_SRC
+#      List of source files that are concatenated to form the
+#      deinstall and install scripts.
+#
+.if ( "${USE_PKGTASKS:tl}" == "yes" ) || !empty(HEADER_TEMPLATES) ||   \
+    !empty(DEINSTALL_TEMPLATES) || !empty(INSTALL_TEMPLATES)
+DEINSTALL_SRC?=                ${_HEADER_TMPL} ${HEADER_TEMPLATES}             \
+                       ${DEINSTALL_TEMPLATES} ${_DEINSTALL_TMPL}       \
+                       ${_FOOTER_TMPL} ${PKGTASKS_DATAFILE}
+INSTALL_SRC?=          ${_HEADER_TMPL} ${HEADER_TEMPLATES}             \
+                       ${_INSTALL_TMPL} ${INSTALL_TEMPLATES}           \
+                       ${_FOOTER_TMPL} ${PKGTASKS_DATAFILE}
+.else
+DEINSTALL_SRC?=                # empty
+INSTALL_SRC?=          # empty
+.endif
+
+# _DEINSTALL_FILE
+#      The location of the file to be added as the deinstall script
+#      for the package.
+#
+#      Possible: any valid path
+#      Default: ${PKG_DB_TMPDIR}/+DEINSTALL
+#
+# _INSTALL_FILE
+#      The location of the file to be added as the install script
+#      for the package.
+#
+#      Possible: any valid path
+#      Default: ${PKG_DB_TMPDIR}/+INSTALL
+#
+# _pkgformat-generate-install-scripts (PRIVATE)
+#      Convenience target to generate the deinstall and install
+#      scripts for the package.
+#
+
+.if !empty(DEINSTALL_SRC)
+_DEINSTALL_FILE=       ${PKG_DB_TMPDIR}/+DEINSTALL
+
+${_DEINSTALL_FILE}: ${DEINSTALL_SRC}
+       ${RUN}${MKDIR} ${.TARGET:H:Q}
+       ${RUN}${CAT} ${.ALLSRC} | ${SED} ${FILES_SUBST_SED} > ${.TARGET}.tmp
+       ${RUN}${CHMOD} +x ${.TARGET}.tmp
+       ${RUN}${MV} -f ${.TARGET}.tmp ${.TARGET}
+.endif
+.if !empty(INSTALL_SRC)
+_INSTALL_FILE=         ${PKG_DB_TMPDIR}/+INSTALL
+
+${_INSTALL_FILE}: ${INSTALL_SRC}
+       ${RUN}${MKDIR} ${.TARGET:H:Q}
+       ${RUN}${CAT} ${.ALLSRC} | ${SED} ${FILES_SUBST_SED} > ${.TARGET}.tmp
+       ${RUN}${CHMOD} +x ${.TARGET}.tmp
+       ${RUN}${MV} -f ${.TARGET}.tmp ${.TARGET}
+.endif
+
+.PHONY: _pkgformat-generate-install-scripts
+_pkgformat-generate-install-scripts: ${_DEINSTALL_FILE} ${_INSTALL_FILE}
+
+# Hook into pkgsrc/mk/pkgformat/pkg/metadata.mk to automatically generate
+# the deinstall and install scripts if needed.
+#
+_METADATA_TARGETS+=    ${_DEINSTALL_FILE} ${_INSTALL_FILE}
+
+###
+# Variable substitutions for the scripts.
+
+FILES_SUBST+=  PKGBASE=${PKGBASE:Q}
+
+# Variables for programs for use by script templates.
+FILES_SUBST+=  BASENAME=${BASENAME:Q}
+FILES_SUBST+=  CHGRP=${CHGRP:Q}
+FILES_SUBST+=  CMP=${CMP:Q}
+FILES_SUBST+=  DIRNAME=${DIRNAME:Q}
+FILES_SUBST+=  ECHO=${ECHO:Q}
+FILES_SUBST+=  ECHO_N=${ECHO_N:Q}
+FILES_SUBST+=  EGREP=${EGREP:Q}
+FILES_SUBST+=  EXPR=${EXPR:Q}
+FILES_SUBST+=  FALSE=${FALSE:Q}
+FILES_SUBST+=  GREP=${GREP:Q}
+FILES_SUBST+=  GTAR=${GTAR:Q}
+FILES_SUBST+=  HEAD=${HEAD:Q}
+FILES_SUBST+=  PERL5=${PERL5:Q}
+FILES_SUBST+=  PWD_CMD=${PWD_CMD:Q}
+FILES_SUBST+=  SETENV=${SETENV:Q}
+FILES_SUBST+=  SH=${SH:Q}
+FILES_SUBST+=  SU=${SU:Q}
+FILES_SUBST+=  TEST=${TEST:Q}
+FILES_SUBST+=  TOUCH=${TOUCH:Q}
+FILES_SUBST+=  TR=${TR:Q}
+FILES_SUBST+=  TRUE=${TRUE:Q}
+FILES_SUBST+=  XARGS=${XARGS:Q}
+
+# Variables for the pkg_install package tools.
+FILES_SUBST+=  PKG_ADMIN=${PKG_ADMIN:Q}
+FILES_SUBST+=  PKG_INFO=${PKG_INFO:Q}
+
+# Variables for installation prefix references.
+FILES_SUBST+=  LOCALBASE=${LOCALBASE:Q}
+FILES_SUBST+=  X11BASE=${X11BASE:Q}
+FILES_SUBST+=  PREFIX=${PREFIX:Q}
+
+# Variables for the package configuration directory.
+FILES_SUBST+=  PKG_SYSCONFBASE=${PKG_SYSCONFBASE:Q}
+FILES_SUBST+=  PKG_SYSCONFBASEDIR=${PKG_SYSCONFBASEDIR:Q}
+FILES_SUBST+=  PKG_SYSCONFDIR=${PKG_SYSCONFDIR:Q}

Index: pkgsrc/mk/pkgformat/pkg/templates/deinstall
diff -u /dev/null pkgsrc/mk/pkgformat/pkg/templates/deinstall:1.1
--- /dev/null   Thu Jun  1 02:09:43 2017
+++ pkgsrc/mk/pkgformat/pkg/templates/deinstall Thu Jun  1 02:09:43 2017
@@ -0,0 +1,55 @@
+### START: pkgsrc/mk/pkgformat/pkg/templates/deinstall
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# $NetBSD: deinstall,v 1.1 2017/06/01 02:09:43 jlam Exp $
+
+case ${STAGE} in
+DEINSTALL)
+       task_load preremove
+
+       # Use the data in the shell comments appended at the end of
+       # the script.
+       #
+       task_preremove "${SELF}" || exit $?
+       ;;
+
+POST-DEINSTALL)
+       task_load postremove
+
+       # Use the data in the shell comments appended at the end of
+       # the script.
+       #
+       # Failures during the POST-DEINSTALL stage are non-fatal, so
+       # ignore the return value of the "postremove" task.
+       #
+       task_postremove "${SELF}"
+       ;;
+esac
+
+### END: pkgsrc/mk/pkgformat/pkg/templates/deinstall
Index: pkgsrc/mk/pkgformat/pkg/templates/footer
diff -u /dev/null pkgsrc/mk/pkgformat/pkg/templates/footer:1.1
--- /dev/null   Thu Jun  1 02:09:43 2017
+++ pkgsrc/mk/pkgformat/pkg/templates/footer    Thu Jun  1 02:09:43 2017
@@ -0,0 +1,37 @@
+### START: pkgsrc/mk/pkgformat/pkg/templates/footer
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# $NetBSD: footer,v 1.1 2017/06/01 02:09:43 jlam Exp $
+
+# Exit with code 0.  Any errors encountered earlier in the script are
+# expected to cause the script to exit with code >0.
+#
+exit 0
+
+### END: pkgsrc/mk/pkgformat/pkg/templates/footer
Index: pkgsrc/mk/pkgformat/pkg/templates/header
diff -u /dev/null pkgsrc/mk/pkgformat/pkg/templates/header:1.1
--- /dev/null   Thu Jun  1 02:09:43 2017
+++ pkgsrc/mk/pkgformat/pkg/templates/header    Thu Jun  1 02:09:43 2017
@@ -0,0 +1,148 @@
+#!@SH@
+
+### START: pkgsrc/mk/pkgformat/pkg/templates/header
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# $NetBSD: header,v 1.1 2017/06/01 02:09:43 jlam Exp $
+
+# Package task loader.
+: ${TASK_MODULE_DIR:=@LOCALBASE@/share/pkgtasks-1}
+. "${TASK_MODULE_DIR}/load.subr"
+
+SELF="$0"
+if [ $# -lt 2 ]; then
+       echo 1>&2 "usage: ${SELF} <pkgname> <stage>"
+       exit 127
+fi
+# Script positional parameters.
+PKGNAME="$1"; shift
+STAGE="$1"; shift
+
+###
+# PKGBASE
+#      ${PKGNAME} stripped of the the version number.
+#
+# PKGVERSION
+#      The version number of the package, derived from taking
+#      ${PKGNAME} and stripping "${PKGBASE}-" from the front.
+#
+# ${PKGNAME} := ${PKGBASE}-${PKGVERSION}
+#
+PKGBASE="@PKGBASE@"
+PKGVERSION=${PKGNAME#${PKGBASE}-}
+
+# Prefix all task messages with "=> ".
+TASK_MSG="=> "
+
+# Variables for programs used by pkgtasks.
+AWK="@AWK@"
+CAT="@CAT@"
+CHMOD="@CHMOD@"
+CHOWN="@CHOWN@"
+CP="@CP@"
+DATE="@DATE@"
+FIND="@FIND@"
+ID="@ID@"
+LDCONFIG="@LDCONFIG@"
+LN="@LN@"
+LS="@LS@"
+MKDIR="@MKDIR@"
+MKTEMP="@MKTEMP@"
+MV="@MV@"
+PRINTF="@PRINTF@"
+RM="@RM@"
+RMDIR="@RMDIR@"
+SED="@SED@"
+SORT="@SORT@"
+UNAME="@UNAME@"
+
+# Variables for addgroup/adduser programs used by pkgtasks.
+GROUPADD="@GROUPADD@"
+PW="@PW@"
+PWD_MKDB="@PWD_MKDB@"
+USERADD="@USERADD@"
+
+# Variables for programs for use by script templates.
+BASENAME="@BASENAME@"
+CHGRP="@CHGRP@"
+CMP="@CMP@"
+DIRNAME="@DIRNAME@"
+ECHO="@ECHO@"
+ECHO_N="@ECHO_N@"
+EGREP="@EGREP@"
+EXPR="@EXPR@"
+FALSE="@FALSE@"
+GREP="@GREP@"
+GTAR="@GTAR@"
+HEAD="@HEAD@"
+PERL5="@PERL5@"
+PWD_CMD="@PWD_CMD@"
+SETENV="@SETENV@"
+SH="@SH@"
+SU="@SU@"
+TEST="@TEST@"
+TOUCH="@TOUCH@"
+TR="@TR@"
+TRUE="@TRUE@"
+XARGS="@XARGS@"
+
+# Variables for the pkg_install package tools.
+PKG_ADMIN="@PKG_ADMIN@"
+PKG_INFO="@PKG_INFO@"
+
+# Variables for installation prefix references.
+LOCALBASE="@LOCALBASE@"
+X11BASE="@X11BASE@"
+PREFIX="${PKG_PREFIX}"
+
+# Variables for the package configuration directory.
+PKG_SYSCONFBASE="@PKG_SYSCONFBASE@"
+PKG_SYSCONFBASEDIR="@PKG_SYSCONFBASEDIR@"
+PKG_SYSCONFDIR="@PKG_SYSCONFDIR@"
+
+# The current working directory from which the script was invoked.
+CURDIR=$( ${PWD_CMD} )
+
+# Default values for environment variables set by the package tools.
+: ${PKG_PREFIX:=@PREFIX@}
+: ${PKG_METADATA_DIR:=${CURDIR}}
+: ${PKG_DESTDIR:=""}
+: ${PKG_REFCOUNT_DBDIR:=@PKG_REFCOUNT_DBDIR@}
+
+# Default values for environment variables that control whether
+# task actions are executed.
+#
+: ${PKG_CONFIG:=@PKG_CONFIG@}
+: ${PKG_CONFIG_PERMS:=@PKG_CONFIG_PERMS@}
+: ${PKG_CREATE_USERGROUP:=@PKG_CREATE_USERGROUP@}
+: ${PKG_INIT_SCRIPTS:=@PKG_INIT_SCRIPTS@}
+: ${PKG_REGISTER_SHELLS:=@PKG_REGISTER_SHELLS@}
+: ${PKG_UPDATE_FONTS_DB:=@PKG_UPDATE_FONTS_DB@}
+
+### END: pkgsrc/mk/pkgformat/pkg/templates/header
Index: pkgsrc/mk/pkgformat/pkg/templates/install
diff -u /dev/null pkgsrc/mk/pkgformat/pkg/templates/install:1.1
--- /dev/null   Thu Jun  1 02:09:43 2017
+++ pkgsrc/mk/pkgformat/pkg/templates/install   Thu Jun  1 02:09:43 2017
@@ -0,0 +1,52 @@
+### START: pkgsrc/mk/pkgformat/pkg/templates/install
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# $NetBSD: install,v 1.1 2017/06/01 02:09:43 jlam Exp $
+
+case ${STAGE} in
+PRE-INSTALL)
+       task_load preinstall
+
+       # Use the data in the shell comments appended at the end of
+       # the script.
+       #
+       task_preinstall "${SELF}" || exit $?
+       ;;
+
+POST-INSTALL)
+       task_load postinstall
+
+       # Use the data in the shell comments appended at the end of
+       # the script.
+       #
+       task_postinstall "${SELF}" || exit $?
+       ;;
+esac
+
+### END: pkgsrc/mk/pkgformat/pkg/templates/install

Index: pkgsrc/mk/pkgformat/pkg/tests/Kyuafile
diff -u /dev/null pkgsrc/mk/pkgformat/pkg/tests/Kyuafile:1.1
--- /dev/null   Thu Jun  1 02:09:43 2017
+++ pkgsrc/mk/pkgformat/pkg/tests/Kyuafile      Thu Jun  1 02:09:43 2017
@@ -0,0 +1,49 @@
+-- $NetBSD: Kyuafile,v 1.1 2017/06/01 02:09:43 jlam Exp $
+--[[-----------------------------------------------------------------------
+Copyright (c) 2017 The NetBSD Foundation, Inc.
+All rights reserved.
+
+This code is derived from software contributed to The NetBSD Foundation
+by Johnny C. Lam.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+--]]-----------------------------------------------------------------------
+
+--[[-----------------------------------------------------------------------
+
+       The following variables will be used if they are set.
+
+       MAKE    The name or path to the BSD make(1) utility.  The default
+               is "make".
+
+       PKGSRCDIR
+               The location of the pkgsrc source tree.  The default is
+               "/usr/pkgsrc".
+
+--]]-----------------------------------------------------------------------
+
+syntax( 2 )
+
+test_suite( "pkgsrc_pkgformat_pkg" )
+
+atf_test_program { name = "scripts_test" }
Index: pkgsrc/mk/pkgformat/pkg/tests/scripts_test
diff -u /dev/null pkgsrc/mk/pkgformat/pkg/tests/scripts_test:1.1
--- /dev/null   Thu Jun  1 02:09:43 2017
+++ pkgsrc/mk/pkgformat/pkg/tests/scripts_test  Thu Jun  1 02:09:43 2017
@@ -0,0 +1,234 @@
+#!/usr/bin/env atf-sh
+#
+# $NetBSD: scripts_test,v 1.1 2017/06/01 02:09:43 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# ENVIRONMENT
+#      The following variables are used if they are set:
+#
+#      MAKE    The name or path to the BSD make(1) utility.  The default
+#              is "make".
+#
+#      PKGSRCDIR
+#              The location of the pkgsrc source tree.  The default is
+#              "/usr/pkgsrc".
+#
+
+setup()
+{
+       cat > mk.conf << 'EOF'
+# Definitions used by pkgformat/pkg/*.mk files that are not assigned
+# default values.
+#
+CAT?=          cat
+CHMOD?=                chmod
+MKDIR?=                mkdir -p
+MV?=           mv
+RUN?=          @
+SED?=          sed
+
+# Override any other default definitions so that generated files go into
+# the current directory.
+#
+PKGDIR=                ${.CURDIR}
+WRKDIR=                ${.CURDIR}
+PKG_DB_TMPDIR= ${.CURDIR}/.pkgdb
+
+# Don't generate a pkgtasks datafile.
+PKGTASKS_DATAFILE=     # empty
+# Generate a sed(1) script from ${FILES_SUBST}.
+FILES_SUBST_SED=       ${FILES_SUBST:S/=/@!/:S/$/!g/:S/^/ -e s!@/}
+EOF
+}
+
+###
+### test1: no scripts
+###
+
+atf_test_case test1
+
+test1_head()
+{
+       atf_set "descr" "no scripts"
+}
+
+test1_body()
+{
+       : ${MAKE:=make}
+       : ${PKGSRCDIR:=/usr/pkgsrc}
+
+       setup
+       cat > Makefile << 'EOF'
+.include "mk.conf"
+.include "${PKGSRCDIR}/mk/pkgformat/pkg/scripts.mk"
+
+.PHONY: all
+all:
+.if defined(_DEINSTALL_FILE)
+       @echo "_DEINSTALL_FILE = "${_DEINSTALL_FILE:Q}
+.endif
+.if defined(_INSTALL_FILE)
+       @echo "_INSTALL_FILE = "${_INSTALL_FILE:Q}
+.endif
+EOF
+       ${MAKE} all PKGSRCDIR="${PKGSRCDIR}" > output
+       if grep -cq "^" output; then
+               cat output
+               atf_fail "variables should not be defined"
+       fi
+       atf_pass
+}
+
+###
+### test2: named template files exist"
+###
+
+atf_test_case test2
+
+test2_head()
+{
+       atf_set "descr" "named template files exist"
+}
+
+test2_body()
+{
+       : ${MAKE:=make}
+       : ${PKGSRCDIR:=/usr/pkgsrc}
+
+       setup
+       echo "### HEADER SCRIPT TEMPLATE ###" > HEADER
+       echo "### DEINSTALL SCRIPT TEMPLATE ###" > DEINSTALL
+       echo "### INSTALL SCRIPT TEMPLATE ###" > INSTALL
+
+       cat > Makefile << 'EOF'
+.include "mk.conf"
+
+HEADER_TEMPLATES+=     ${PKGDIR}/HEADER
+DEINSTALL_TEMPLATES+=  ${PKGDIR}/DEINSTALL
+INSTALL_TEMPLATES+=    ${PKGDIR}/INSTALL
+
+.include "${PKGSRCDIR}/mk/pkgformat/pkg/scripts.mk"
+
+.PHONY: all
+all: _pkgformat-generate-install-scripts
+EOF
+       ${MAKE} all PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
+       local count
+
+       count=$( grep -c "### HEADER SCRIPT TEMPLATE ###" .pkgdb/+DEINSTALL )
+       case $count in
+       0)      cat .pkgdb/+DEINSTALL
+               atf_fail "HEADER template was not used in +DEINSTALL" ;;
+       1)      : "success" ;;
+       *)      cat .pkgdb/+DEINSTALL
+               atf_fail "HEADER template used too many times in +DEINSTALL" ;;
+       esac
+
+       count=$( grep -c "### HEADER SCRIPT TEMPLATE ###" .pkgdb/+INSTALL )
+       case $count in
+       0)      cat .pkgdb/+INSTALL
+               atf_fail "HEADER template was not used in +INSTALL" ;;
+       1)      : "success" ;;
+       *)      cat .pkgdb/+INSTALL
+               atf_fail "HEADER template used too many times in +INSTALL" ;;
+       esac
+
+       count=$( grep -c "### DEINSTALL SCRIPT TEMPLATE ###" .pkgdb/+DEINSTALL )
+       case $count in
+       0)      cat .pkgdb/+DEINSTALL
+               atf_fail "DEINSTALL template was not used in +DEINSTALL" ;;
+       1)      : "success" ;;
+       *)      cat .pkgdb/+DEINSTALL
+               atf_fail "DEINSTALL template used too many times in +DEINSTALL" ;;
+       esac
+
+       count=$( grep -c "### INSTALL SCRIPT TEMPLATE ###" .pkgdb/+INSTALL )
+       case $count in
+       0)      cat .pkgdb/+INSTALL
+               atf_fail "INSTALL template was not used in +INSTALL" ;;
+       1)      : "success" ;;
+       *)      cat .pkgdb/+INSTALL
+               atf_fail "INSTALL template used too many times in +INSTALL" ;;
+       esac
+
+       atf_pass
+}
+
+###
+### test3: DEINSTALL_SRC and INSTALL_SRC
+###
+
+atf_test_case test3
+
+test3_head()
+{
+       atf_set "descr" "DEINSTALL_SRC and INSTALL_SRC"
+}
+
+test3_body()
+{
+       : ${MAKE:=make}
+       : ${PKGSRCDIR:=/usr/pkgsrc}
+
+       setup
+       ( exec > INSTALL )      # empty INSTALL script
+       cat > Makefile << 'EOF'
+.include "mk.conf"
+
+DEINSTALL_SRC= # empty
+INSTALL_SRC=   INSTALL
+
+.include "${PKGSRCDIR}/mk/pkgformat/pkg/scripts.mk"
+
+.PHONY: all
+all: _pkgformat-generate-install-scripts
+EOF
+       ${MAKE} all PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
+
+       if [ -f .pkgdb/+DEINSTALL ]; then
+               find .
+               atf_fail "DEINSTALL_SRC is empty but +DEINSTALL script exists."
+       fi
+
+       if cmp INSTALL .pkgdb/+INSTALL; then
+               : "success"
+       else
+               cat .pkgdb/+INSTALL
+               atf_fail "INSTALL script not based solely on INSTALL_SRC"
+       fi
+
+       atf_pass
+}
+
+atf_init_test_cases()
+{
+       atf_add_test_case test1
+       atf_add_test_case test2
+       atf_add_test_case test3
+}



Home | Main Index | Thread Index | Old Index