pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/R2pkg/files pkgtools/R2pkg: clean up shell pr...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/f7aecb09d3ef
branches:  trunk
changeset: 403023:f7aecb09d3ef
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Oct 19 17:15:00 2019 +0000

description:
pkgtools/R2pkg: clean up shell program

diffstat:

 pkgtools/R2pkg/files/R2pkg.sh |  241 ++++++++++++++++++-----------------------
 1 files changed, 105 insertions(+), 136 deletions(-)

diffs (truncated from 406 to 300 lines):

diff -r b4d97a7765f2 -r f7aecb09d3ef pkgtools/R2pkg/files/R2pkg.sh
--- a/pkgtools/R2pkg/files/R2pkg.sh     Sat Oct 19 17:08:12 2019 +0000
+++ b/pkgtools/R2pkg/files/R2pkg.sh     Sat Oct 19 17:15:00 2019 +0000
@@ -1,5 +1,5 @@
 #!/bin/sh
-# $NetBSD: R2pkg.sh,v 1.10 2019/10/19 16:18:55 rillig Exp $
+# $NetBSD: R2pkg.sh,v 1.11 2019/10/19 17:15:00 rillig Exp $
 #
 # Copyright (c) 2014,2015,2016,2017,2018,2019
 #      Brook Milligan.  All rights reserved.
@@ -34,116 +34,93 @@
 
 set -u
 
-NAME="R2pkg"
-VERS="@VERS@"
+name="R2pkg"
+vers="@VERS@"
 
-R2PKG=${0}
+r2pkg=$0
 
-USAGE="${NAME} [-cDehqruVv] [-E editor] [-M maintainer] [package] -- create an R package for pkgsrc"
+usage="$name [-cDehqruVv] [-E editor] [-M maintainer] [package] -- create an R package for pkgsrc"
 
-: ${CRAN_URL:=ftp://cran.r-project.org}
-: ${PKGEDITOR:=${EDITOR:=vi}}
-: ${TMPDIR:=/tmp}
+: "${CRAN_URL:=ftp://cran.r-project.org}";
+: "${PKGEDITOR:=${EDITOR:=vi}}"
+: "${TMPDIR:=/tmp}"
 
 # Substituted by pkgsrc at pre-configure time.
-MAKE=@MAKE@
-EDIT=1
-LEVEL=0
-MAINTAINER_EMAIL=pkgsrc-users%NetBSD.org@localhost
-PID=$$
-QUIET=false
-RECURSIVE=false
-UPDATE=false
-VERBOSE=0
+make=@MAKE@
+level=0
+maintainer_email="pkgsrc-users%NetBSD.org@localhost"
+pid=$$
+quiet=false
+recursive=false
+update=false
+use_editor=yes
+verbose=0
 
-DESCRIPTION=no
+keep_description=no
 
 args=""
 while getopts cDehqruVvE:M:L:P: arg
 do
-    case ${arg} in
+    case $arg in
        # options without arguments
-       c) args="${args} ${arg}"; UPDATE=false;;
-       D) args="${args} ${arg}"; DESCRIPTION=yes;;
-       e) args="${args} ${arg}"; EDIT=0;;
-       h) echo "${USAGE}"; exit 0;;
-       q) args="${args} ${arg}"; QUIET=true;;
-       r) args="${args} ${arg}"; RECURSIVE=true;;
-       u) args="${args} ${arg}"; UPDATE=true;;
-       V) echo "${NAME} v${VERS}"; exit 0;;
-       v) args="${args} ${arg}"; VERBOSE=$((VERBOSE + 1));;
+       c) args="$args $arg"; update=false;;
+       D) args="$args $arg"; keep_description=yes;;
+       e) args="$args $arg"; use_editor=no;;
+       h) echo "$usage"; exit 0;;
+       q) args="$args $arg"; quiet=true;;
+       r) args="$args $arg"; recursive=true;;
+       u) args="$args $arg"; update=true;;
+       V) echo "$name v$vers"; exit 0;;
+       v) args="$args $arg"; verbose=$((verbose + 1));;
        # options taking arguments
-       E) args="${args} ${arg} ${OPTARG}"; PKGEDITOR=${OPTARG};;
-       M) args="${args} ${arg} ${OPTARG}"; MAINTAINER_EMAIL=${OPTARG};;
+       E) args="$args $arg $OPTARG"; PKGEDITOR=$OPTARG;;
+       M) args="$args $arg $OPTARG"; maintainer_email=$OPTARG;;
        # options for recursion; only for internal use
-       L) LEVEL=${OPTARG};;
-       P) PID=${OPTARG};;
+       L) level=$((OPTARG + 0));;
+       P) pid=$((OPTARG + 0));;
        # unknown options
-       \?) echo "${USAGE}" 1>&2; exit 1;;
+       \?) echo "$usage" 1>&2; exit 1;;
     esac
 done
 shift $((OPTIND - 1))
 
