Bug 184039 - Mk/Scripts: fix working with blanks in filenames, handle missing variables
Summary: Mk/Scripts: fix working with blanks in filenames, handle missing variables
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Matthias Andree
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-17 20:20 UTC by Matthias Andree
Modified: 2013-11-23 12:30 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Andree freebsd_committer freebsd_triage 2013-11-17 20:20:00 UTC
Request permission to commit the patch below.

It fixes these issues:
- in qa.sh, properly work with filenames containing blank or tab,
  by setting IFS to just LF

- in check-stagedir.sh, properly detect unset environmental variables,
  and list them all

- in check-stagedir.sh, also list the full prefix as known, not just
  its parents

Fix: Apply this patch in ports/Mk/Scripts/:



### END OF PATCH ###--ZTyKOz6uOvL55LMXGBZA8uOt2hOnnM7rml0mMafLRbneJsX7
Content-Type: text/plain; name="file.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="file.diff"

Index: check-stagedir.sh
===================================================================
--- check-stagedir.sh	(revision 333870)
+++ check-stagedir.sh	(working copy)
@@ -1,5 +1,6 @@
 #!/bin/sh
 # ports/Mk/Scripts/check-stagedir.sh - called from ports/Mk/bsd.stage.mk
+# $FreeBSD$
 
 set -e
 export LC_ALL=C
@@ -21,16 +22,17 @@
 esac
 
 # validate environment
-envfault=0
+envfault=
 for i in STAGEDIR PREFIX LOCALBASE WRKDIR WRKSRC MTREE_FILE \
     TMPPLIST DATADIR DOCSDIR EXAMPLESDIR
 do
-	if eval test -z "\$$i" ; then
-		echo >&2 "Environment variable $i undefined. Aborting."
-		envfault=1
+    if ! ( eval ": \${${i}?}" ) 2>/dev/null ; then
+		envfault="${envfault}${envfault:+" "}${i}"
     fi
 done
-if [ $envfault -ne 0 ] ; then
+if [ -n "$envfault" ] ; then
+	echo "Environment variables $envfault undefined. Aborting." \
+	| fmt >&2
 	exit 1
 fi
 
@@ -85,9 +87,9 @@
 
 	a=${PREFIX}
 	while :; do
+		echo ${a}
 		a=${a%/*}
 		[ -z "${a}" ] && break
-		echo ${a}
 	done
 } > ${WRKDIR}/.mtree
 
Index: qa.sh
===================================================================
--- qa.sh	(revision 333870)
+++ qa.sh	(working copy)
@@ -7,6 +7,9 @@
 	exit 1
 fi
 
+LF=$(printf '\nX')
+LF=${LF%X}
+
 warn() {
 	echo "Warning: $@" >&2
 }
@@ -17,7 +20,7 @@
 
 shebang() {
 	rc=0
-	for f in `find ${STAGEDIR} -type f`; do
+	IFS="$LF" ; for f in `find ${STAGEDIR} -type f`; do
 		interp=$(sed -n -e '1s/^#![[:space:]]*\([^[:space:]]*\).*/\1/p;2q' $f)
 		case "$interp" in
 		"") ;;
@@ -37,7 +40,7 @@
 
 symlinks() {
 	rc=0
-	for l in `find ${STAGEDIR} -type l`; do
+	IFS="$LF" ; for l in `find ${STAGEDIR} -type l`; do
 		link=$(readlink ${l})
 		case "${link}" in
 		${STAGEDIR}*) err "Bad symlinks ${l} pointing inside the stage directory"
