Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 May 2020 01:10:17 +0000 (UTC)
From:      Matthias Andree <mandree@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r534314 - head/Tools/scripts
Message-ID:  <202005080110.0481AHdq044876@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mandree
Date: Fri May  8 01:10:16 2020
New Revision: 534314
URL: https://svnweb.freebsd.org/changeset/ports/534314

Log:
  Tools/scripts/bump_revision.pl: chase option rename for getopts().

Modified:
  head/Tools/scripts/bump_revision.pl
  head/Tools/scripts/sed_checked.sh

Modified: head/Tools/scripts/bump_revision.pl
==============================================================================
--- head/Tools/scripts/bump_revision.pl	Fri May  8 01:09:15 2020	(r534313)
+++ head/Tools/scripts/bump_revision.pl	Fri May  8 01:10:16 2020	(r534314)
@@ -109,7 +109,7 @@ my ($portsdir, $INDEX);
 {
     $opt_i = "";
     $opt_u = "";
-    getopts("cgi:lnu:p:");
+    getopts("fgi:lnu:p:");
     $shallow = $opt_l if $opt_l;
     if ($opt_l and $opt_g) {
 	die "Options -g and -l given, which are mutually exclusive. Pick either.";

Modified: head/Tools/scripts/sed_checked.sh
==============================================================================
--- head/Tools/scripts/sed_checked.sh	Fri May  8 01:09:15 2020	(r534313)
+++ head/Tools/scripts/sed_checked.sh	Fri May  8 01:10:16 2020	(r534314)
@@ -1,13 +1,84 @@
 #!/bin/sh
 
-set -e
-/usr/bin/sed -i.bak "$@"
-for x in "${@}" ; do
-    if [ -f "${x}" ]; then
-	if cmp -s "${x}" "${x}".bak ; then
-            if [ ! -z "${REWARNFILE}" ]; then
-                echo sed failed: file content unchanged from backup: ${x#${WRKSRC}/} >> ${REWARNFILE}
-            fi
-        fi
+# Rationale:
+# The ports tree has accumulated quite a bit of REINPLACE_CMD lines
+# in its Makefile. Some of these have gone stale as ports were updated
+# upstream, or as the ports have evolved.
+
+# For DEVELOPERS, we check the effectiveness of REINPLACE_CMD lines
+# by requesting backup files be written, and comparing them against
+# source files.
+
+set -eu
+
+DEBUG=:
+#DEBUG=echo
+
+check_dash_i() {
+    # this must be called from a subshell so as not to clobber $@
+    # WARNING: assumes that -i is given at least once!
+    unset OPTIND
+    $DEBUG >&2 DEBUG: check_dash_i "$@"
+    while getopts :EI:ae:f:i:lnru var ; do
+	$DEBUG >&2 DEBUG: option "$var" '"'"${OPTARG-""}"'"'
+	case "$var" in [iI])
+	    last_i="$OPTARG"
+	esac
+    done
+
+    $DEBUG >&2 DEBUG: last_i='"'"$last_i"'"'
+    printf '"%s"\n' "$last_i"
+}
+
+shadowed="$( (check_dash_i -i.bak "$@") )"
+if [ "$shadowed" != '".bak"' ] ; then
+    echo >&2 "WARNING: $0 -i.bak clobbered by caller's backup suffix $shadowed"
+fi
+
+${SED-/usr/bin/sed} -i.bak "$@"
+check() {
+    issues=0
+    files=0
+    args=
+    for x in "${@}" ; do
+	# we decide very simply whether the argument we are looking at is
+	# a sed command or a file: if it's not a regular file, it must be
+	# a sed argument worth collecting for our warning message,
+	# so that maintainers can identify the failing sed command.
+	#
+	# We cannot easily relate to Makefile lines here.
+	if [ -f "${x}" ]; then
+	    # File? Check if sed was effective.
+	    files=$(($files + 1))
+	    if cmp -s "${x}" "${x}".bak ; then
+		issues=$(($issues + 1))
+		if [ $issues -eq 1 ] ; then
+		    echo "sed failed:${args} ..."
+		fi
+		echo "  - file content unchanged from backup: ${x#${WRKSRC}/}"
+	    fi
+	else
+	    # Not a file? Collect sed(1) command.
+	    args="${args} ${x}"
+	fi
+    done
+
+    if [ ${issues} -gt 0 ] ; then
+	action="review"
+	if [ ${issues} -eq ${files} ] ; then
+	    action=" FIX " # blanks at either end
+	else
+	    action="review"
+	fi
+	echo "--- issues found: ${issues}, files to edit: ${files}, please ${action} ---"
     fi
-done
+}
+
+if [ ! -z "${REWARNFILE}" ] ; then
+    check "$@" | tee -a ${REWARNFILE}
+    # if ${REWARNFILE} is a regular file (not /dev/null) and empty, delete it.
+    if [ -f "${REWARNFILE}" -a ! -s "${REWARNFILE}" ] ; then rm -f "${REWARNFILE}" ; fi
+else
+    check "$@"
+fi
+



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005080110.0481AHdq044876>