-# Update ${args} for recursive call
-args="${args} -L $((LEVEL + 1)) -P ${PID}"
+# Update $args for recursive call
+args="$args -L $((level + 1)) -P $pid"
 
 if [ ${#} -eq 0 ]; then
-    RPKG=$(basename "$(pwd)" | sed -e 's/^R-//')
+    rpkg=$(basename "$(pwd)" | sed -e 's/^R-//')
 elif [ ${#} -eq 1 ]; then
-    RPKG=${1}
+    rpkg=$1
 else
     echo "Error: multiple package names given." 1>&2
-    echo "${USAGE}" 1>&2
+    echo "$usage" 1>&2
     exit 1
 fi
 
-R_FILE=${TMPDIR}/R2pkg.$$.R
-
-if [ ${UPDATE} = true ] && [ -r Makefile ]; then
-    BANNER_MSG="[ ${LEVEL} ] ===> Updating R package R-${RPKG} in $(pwd)"
+if [ $update = true ] && [ -r Makefile ]; then
+    banner_msg="[ $level ] ===> Updating R package R-$rpkg in $(pwd)"
 else
-    BANNER_MSG="[ ${LEVEL} ] ===> Creating R package R-${RPKG} in $(pwd)"
+    banner_msg="[ $level ] ===> Creating R package R-$rpkg in $(pwd)"
 fi
 
-PACKAGES_LIST=${TMPDIR}/R2pkg.packages.${PID}
-DEPENDENCY_LIST=${TMPDIR}/R2pkg.depends.${PID}
+packages_list=$TMPDIR/R2pkg.packages.$pid
+dependency_list=$TMPDIR/R2pkg.depends.$pid
 
-if [ ${QUIET} = true ]; then
-    STDOUT_MAKESUM=">/dev/null"
-    STDOUT_EXTRACT=">/dev/null"
-    QUIET_CURL="TRUE"
-    ECHO_BANNER=":"
-    ECHO_DONE=":"
-    ECHO_FETCH=":"
-    ECHO_EXTRACT=":"
-elif [ ${VERBOSE} -eq 0 ]; then
-    STDOUT_MAKESUM=">/dev/null"
-    STDOUT_EXTRACT=">/dev/null"
-    QUIET_CURL="TRUE"
-    ECHO_BANNER="echo"
-    ECHO_DONE=":"
-    ECHO_FETCH=":"
-    ECHO_EXTRACT="echo"
-elif [ ${VERBOSE} -eq 1 ]; then
-    STDOUT_MAKESUM=">/dev/null"
-    STDOUT_EXTRACT=">/dev/null"
-    QUIET_CURL="TRUE"
-    ECHO_BANNER="echo"
-    ECHO_DONE="echo"
-    ECHO_FETCH="echo"
-    ECHO_EXTRACT="echo"
-else
-    STDOUT_MAKESUM=""
-    STDOUT_EXTRACT=""
-    QUIET_CURL="FALSE"
-    ECHO_BANNER="echo"
-    ECHO_DONE="echo"
-    ECHO_FETCH="echo"
-    ECHO_EXTRACT="echo"
+echo_verbose0() { echo "$@"; }
+echo_verbose1() { :; }
+show_verbose2() { "$@" >/dev/null; }
+quiet_curl="TRUE"
+if [ $quiet = true ]; then
+    echo_verbose0() { :; }
+elif [ $verbose -eq 1 ]; then
+    echo_verbose1() { echo "$@"; }
+elif [ $verbose -gt 1 ]; then
+    echo_verbose1() { echo "$@"; }
+    show_verbose2() { "$@"; }
+    quiet_curl="FALSE"
 fi
 
-CRAN_PACKAGES=pub/R/web/packages
-RPKG_DESCRIPTION_URL=${CRAN_URL}/${CRAN_PACKAGES}/${RPKG}/DESCRIPTION
+rpkg_description_url=$CRAN_URL/pub/R/web/packages/$rpkg/DESCRIPTION
 
 exists ()
 {
@@ -160,10 +137,10 @@
 
 check_for_no_recursion ()
 {
-    touch "${PACKAGES_LIST}"
-    grep -E -q -e "${RPKG}" "${PACKAGES_LIST}" \
+    touch "$packages_list"
+    grep -E -q -e "$rpkg" "$packages_list" \
        && echo "ERROR: circular dependency" 1>&2
-    echo "${RPKG}" >> "${PACKAGES_LIST}"
+    echo "$rpkg" >> "$packages_list"
 }
 
 preserve_original_content ()
@@ -185,63 +162,56 @@
 
 make_package ()
 {
-    env LEVEL="${LEVEL}" RPKG="${RPKG}" PACKAGES_LIST="${PACKAGES_LIST}" \
-       R2PKG="${R2PKG}" ARGS="${args}" RECURSIVE="${RECURSIVE}" \
-       UPDATE="${UPDATE}" DEPENDENCY_LIST="${DEPENDENCY_LIST}" \
-       MAINTAINER_EMAIL="${MAINTAINER_EMAIL}" \
-       RPKG_DESCRIPTION_URL="${RPKG_DESCRIPTION_URL}" \
-       QUIET_CURL="${QUIET_CURL}" \
+    env LEVEL="$level" rpkg="$rpkg" PACKAGES_LIST="$packages_list" \
+       R2PKG="$r2pkg" ARGS="$args" RECURSIVE="$recursive" \
+       UPDATE="$update" DEPENDENCY_LIST="$dependency_list" \
+       MAINTAINER_EMAIL="$maintainer_email" \
+       RPKG_DESCRIPTION_URL="$rpkg_description_url" \
+       QUIET_CURL="$quiet_curl" \
        LC_ALL="C" \
        Rscript --no-save -e "source('@LIBDIR@/R2pkg.R'); main()"
     retval=${?}
-    if [ ${retval} -ne 0 ]; then
-       echo "ERROR: making ${RPKG} package failed." 1>&2
+    if [ $retval -ne 0 ]; then
+       echo "ERROR: making $rpkg package failed." 1>&2
     fi
-    return ${retval}
+    return $retval
 }
 
 edit_Makefile ()
 {
-    if [ ${EDIT} -ne 0 ] && [ -s Makefile ]; then
-       ${PKGEDITOR} Makefile
+    if [ $use_editor = yes ] && [ -s Makefile ]; then
+       $PKGEDITOR Makefile
     fi
 }
 
 edit_DESCR ()
 {
-    if [ ${EDIT} -ne 0 ] && [ -s DESCR ]; then
-       ${PKGEDITOR} DESCR
+    if [ $use_editor = yes ] && [ -s DESCR ]; then
+       $PKGEDITOR DESCR
     fi
 }
 
 create_distinfo ()
 {
-    ${ECHO_FETCH} "==> Fetching R-${RPKG} ..."
-    MAKE_CMD="${MAKE} makesum ${STDOUT_MAKESUM}"
-    eval "${MAKE_CMD}"
-    error=${?}
-    if [ ${error} -eq 0 ]; then
-       MAKE_CMD="${MAKE} makepatchsum ${STDOUT_MAKESUM}"
-       eval "${MAKE_CMD}"
-       error=${?}
-    fi
-    return ${error}
+    echo_verbose1 "==> Fetching R-$rpkg ..."
+    show_verbose2 "$make" "makesum" || return $?
+    show_verbose2 "$make" "makepatchsum" || return $?
+    return 0
 }
 
 create_buildlink3_mk ()
 {
     if [ -f buildlink3.mk.orig ]; then
-       PKGVERSION=$(${MAKE} show-var VARNAME=PKGVERSION)
-       sed -E -e "/BUILDLINK_API_DEPENDS\./s/[[:digit:].]+$/${PKGVERSION}/" \
+       PKGVERSION=$($make show-var VARNAME=PKGVERSION)
+       sed -E -e "/BUILDLINK_API_DEPENDS\./s/[[:digit:].]+$/$PKGVERSION/" \
            buildlink3.mk.orig > buildlink3.mk
     fi
 }
 
 extract ()
 {
-    ${ECHO_EXTRACT} "[ ${LEVEL} ] Extracting R-${RPKG} ..."
-    MAKE_CMD="env SKIP_DEPENDS=yes ${MAKE} clean extract ${STDOUT_EXTRACT}"
-    eval "${MAKE_CMD}"
+    echo_verbose0 "[ $level ] Extracting R-$rpkg ..."
+    show_verbose2 env SKIP_DEPENDS=yes "$make" clean extract
 }
 
 check_license ()
@@ -256,15 +226,15 @@
        if [ -s LICENSE ]; then
            # ninka -d LICENSE
            cp work/*/LICENSE .
-           printf '%s' "[ ${LEVEL} ] Current license: "
+           printf '%s' "[ $level ] Current license: "
            grep LICENSE Makefile
-           echo "[ ${LEVEL} ] Please check it against the following:"
+           echo "[ $level ] Please check it against the following:"
            cat LICENSE
        else
            rm LICENSE
-           sed -E -e 's/[[:blank:]]+#[[:blank:]]+\+ file LICENSE[[:blank:]]+.*$//' Makefile > Makefile.$$ \
-               && mv Makefile.$$ Makefile
-           grep -q "file LICENSE" Makefile && echo "[ ${LEVEL} ] 'file LICENSE' in Makefile but no relevant license information"
+           sed -E -e 's/[[:blank:]]+#[[:blank:]]+\+ file LICENSE[[:blank:]]+.*$//' Makefile > Makefile.$pid \
+               && mv Makefile.$pid Makefile
+           grep -q "file LICENSE" Makefile && echo "[ $level ] 'file LICENSE' in Makefile but no relevant license information"
        fi



Home | Main Index | Thread Index | Old Index