Change the semantics of AS_EXIT without argument.

* lib/m4sugar/m4sh.m4 (_AS_EXIT_PREPARE): When defaulting, use $?
even if it is 0.
(AS_ERROR): Guarantee non-zero status.
* bin/autoconf.as (exit_missing_arg, getopt): Revert prior change;
we want non-zero status.
* tests/m4sh.at (AS@&t@_EXIT): Update test accordingly.
* doc/autoconf.texi (Common Shell Constructs) <AS_EXIT>: Update
the documentation.
<AS_SET_STATUS>: Don't overly restrict implementation.
(Printing Messages) <AC_MSG_ERROR>: Describe better default.
Suggestions by Paolo Bonzini and Ralf Wildenhues.

Signed-off-by: Eric Blake <ebb9@byu.net>
This commit is contained in:
Eric Blake 2008-11-21 08:12:12 -07:00
parent 26ba3d5318
commit bbc3dc81cc
5 changed files with 48 additions and 29 deletions

View File

@ -1,3 +1,18 @@
2008-11-21 Eric Blake <ebb9@byu.net>
Change the semantics of AS_EXIT without argument.
* lib/m4sugar/m4sh.m4 (_AS_EXIT_PREPARE): When defaulting, use $?
even if it is 0.
(AS_ERROR): Guarantee non-zero status.
* bin/autoconf.as (exit_missing_arg, getopt): Revert prior change;
we want non-zero status.
* tests/m4sh.at (AS@&t@_EXIT): Update test accordingly.
* doc/autoconf.texi (Common Shell Constructs) <AS_EXIT>: Update
the documentation.
<AS_SET_STATUS>: Don't overly restrict implementation.
(Printing Messages) <AC_MSG_ERROR>: Describe better default.
Suggestions by Paolo Bonzini and Ralf Wildenhues.
2008-11-21 Eric Blake <ebb9@byu.net>
Add @anchors within Builtins and Usual Tools lists.

View File

@ -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
AS_EXIT([1])
' # 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 ;;
AS_EXIT([1]) ;;
* )
break ;;
esac
@ -175,7 +175,7 @@ case $# in
infile=configure.in
else
AS_ECHO(["$as_me: no input file"]) >&2
AS_EXIT
AS_EXIT([1])
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 ;;
AS_EXIT([1]) ;;
esac
# Unless specified, the output is stdout.

View File

@ -9223,11 +9223,12 @@ This macro prints nothing if @command{configure} is run with the
@end defmac
@anchor{AC_MSG_ERROR}
@defmac AC_MSG_ERROR (@var{error-description}, @ovar{exit-status})
@defmac AC_MSG_ERROR (@var{error-description}, @dvar{exit-status, $?/1})
@acindex{MSG_ERROR}
Notify the user of an error that prevents @command{configure} from
completing. This macro prints an error message to the standard error
output and exits @command{configure} with @var{exit-status} (1 by default).
output and exits @command{configure} with @var{exit-status} (@samp{$?}
by default, except that @samp{0} is converted to @samp{1}).
@var{error-description} should be something like @samp{invalid value
$HOME for \$HOME}.
@ -12165,12 +12166,10 @@ 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, max($?/1)})
@defmac AS_EXIT (@dvar{status, $?})
@asindex{EXIT}
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
Emit code to exit the shell with @var{status}, defaulting to @samp{$?}.
This macro
works around shells that see the exit status of the command prior to
@code{exit} inside a @samp{trap 0} handler (@pxref{trap, , Limitations
of Shell Builtins}).
@ -12213,9 +12212,10 @@ Also see the @code{AC_PROG_MKDIR_P} macro (@pxref{Particular Programs}).
@defmac AS_SET_STATUS (@var{status})
@asindex{SET_STATUS}
Emit shell code to set the value of @samp{$?} to @var{status} without
forking. However, this is not guaranteed to abort a shell running with
@code{set -e} (@pxref{set, , Limitations of Shell Builtins}).
Emit shell code to set the value of @samp{$?} to @var{status}, as
efficiently as possible. However, this is not guaranteed to abort a
shell running with @code{set -e} (@pxref{set, , Limitations of Shell
Builtins}).
@end defmac
@defmac AS_TR_CPP (@var{expression})

View File

@ -539,21 +539,19 @@ m4_defun([_AS_EXIT_PREPARE],
[AS_FUNCTION_DESCRIBE([as_fn_set_status], [STATUS],
[Set $? to STATUS, without forking.])], [ return $[]1])]dnl
[AS_REQUIRE_SHELL_FN([as_fn_exit],
[AS_FUNCTION_DESCRIBE([as_fn_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_FUNCTION_DESCRIBE([as_fn_exit], [[[STATUS=$?]]],
[Exit the shell with STATUS, even in a "trap 0" or "set -e" context.])],
[ as_status=$?
set +e
test $as_status = 0 && as_status=1
as_fn_set_status ${1-$as_status}
exit ${1-$as_status}])])#_AS_EXIT_PREPARE
# AS_EXIT([EXIT-CODE = $?/1])
# ---------------------------
# AS_EXIT([EXIT-CODE = $?])
# -------------------------
# Exit, with status set to EXIT-CODE in the way that it's seen
# within "trap 0", and without interference from "set -e". If
# EXIT-CODE is omitted, then use $?, except use 1 if $? is 0.
# EXIT-CODE is omitted, then use $?.
m4_defun([AS_EXIT],
[AS_REQUIRE([_AS_EXIT_PREPARE])[]as_fn_exit[]m4_ifval([$1], [ $1])])
@ -769,15 +767,19 @@ _AS_ECHO([$as_me: $1], [$2]);}],
# AS_WARN(PROBLEM)
# ----------------
# Output "`basename $0`: WARNING: "STRING to stderr.
m4_define([AS_WARN],
[AS_MESSAGE([WARNING: $1], [2])])# AS_WARN
# AS_ERROR(ERROR, [EXIT-STATUS = 1])
# ----------------------------------
# AS_ERROR(ERROR, [EXIT-STATUS = max($?/1)])
# ------------------------------------------
# Output "`basename $0`: error: "STRING to stderr, then exit the
# script with EXIT-STATUS.
m4_define([AS_ERROR],
[{ AS_MESSAGE([error: $1], [2])
AS_EXIT([$2]); }])# AS_ERROR
[{ m4_ifval([$2], [], [as_status=$?; test $as_status -eq 0 && as_status=1
]) AS_MESSAGE([error: $1], [2])
AS_EXIT(m4_default([$2], [$as_status])); }])# AS_ERROR

View File

@ -308,6 +308,7 @@ test x${1} = xb && AS_EXIT([${2}])
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
test $[#] -gt 0 || AS_EXIT
AS_SET_STATUS([3])
dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls
test x${2} = xe \
@ -316,12 +317,13 @@ AS_SET_STATUS([4])
]])
AT_CHECK_M4SH
AT_CHECK([./script], [4])
AT_CHECK([./script a], [1])
AT_CHECK([./script b], [1])
AT_CHECK([./script], [1])
AT_CHECK([./script ''], [4])
AT_CHECK([./script a], [0])
AT_CHECK([./script b], [0])
AT_CHECK([./script b 0], [0])
AT_CHECK([./script b 2], [2])
AT_CHECK([./script c 0], [1])
AT_CHECK([./script c 0], [0])
AT_CHECK([./script c 2], [2])
AT_CHECK([./script d], [4], [[4
]])