@@ -50,7 +53,7 @@
 paths() {
 	rc=0
 	dirs="${STAGEDIR} ${WRKDIR}"
-	for f in `find ${STAGEDIR} -type f`;do
+	IFS="$LF" ; for f in `find ${STAGEDIR} -type f`;do
 		for d in ${dirs}; do
 			if grep -q ${d} ${f} ; then
 				err "${f} is referring to ${d}"
@@ -64,7 +67,7 @@
 stripped() {
 	[ -x /usr/bin/file ] || return # this is fatal
 	[ -n "${STRIP}" ] || return 0
-	for f in `find ${STAGEDIR} -type f`; do
+	IFS="$LF" ; for f in `find ${STAGEDIR} -type f`; do
 		output=`/usr/bin/file ${f}`
 		case "${output}" in
 		*:*\ ELF\ *,\ not\ stripped*) warn "${f} is not stripped consider using \${STRIP_CMD}";;
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2013-11-17 20:20:06 UTC
Maintainer of Mk/Scripts,

Please note that PR ports/184039 has just been submitted.

If it contains a patch for an upgrade, an enhancement or a bug fix
you agree on, reply to this email stating that you approve the patch
and a committer will take care of it.

The full text of the PR can be found at:
    http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/184039

-- 
Edwin Groothuis via the GNATS Auto Assign Tool
edwin@FreeBSD.org
Comment 2 Edwin Groothuis freebsd_committer freebsd_triage 2013-11-17 20:20:07 UTC
State Changed
From-To: open->feedback

Awaiting maintainers feedback (via the GNATS Auto Assign Tool)
Comment 3 Matthias Andree freebsd_committer freebsd_triage 2013-11-17 21:36:08 UTC
Responsible Changed
From-To: freebsd-ports-bugs->portmgr

assign to maintainer (portmgr)
Comment 4 Baptiste Daroussin freebsd_committer freebsd_triage 2013-11-23 11:00:05 UTC
Responsible Changed
From-To: portmgr->mandree

Approved
Comment 5 dfilter service freebsd_committer freebsd_triage 2013-11-23 12:23:27 UTC
Author: mandree
Date: Sat Nov 23 12:23:19 2013
New Revision: 334663
URL: http://svnweb.freebsd.org/changeset/ports/334663

Log:
  - in qa.sh, properly work with filenames containing blank or tab,
    by setting IFS to just LF
  
  - in check-stagedir.sh, properly detect unset environmental variables,
    and list them all
  
  - in check-stagedir.sh, also list the full prefix as known, not just
    its parents
  
  PR:		184039
  Approved by:	portmgr (bapt)

Modified:
  head/Mk/Scripts/check-stagedir.sh   (contents, props changed)
  head/Mk/Scripts/qa.sh

Modified: head/Mk/Scripts/check-stagedir.sh
==============================================================================
--- head/Mk/Scripts/check-stagedir.sh	Sat Nov 23 12:16:10 2013	(r334662)
+++ head/Mk/Scripts/check-stagedir.sh	Sat Nov 23 12:23:19 2013	(r334663)
@@ -1,5 +1,6 @@
 #!/bin/sh
 # ports/Mk/Scripts/check-stagedir.sh - called from ports/Mk/bsd.stage.mk
+# $FreeBSD$
 
 set -e
 export LC_ALL=C
@@ -21,16 +22,17 @@ case "$1" in
 esac
 
 # validate environment
-envfault=0
+envfault=
 for i in STAGEDIR PREFIX LOCALBASE WRKDIR WRKSRC MTREE_FILE \
     TMPPLIST DATADIR DOCSDIR EXAMPLESDIR
 do
-	if eval test -z "\$$i" ; then
-		echo >&2 "Environment variable $i undefined. Aborting."
-		envfault=1
+    if ! ( eval ": \${${i}?}" ) 2>/dev/null ; then
+		envfault="${envfault}${envfault:+" "}${i}"
     fi
 done
-if [ $envfault -ne 0 ] ; then
+if [ -n "$envfault" ] ; then
+	echo "Environment variables $envfault undefined. Aborting." \
+	| fmt >&2
 	exit 1
 fi
 
@@ -85,9 +87,9 @@ fi
 
 	a=${PREFIX}
 	while :; do
+		echo ${a}
 		a=${a%/*}
 		[ -z "${a}" ] && break
-		echo ${a}
 	done
 } > ${WRKDIR}/.mtree
 

Modified: head/Mk/Scripts/qa.sh
==============================================================================
--- head/Mk/Scripts/qa.sh	Sat Nov 23 12:16:10 2013	(r334662)
+++ head/Mk/Scripts/qa.sh	Sat Nov 23 12:23:19 2013	(r334663)
@@ -7,6 +7,9 @@ if [ -z "${STAGEDIR}" -o -z "${PREFIX}" 
 	exit 1
 fi
 
+LF=$(printf '\nX')
+LF=${LF%X}
+
 warn() {
 	echo "Warning: $@" >&2
 }
@@ -17,7 +20,7 @@ err() {
 
 shebang() {
 	rc=0
-	for f in `find ${STAGEDIR} -type f`; do
+	IFS="$LF" ; for f in `find ${STAGEDIR} -type f`; do
 		interp=$(sed -n -e '1s/^#![[:space:]]*\([^[:space:]]*\).*/\1/p;2q' $f)
 		case "$interp" in
 		"") ;;
@@ -37,7 +40,7 @@ shebang() {
 
 symlinks() {
 	rc=0
-	for l in `find ${STAGEDIR} -type l`; do
+	IFS="$LF" ; for l in `find ${STAGEDIR} -type l`; do
 		link=$(readlink ${l})
 		case "${link}" in
 		${STAGEDIR}*) err "Bad symlinks ${l} pointing inside the stage directory"
@@ -50,7 +53,7 @@ symlinks() {
 paths() {
 	rc=0
 	dirs="${STAGEDIR} ${WRKDIR}"
-	for f in `find ${STAGEDIR} -type f`;do
+	IFS="$LF" ; for f in `find ${STAGEDIR} -type f`;do
 		for d in ${dirs}; do
 			if grep -q ${d} ${f} ; then
 				err "${f} is referring to ${d}"
@@ -64,7 +67,7 @@ paths() {
 stripped() {
 	[ -x /usr/bin/file ] || return # this is fatal
 	[ -n "${STRIP}" ] || return 0
-	for f in `find ${STAGEDIR} -type f`; do
+	IFS="$LF" ; for f in `find ${STAGEDIR} -type f`; do
 		output=`/usr/bin/file ${f}`
 		case "${output}" in
 		*:*\ ELF\ *,\ not\ stripped*) warn "${f} is not stripped consider using \${STRIP_CMD}";;
_______________________________________________
svn-ports-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-ports-all
To unsubscribe, send any mail to "svn-ports-all-unsubscribe@freebsd.org"
Comment 6 Matthias Andree freebsd_committer freebsd_triage 2013-11-23 12:23:30 UTC
State Changed
From-To: feedback->closed

Committed. Thanks!