Skip to content

Commit 61096cc

Browse files
committed
opal_functions.m4: fix OPAL_WHICH
Make OPAL_WHICH properly respond to absolute pathnames, and relative pathnames that contain one or more path separators. See comment in the code explaining the three cases. Prior to this commit, passing /path/to/some/valid/executable into OPAL_WHICH would result in $2 not being set. Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
1 parent f882930 commit 61096cc

File tree

1 file changed

+52
-17
lines changed

1 file changed

+52
-17
lines changed

config/opal_functions.m4

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -480,24 +480,59 @@ dnl #######################################################################
480480
# of the assignment in foo=`which <prog>`). This macro ensures that we
481481
# get a sane executable value.
482482
AC_DEFUN([OPAL_WHICH],[
483-
# 1 is the variable name to do "which" on
484-
# 2 is the variable name to assign the return value to
483+
# 1 is the variable name to do "which" on
484+
# 2 is the variable name to assign the return value to
485+
486+
OPAL_VAR_SCOPE_PUSH([opal_prog opal_file opal_dir opal_sentinel])
487+
488+
opal_prog=$1
489+
490+
# There are 3 cases:
491+
492+
# 1. opal_prog is an absolute filename. If that absolute filename
493+
# exists and is executable, return $2 with that name. Otherwise,
494+
# $2 is unchanged.
495+
496+
# 2. opal_prog is a relative filename (i.e., it contains one or
497+
# more /, but does not begin with a /). If that file exists
498+
# relative to where we are right now in the filesystem and is
499+
# executable, return the absolute path of that value in $2.
500+
# Otherwise, $2 is unchanged.
501+
502+
# 3. opal_prog contains no /. Search the PATH for an excutable
503+
# with the appropriate name. If found, return the absolute path
504+
# in $2. Otherwise, $2 is unchanged.
505+
506+
# Note that these three cases are exactly what which(1) does.
507+
508+
# Note the double square brackets around the case expressions for
509+
# m4 escaping.
510+
case $opal_prog in
511+
[[\\/]]* | ?:[[\\/]]* )
512+
# Case 1: absolute
513+
AS_IF([test -x "$opal_prog"],
514+
[$2=$opal_prog])
515+
;;
516+
517+
*[[\\/]]*)
518+
# Case 2: relative with 1 or more /
519+
AS_IF([test -x "$opal_prog"],
520+
[$2="$cwd/$opal_prog"])
521+
;;
522+
523+
*)
524+
# Case 3: no / at all
525+
IFS_SAVE=$IFS
526+
IFS=$PATH_SEPARATOR
527+
for opal_dir in $PATH; do
528+
AS_IF([test -x "$opal_dir/$opal_prog"],
529+
[$2="$opal_dir/$opal_prog"])
530+
done
531+
IFS=$IFS_SAVE
532+
;;
533+
esac
485534

486-
OPAL_VAR_SCOPE_PUSH([opal_prog opal_file opal_dir opal_sentinel])
487-
488-
opal_prog=$1
489-
490-
IFS_SAVE=$IFS
491-
IFS="$PATH_SEPARATOR"
492-
for opal_dir in $PATH; do
493-
if test -x "$opal_dir/$opal_prog"; then
494-
$2="$opal_dir/$opal_prog"
495-
break
496-
fi
497-
done
498-
IFS=$IFS_SAVE
499-
500-
OPAL_VAR_SCOPE_POP
535+
OPAL_VAR_SCOPE_POP
501536
])dnl
502537

503538
dnl #######################################################################

0 commit comments

Comments
 (0)