[Top][All Lists]

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

Re: [PATCH] tests/test-xalloc-die.sh: Use $EXEEXT.

From: Jim Meyering
Subject: Re: [PATCH] tests/test-xalloc-die.sh: Use $EXEEXT.
Date: Sat, 13 Feb 2010 12:51:34 +0100

Jim Meyering wrote:
> Eric Blake wrote:
>> According to Jim Meyering on 1/14/2010 1:08 AM:
>>> Think of a set-up function that (when $EXEEXT is nonempty)
>>> iterates through the *.$EXEEXT executables in a specified directory...
>>> create_exe_shim_functions ()
>>> {
>>>   case $EXEEXT in
>>>     '') return 0 ;;
>>>     .exe) ;;
>>>     *) echo "$0: unexpected value of $EXEEXT" 1>&2; return 1 ;;
>>>   esac
>> So we still have to pass EXEEXT through TESTS_ENVIRONMENT in
>> modules/*-tests for any test that uses a .sh file.  But other than that,
>> all of our tests-*.sh no longer need to worry about EXEEXT, once they've
>> been converted to use init.sh.  I like it.
>> Or go one step further, do the search for *.exe without regards to
>> $EXEEXT, skipping this case block, and simplifying modules/*-tests.
> I like the idea of not having to modify all modules/*-tests, but have
> two reservations:
>   - I like having no shim-eval overhead when $EXEEXT is empty.
>   - What if a script were to run something named foo.exe _in unix land_?
>     Then if there is also a "foo" executable in that directory, it would
>     mistakenly run "foo" via our shim that creates a foo.exe *function*.
> An alternative would be to make gnulib-tool always add EXEEXT.
>>>     # Remove the .$EXEEXT suffix.
>>>     base=${file%.$EXEEXT}
>> This is not portable to Solaris /bin/sh.  Unless we take the same measures
>> as coreutils to ensure a (mostly) POSIX-compliant shell, I think we are
>> better off using only features supported by common /bin/sh.
> Good point.  Not worth it.
>   base=$(echo "$file" | sed "s/$EXEEXT//")

I've released diffutils, so catching up on some of the backlog ;-)

I wrote most of this a few weeks ago and have just added some comments.
I still have a nit to pick with how new directories are prepended to PATH.
Currently they are prepended in the order in which they're processed,
which puts them in the reverse order of what you'd expect.
  - accept only one name at a time (currently most uses
    require only a single directory, so this isn't disruptive)
  - allow the convenience of multiple directory args, and prepend
    so they appear in the expected order.

But that needn't hold up the change, which should
be a net no-op unless your build defines EXEEXT.

I really dislike the ugly per-function, trailing-underscore-decorated
local variable names I've used, but until we agree that depending on "local"
is ok, I see no alternative.

Review/comments appreciated.

>From 42a6cb8ca77498565c78b40b22c6def9ab8d3c5c Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 18 Jan 2010 08:08:18 +0100
Subject: [PATCH] automatically accommodate programs with the .exe suffix

Automatically arrange for an invocation of "prog" to execute the
program named "prog$EXEEXT" (usually prog.exe).  Thus, all invocations
may use the simpler "prog", yet still work when built on a system
that requires specifying the added suffix.
Do this by constructing a function named "prog" that invokes
"prog.exe" for each .exe file in selected directories.
* tests/init.sh (find_exe_basenames_): New function.
(create_exe_shim_functions_): New function.
(path_prepend_): Use it.
 tests/init.sh |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/tests/init.sh b/tests/init.sh
index 979eb3c..c584b55 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -92,6 +92,56 @@ remove_tmp_()
   exit $__st

+# Given a directory name, DIR, if every entry in it that matches *.exe
+# contains only the specified bytes (see the case stmt below), then print
+# a space-separated list of those names and return 0.  Otherwise, don't
+# print anything and return 1.  Naming constraints apply also to DIR.
+  feb_dir_=$1
+  feb_fail_=0
+  feb_result_=
+  feb_sp_=
+  for feb_file_ in $feb_dir_/*.exe dummy; do
+    case $feb_file_ in
+      dummy) continue;;
+      *[^-a-zA-Z/0-9_.+]*) feb_fail_=1; break;;
+      *) feb_file_=$(echo $feb_file_ | sed "s,^$feb_dir_/,,;"'s/\.exe$//')
+        feb_result_="$feb_result_$feb_sp_$feb_file_";;
+    esac
+    feb_sp_=' '
+  done
+  test $feb_fail_ = 0 && printf %s "$feb_result_"
+  return $feb_fail_
+# Consider the files in directory, $1.
+# For each file name of the form PROG.exe, create a shim function named
+# PROG that simply invokes PROG.exe, then return 0.  If any selected
+# file name or the directory name, $1, contains an unexpected character,
+# define no function and return 1.
+  case $EXEEXT in
+    '') return 0 ;;
+    .exe) ;;
+    *) echo "$0: unexpected \$EXEEXT value: $EXEEXT" 1>&2; return 1 ;;
+  esac
+  base_names_=$(find_exe_basenames_ $1) \
+    || { echo "$0 (exe-shim): skipping directory: $1" 1>&2; return 1; }
+  if test -n "$base_names_"; then
+    for base_ in $base_names_; do
+      # Create a function named $base whose sole job is to invoke
+      # $base_$EXEEXT, assuming its containing dir is already in PATH.
+      eval "$base_() { $base_$EXEEXT"' "$@"; }'
+    done
+  fi
+  return 0
 # Use this function to prepend to PATH an absolute name for each
 # specified, possibly-$initial_cwd_relative, directory.
@@ -108,6 +158,9 @@ path_prepend_()
       *:*) fail_ "invalid path dir: '$abs_path_dir_'";;
+    # Create a function FOO for each FOO.exe in this directory.
+    create_exe_shim_functions_ "$abs_path_dir_"
   export PATH

reply via email to

[Prev in Thread] Current Thread [Next in Thread]