From: Eric Blake Date: Wed, 19 Nov 2008 03:58:19 +0000 (-0700) Subject: Alter default value of AS_EXIT. X-Git-Tag: v2.63b~94 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e84b404ff0cfc9ab0b56a538fa17283d6688284e;p=thirdparty%2Fautoconf.git Alter default value of AS_EXIT. * lib/m4sugar/m4sh.m4 (_AS_EXIT_PREPARE): Let as_func_exit parameter be optional. (AS_EXIT): Use it to make better default. (_AS_DETECT_BETTER_SHELL): Use new default. * bin/autoconf.as (exit_missing_arg, getopt): Likewise. * lib/autoconf/status.m4 (AC_OUTPUT): Likewise. * tests/m4sh.at (AS@&t@_EXIT): Update test. * doc/autoconf.texi (Common Shell Constructs) : Mention new default behavior. (Limitations of Builtins) : Adjust to use new default. * NEWS: Mention the semantic change. Suggested by Ralf Wildenhues. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index a817ee220..7ce0fa59d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2008-11-18 Eric Blake + Alter default value of AS_EXIT. + * lib/m4sugar/m4sh.m4 (_AS_EXIT_PREPARE): Let as_func_exit + parameter be optional. + (AS_EXIT): Use it to make better default. + (_AS_DETECT_BETTER_SHELL): Use new default. + * bin/autoconf.as (exit_missing_arg, getopt): Likewise. + * lib/autoconf/status.m4 (AC_OUTPUT): Likewise. + * tests/m4sh.at (AS@&t@_EXIT): Update test. + * doc/autoconf.texi (Common Shell Constructs) : Mention + new default behavior. + (Limitations of Builtins) : Adjust to use new default. + * NEWS: Mention the semantic change. + Suggested by Ralf Wildenhues. + Update example to match actual Tru64 behavior. * doc/autoconf.texi (Limitations of Builtins) : Correct the example. diff --git a/NEWS b/NEWS index b67d82ce6..6ef072591 100644 --- a/NEWS +++ b/NEWS @@ -33,7 +33,9 @@ GNU Autoconf NEWS - User visible changes. AS_LINENO_PREPARE AS_ME_PREPARE AS_SET_STATUS AS_VAR_APPEND AS_VAR_ARITH AS_VAR_COPY -** The following m4sh macros are documented now: +** The following m4sh macros are documented now, but in some cases + with slightly different semantics than what the previous + undocumented version had: AS_ECHO AS_ECHO_N AS_EXIT AS_LITERAL_IF AS_UNSET AS_VAR_IF AS_VAR_POPDEF AS_VAR_PUSHDEF AS_VAR_SET AS_VAR_SET_IF AS_VAR_TEST_SET AS_VERSION_COMPARE diff --git a/bin/autoconf.as b/bin/autoconf.as index c678e55ae..c6bb0f653 100644 --- a/bin/autoconf.as +++ b/bin/autoconf.as @@ -81,7 +81,7 @@ Try \`$as_me --help' for more information." exit_missing_arg=' AS_ECHO(["$as_me: option \`$[1]'\'' requires an argument"]) >&2 AS_ECHO(["$help"]) >&2 - AS_EXIT([1]) + AS_EXIT ' # restore font-lock: " # Variables. @@ -156,7 +156,7 @@ while test $# -gt 0 ; do exec >&2 AS_ECHO(["$as_me: invalid option $[1]"]) AS_ECHO(["$help"]) - AS_EXIT([1]) ;; + AS_EXIT ;; * ) break ;; esac @@ -175,7 +175,7 @@ case $# in infile=configure.in else AS_ECHO(["$as_me: no input file"]) >&2 - AS_EXIT([1]) + AS_EXIT fi test -z "$traces" && test -z "$outfile" && outfile=configure;; 1) @@ -183,7 +183,7 @@ case $# in *) exec >&2 AS_ECHO(["$as_me: invalid number of arguments."]) AS_ECHO(["$help"]) - AS_EXIT([1]) ;; + AS_EXIT ;; esac # Unless specified, the output is stdout. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 3cc165bb6..0382412d4 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -12010,12 +12010,15 @@ for portability, should not include more than one newline. The bytes of Redirections can be placed outside the macro invocation. @end defmac -@defmac AS_EXIT (@dvar{status, 1}) +@defmac AS_EXIT (@dvar{status, max($?/1)}) @asindex{EXIT} -Emit code to exit the shell with @var{status}. This works around shells -that see the exit status of the command prior to @code{exit} inside a -@samp{trap 0} handler (@pxref{Limitations of Builtins, , Limitations of -Shell Builtins}). +Emit code to exit the shell with @var{status}. If @var{status} is +omitted, then @samp{$?} is used, except that a status of zero is +converted to @samp{1}. To exit with successful status, it is necessary +to supply an explicit @var{status} that expands to @samp{0}. This macro +works around shells that see the exit status of the command prior to +@code{exit} inside a @samp{trap 0} handler (@pxref{Limitations of +Builtins, , Limitations of Shell Builtins}). @end defmac @defmac AS_IF (@var{test1}, @ovar{run-if-true1}, @dots{}, @ovar{run-if-false}) @@ -15447,7 +15450,7 @@ $ @kbd{sh -c 'set -e; trap '\''echo $?'\'' 0; false'} @noindent Thus, when writing a script in M4sh, rather than trying to rely on -@samp{set -e}, it is better to append @samp{|| AS_EXIT([$?])} to any +@samp{set -e}, it is better to append @samp{|| AS_EXIT} to any statement where it is desirable to abort on failure. @item @command{shift} diff --git a/lib/autoconf/status.m4 b/lib/autoconf/status.m4 index c134bb7b5..fe7835832 100644 --- a/lib/autoconf/status.m4 +++ b/lib/autoconf/status.m4 @@ -1307,7 +1307,7 @@ if test "$no_create" != yes; then exec AS_MESSAGE_LOG_FD>>config.log # Use ||, not &&, to avoid exiting from the if with $? = 1, which # would make configure fail if this is the last instruction. - $ac_cs_success || AS_EXIT([1]) + $ac_cs_success || AS_EXIT fi dnl config.status should not do recursion. AC_PROVIDE_IFELSE([AC_CONFIG_SUBDIRS], [_AC_OUTPUT_SUBDIRS()])dnl diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4 index f056ee315..c8001081f 100644 --- a/lib/m4sugar/m4sh.m4 +++ b/lib/m4sugar/m4sh.m4 @@ -270,7 +270,7 @@ _m4_defn([AC_PACKAGE_BUGREPORT]), [], [and _m4_defn([AC_PACKAGE_BUGREPORT])])]) Then install a modern shell, or manually run the script under such a shell if you do have one.], [$[]0: ], [], [62])") fi - AS_EXIT(1)])]) + AS_EXIT])]) fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL @@ -539,19 +539,23 @@ m4_defun([_AS_EXIT_PREPARE], [AS_FUNCTION_DESCRIBE([as_func_set_status], [STATUS], [Set $? to STATUS, without forking.])], [ return $[]1])]dnl [AS_REQUIRE_SHELL_FN([as_func_exit], - [AS_FUNCTION_DESCRIBE([as_func_exit], [STATUS], - [Exit the shell with STATUS, even in a "trap 0" or "set -e" context.])], -[ set +e - as_func_set_status $[]1 - exit $[]1])])#_AS_EXIT_PREPARE + [AS_FUNCTION_DESCRIBE([as_func_exit], [[[STATUS]]], + [Exit the shell with STATUS, even in a "trap 0" or "set -e" context. + If STATUS is omitted, use the maximum of $? and 1.])], +[ as_status=$? + set +e + test $as_status = 0 && as_status=1 + as_func_set_status ${1-$as_status} + exit ${1-$as_status}])])#_AS_EXIT_PREPARE -# AS_EXIT([EXIT-CODE = 1]) -# ------------------------ +# AS_EXIT([EXIT-CODE = $?/1]) +# --------------------------- # Exit, with status set to EXIT-CODE in the way that it's seen -# within "trap 0", and without interference from "set -e". +# within "trap 0", and without interference from "set -e". If +# EXIT-CODE is omitted, then use $?, except use 1 if $? is 0. m4_defun([AS_EXIT], -[AS_REQUIRE([_AS_EXIT_PREPARE])[]as_func_exit m4_default([$1], 1)]) +[AS_REQUIRE([_AS_EXIT_PREPARE])[]as_func_exit[]m4_ifval([$1], [ $1])]) # AS_FOR(MACRO, SHELL-VAR, [LIST = "$@"], [BODY = :]) diff --git a/tests/m4sh.at b/tests/m4sh.at index 85ad5d8b1..1f39bb10c 100644 --- a/tests/m4sh.at +++ b/tests/m4sh.at @@ -305,11 +305,12 @@ AT_DATA_M4SH([script.as], [[AS_INIT test x${1} = xa && AS_EXIT test x${1} = xb && AS_EXIT([${2}]) -test x${1} = xc && trap 's=$?; echo $s; AS_EXIT([$s])' 0 -test x${2} = xd && set -e +test x${1} = xc && { AS_SET_STATUS([${2}]); AS_EXIT; } +test x${1} = xd && trap 's=$?; echo $s; AS_EXIT([$s])' 0 +test x${2} = xe && set -e AS_SET_STATUS([3]) dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls -test x${2} = xd \ +test x${2} = xe \ && { echo 'skipping rest of test: set -e support is lousy'; exit 77; } AS_SET_STATUS([4]) ]]) @@ -317,9 +318,12 @@ AS_SET_STATUS([4]) AT_CHECK_M4SH AT_CHECK([./script], [4]) AT_CHECK([./script a], [1]) -AT_CHECK([./script b], [0]) +AT_CHECK([./script b], [1]) +AT_CHECK([./script b 0], [0]) AT_CHECK([./script b 2], [2]) -AT_CHECK([./script c], [4], [[4 +AT_CHECK([./script c 0], [1]) +AT_CHECK([./script c 2], [2]) +AT_CHECK([./script d], [4], [[4 ]]) dnl If we got to this point without a FAIL, then AS_EXIT at least works. dnl The rest of this test relies on semi-decent 'set -e' support, even @@ -327,8 +331,8 @@ dnl though m4sh in general should not try to rely on it because of dnl portability nightmares on what constructs are considered errors across dnl various shells; therefore, an overall SKIP result is desirable on dnl broken shells like Solaris /bin/sh. -AT_CHECK([./script '' d], [3]) -AT_CHECK([./script c d], [3], [[3 +AT_CHECK([./script '' e], [3]) +AT_CHECK([./script d e], [3], [[3 ]]) AT_CLEANUP